Game Development Community

Best Place for SetArmThread

by Steve Acaster · in Torque 3D Professional · 11/09/2009 (9:43 pm) · 3 replies

The rest of the world might have already got this ... but I hadn't.

I was attempting to work out the best way to get setArmThread to play in correspondence to mounting various weapon images. It seemed obvious that throwing it in StateScript for the image's "Activate" was probably best, but then I hit a slight hiccup -> calling a dump on my mounted image didn't give me a whole range of useful functions. Slightly baffled, I noticed that alot of function which I would have considered weapon image related, actually got called in player.cpp. Calling a quick getmountedobject returned my player, and embafflement cleared. The %obj wasn't the image as I had first thought, it was the player.

So, here we go. note: Your directory structure may vary...
In art/datablocks/weapons/yourweapon.cs
//in state[1]
//....
   stateSequence[1]                 = "Activate";
   stateScript[1]					= "onActivate";//added yorks

   // Ready to fire, just waiting for the trigger
   stateName[2]                     = "Ready";
//....

In scripts/server/weapons/yourweapon.cs
//between projectile::onCollision() and image::onFire()
function yourweaponImage::onActivate(%this, %obj)
{
//echo(%obj);
//%obj is the player, thinking it the image, 
//I'd confused myself by trying to call what it was mounted on

%obj.setarmthread(your_other_look_animation);
}

This way whenever a weapon is changed, or spawned on a player or AI, it'll set the correct arm animation for that. Obviously remember to change all of your weapon image files so that they play the correct arm animations, and you'll probably also want to edit the ServerCommand to unmount weapon (default "0" key).

Not sure that this is the best way to do it, but ... in scripts/server/commands.cs
function serverCmdUnmountWeapon(%client)
{
   %client.getControlObject().unmountImage($WeaponSlot);
   LocalClientConnection.getControlObject().setarmthread(looknw);//added yorks
}

And it all works lovely. If anyone has a better way, feel free to enlighten.

#1
11/10/2009 (7:17 am)
If used a global variable for the player (for example $thePlayer),then:
$thePlayer.setarmthread(your_other_look_animation);
will work all over the place.
#2
11/10/2009 (9:35 am)
In TGEA (I've not ported it in T3D yet) I used the Weapon::onUse function. It is something like:
function Weapon::onUse(%data,%obj, %slot)
{
  ...
  %obj.setArmThread(%data.image.armThread);
  ...
}
Where armThread is a dynamic field defined in the ShapeBaseImageData datablock relative to the weapon.
This works perfectly if you always have a weapon in hand.
If you want to have the hands empty, perhaps you could use the generic
function WeaponImage::onUnmount(%this, %obj, %slot)
{
   %obj.setArmThread(looknw);
}
If you implement specific onUnmount function for your weapon image, just remember to call the parent function.

Edit: after readig this again, perhaps the setArmThread for the weapon image can be placed inside the
function WeaponImage::onMount(%this, %obj, %slot)
{
   %obj.setArmThread(%this.armThread);
}
#3
11/10/2009 (11:36 am)
Thanks guys.

I think WeaponImage::onUse is probably better - on the grounds that it requires less file editing!

function Weapon::onUse(%data, %obj)
{
//.....
   if(%data $= "carbine" || %data $= "rifle" || %data $= "lmg" || %data $= "shotgun")
   {
   %obj.setarmthread(look);
   }
   if(%data $= "smg" || %data $= "tmp" || %data $= "gl")
   {
   %obj.setarmthread(lookpg);
   }
}

@Pic
I'd actually kinda forgotten about globals for some time - after having issues using them back in TGE and turning everything I could lay my hands on to locals. But you've just reminded me that having a Global for the client would be really useful.

Forest -> Trees