Game Development Community

I need help with my weapon.

by Jose Salinas · in Torque 3D Beginner · 01/08/2014 (1:53 pm) · 3 replies

Hi, I am a beginner programmer. If I wanted my gun to shoot a missile when I push the "r" key, how and where would I script that?

#1
01/09/2014 (10:22 am)
Hello Jose and welcome to the community.

This task may be a little "difficult" for an intro level programmer, but hey, props for taking on a challenging task.

Introduce a new keybind in optionsDlg.cs and call it something like "SpecialFireMode", then in client.cs have a function like this:

function specialFireMode(%val) {
   if(%val) {
      commandToServer('doSpecialFireMode');
   }
}

on the server side you'd receive this handle like so:
function serverCmdDoSpecialFireMode(%client) {
   %player = %client.getControlObject();
   if(%player.getDatablock() $= "DefaultPlayer") {
      if(isObject(%player) && %player.getState() !$= "dead") {
         doSpecialFire(%player);
      }
   }
}

This will push a call to doSpecialFire() when the player object is alive and is a DefaultPlayer. From there you'd have something like this:
function doSpecialFire(%player) {
   //Always run a sanity check on function calls!
   if(isObject(%player) && %player.getState() !$= "dead") {
      if(%player.getMountedImage($WeaponSlot) $= "MyGun") {
         FireSpecialRocket(%player);
      }
   }
}

From there you'd write up a FireSpecialRocket code that spawns the projectile in the MuzzlePoint of the mounted weapon.

Hope this helps! Good Luck!
#2
01/10/2014 (6:29 pm)
Hi Robert. Thanks for the reply. Well first I enabled the alt trigger. Then I modified the default.bind.cs so the mouse button 1 won't zoom and fire the alt trigger. I'm using the default gun for the soldier the ryder gun. I went into the ryder.cs and I added

ammo = LurkerGrenadeAmmo;
altProjectile = GrenadeLauncherProjectile;
altProjectileType = Projectile;
altProjectileSpread = "0.05";

to it and I also added

stateTransitionOnAltTriggerDown[2] = "AltFire";

to the 2nd state and I added this state

//alt fire
stateName[14] = "AltFire";
stateAlternateFire[14] = true;
stateTransitionOnTimeout[14] = "WaitForRelease";
stateTimeoutValue[14] = 0;
stateScript[14] = "onAltFire";
stateSequence[14] = "fire_alt";

This made my gun fire grenades with the alt trigger. I wanted to add another trigger and I linked it to $mvTriggerCount4++; as

function alt2Fire(%val)
{
$mvTriggerCount4++;
}
but the gun doesn't fire the third trigger I tried to add.
#3
01/13/2014 (9:49 pm)
1st you have to add ammo and weapon to your soldier inventory.
add this to your actor datablock:

maxInv[yourWeaponName] = 1;
maxInv[AmmoUsedByWeapon] = 1000;

then try