Game Development Community

I been tried to add a weapon but it cannot shot or no reaction at all?

by Christopher Pang · in Torque Game Engine · 07/10/2009 (9:36 am) · 20 replies

I were trying to implement second weapon for slot 2 ( keyboard 2 ) seems that I can add the weapon ( Rocket_launcher ) but it just won't shoot so I wondering how can I activate this second weapon as it should shoot normally, any one please let me know how to set this work?

I got the datablock settled so it display the weapon when I picked it up but after that it just won't shoot when I press left mouse button so I couldn't find any similar thread in this moment any one know this depth please show me the answer?

Thanks in advanced.

#1
07/10/2009 (10:10 am)
Have you picked up the weapons ammo as well?
#2
07/10/2009 (1:25 pm)
Yes I did the "Rocket_launcher.cs" I got the ammo settled for "Rocket.dts" so I also insert it on a floor of the level with the bazuka but after I did that I tried to press the left mouse button but nothing happen except seeing the slot 1 >< slot 2 exchanged but cannot shoot with the bazuka only if I switch back to crossbow then it shoot with the crossbow only..?

Looks silly?
#3
07/10/2009 (1:37 pm)
Let's see your 2nd weapon script, the one that's not working properly. Just paste the Projectile datablock, the Ammo datablock, the Weapon Item datablock, and the Weapon Image datablock. From there we should be able to tell what is going wrong.
#4
07/10/2009 (1:52 pm)
I not so sure is that reasonable lines I should paste, my scripting skill are beginner apologize if this annoying...( Basically I just copy paste from orginal source codes no major changed. ):

//-----------------------------------------------------------------------------
// When a rocket is flying through the air, it will emit exhaust like this...
//-----------------------------------------------------------------------------
datablock ParticleData( RocketExhaustParticle )
{
textureName = "~/data/shapes/rocket_launcher/smoke";
useInvAlpha = false;

lifetimeMS = 2000;
lifetimeVarianceMS = 250;

times[0] = 0.0;
times[1] = 0.5;
times[2] = 1.0;

colors[0] = "0.8 0.3 0.0 1.0";
colors[1] = "0.1 0.1 0.1 0.7";
colors[2] = "0.1 0.1 0.1 0.0";

sizes[0] = 0.1;
sizes[1] = 0.5;
sizes[2] = 1.0;
};

datablock ParticleEmitterData( RocketExhaustParticleEmitter )
{
particles = RocketExhaustParticle;

ejectionPeriodMS = 5;
periodVarianceMS = 2;

ejectionVelocity = 0.1;
velocityVariance = 0.1;
};

//-----------------------------------------------------------------------------
// When the rocket launcher fires, it will emit a single rocket which behaves
// like this...
//-----------------------------------------------------------------------------
datablock ProjectileData( RocketProjectile )
{
projectileShapeName = "~/data/shapes/rocket_launcher/rocket.dts";

muzzleVelocity = 120;
armingDelay = 0;
lifetime = 5000;
fadeDelay = 5000;
isBallistic = true;
gravityMod = 0.5;

// The projectile will cast light on the ground as it travels.
hasLight = true;
lightRadius = 5;
lightColor = "0.5 0.5 0.25";

// The rocket will emit exhaust particles using this
particleEmitter = RocketExhaustParticleEmitter;

// We'll create one of these if our rocket hits something
explosion = RocketExplosion;
directDamage = 20;
radiusDamage = 10;
damageRadius = 1.5;
};

function RocketProjectile::onCollision( %this, %obj, %col, %fade, %pos, %normal )
{
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"Rocket_launcherBolt");

// Radius damage is a support scripts defined in radiusDamage.cs
// Push the contact point away from the contact surface slightly
// along the contact normal to derive the explosion center. -dbs
radiusDamage(%obj, %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
}

//-----------------------------------------------------------------------------
// Ammo Item

datablock ItemData(rocket)
{
// Mission editor category
category = "Ammo";

// Add the Ammo namespace as a parent. The ammo namespace provides
// common ammo related functions and hooks into the inventory system.
className = "Ammo";

// Basic Item properties
shapeFile = "~/data/shapes/rocket_launcher/rocket.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;

// Dynamic properties defined by the scripts
pickUpName = "RocketExplosive";
maxInventory = 20;
};

//----------- Rocket Launcher for item data.
datablock ItemData(Rocket_launcher)
{
// Mission editor category
category = "Weapon";

// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";

// Basic Item properties
shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;

// Dynamic properties defined by the scripts
pickUpName = "a RocketProjectile";
image = RocketLauncherImage;
};
//-----------------------------------------------------------------------------
// When the player uses the rocket launcher, it will behave like this...
//-----------------------------------------------------------------------------
datablock ShapeBaseImageData( RocketLauncherImage )
{
shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";

projectile = RocketProjectile;
projectileType = Projectile;
fireTimeout = 0;
emap = true;

// When firing from a point offset from the eye, muzzle correction will
// adjust the muzzle vector to point to the eye LOS point. Since this
// weapon doesn't actually fire from the muzzle point, we need to turn
// this off.
correctMuzzleVector = false;

// Specify mountPoint & offset for 3rd person, and eyeOffset for first
// person rendering.
mountPoint = 0;
offset = "0.0 0.0 0.0";
eyeOffset = "0.0 0.0 0.0";
#5
07/11/2009 (9:33 am)
I rewrote the "Rocket_launcher.cs" then I used it but this time Ammo cannot be pickup any one please let me know how to make the "rocket.dts" work as an ammo?
#6
07/11/2009 (10:19 am)
Did you add the "rocket ammo" to the allowable inventory for the player in the player datablock. This is what allows it to be picked up by the player -- this works with in combination with how the scripted inventory systems is written in inventory.cs.

Look in "server/scripts/player.cs" towards the end of the player datablock you'll see something like this:
// Allowable Inventory Items
maxInv[Pistol] = 1;
maxInv[PistolAmmo] = 50;
maxInv[Rifle] = 1;
maxInv[RifleAmmo] = 20;
maxInv[RocketLauncher] = 1;
maxInv[RocketLauncherAmmo] = 12;
maxInv[Handbomb] = 1;
maxInv[HandbombAmmo] = 4;
Add your weapon and ammo here.
#7
07/11/2009 (1:04 pm)
I did that in the allowable inventory but must be some where not right or clear I not sure what I should do...

//--------------------------------------------------------------------------
// Crossbow image which does all the work. Images do not normally exist in
// the world, they can only be mounted on ShapeBase objects.

datablock ShapeBaseImageData(Rocket_launcherImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";
emap = true;

// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
eyeOffset = "0.1 0.4 -0.6";

// When firing from a point offset from the eye, muzzle correction
// will adjust the muzzle vector to point to the eye LOS point.
// Since this weapon doesn't actually fire from the muzzle point,
// we need to turn this off.
correctMuzzleVector = false;

// Add the WeaponImage namespace as a parent, WeaponImage namespace
// provides some hooks into the inventory system.
className = "WeaponImage";

// Projectile && Ammo.
item = Rocket_launcher; << I suspect this line is not clear
ammo = Rocket_launcherAmmo; << or this.
projectile = CrossbowProjectile;
projectileType = Projectile;

// Images have a state system which controls how the animations
// are run, which sounds are played, script callbacks, etc. This
// state system is downloaded to the client so that clients can
// predict state changes and animate accordingly. The following
// system supports basic ready->fire->reload transitions as
// well as a no-ammo->dryfire idle state.

// Initial start up state
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "NoAmmo";
#8
07/11/2009 (1:30 pm)
My problem is after I did all of these then when I exec the game it cannot collide with the ammo I guess some parameter is missing but I not sure where is it in the scripts so if you know please show me...
#9
07/12/2009 (9:50 am)
Try this in the console:

LocalClientConnection.Player.setInventory("Rocket_LauncherAmmo",10);

Then see if it works. Are there any console errors?
#10
07/12/2009 (10:33 am)
A question I had meant to ask earlier: are you using starter.fps or tutorial.base? I ask because I recognize those comments from the Codesampler.com tutorial.base tutorials -- the answer to this question will provide an answer in itself.

The only thing that I see is wrong is that you've named your ammo "rocket" yet in the Rocket_launcherImage you've put "Rocket_launcherAmmo" in the ammo field.
#11
07/12/2009 (12:54 pm)
I changing it frequently ( mean the Ammo field ) but not working out. I was making my game in "starter.fps" then I borrowed the asset which downloaded from Harris's site for the "tutorial.base" this coding freaking me out.

Well appreciated for the answers if you would show me how to convert that tutorial.base asset into starter.fps's will be nice too.

But I not expect it could work properly I may try other indie engine...
#12
07/12/2009 (1:50 pm)
It's really quite simple, don't give up on it yet. It's probably just something real minor and easy to overlook that's hard to spot here.

Have you deleted your existing .dso files and let them be regenerated -- sometimes they will cause some unexplainable trouble when you modify the scripts, but getting rid of them and then running the game so it makes new ones generally fixes that.

Send me the whole script file if you want and I'll look it over, my email address is on my profile. I can make those tutorial.base tutorials work in every Torque engine :D
#13
07/12/2009 (4:11 pm)
hmm...
#14
07/12/2009 (4:26 pm)
My email is tgeBryce@yahoo.com, I'd like to have a look too
#15
07/12/2009 (5:08 pm)
I don't know what would cause your email to have bounced, strange that. I'll download and convert the rockertlauncher.cs from the CodeSampler.com weapon tutorial for you and paste it here -- but it will be later tonight before I do so, probably in the wee hours of the morning.
#16
07/13/2009 (4:23 am)
This is what I did step-by-step to add a new 2nd weapon for use in TGE for the starter.fps project.

I downloaded the Trq_weapons archive for tutorial.base from Codesampler.com and placed the "rocket_launcher" directory into the "~/data/shapes" directory. This folder contained the rocketlauncher shape, a rocket shape, an explosion sound, and a few textures - some of which are to be used as particle effect images. Particles should technically go in the "~/shapes/particles" directory but since it's an organizational choice I left them where there are just to keep this simple. Now onto the script:

First up is the AudioProfile for the RocketExplosion: Directory looks good -- no change.
//-----------------------------------------------------------------------------
// When a rocket hits something, this is what it will sound like...
//-----------------------------------------------------------------------------
datablock AudioProfile(RocketExplosionSound)
{
   filename = "~/data/shapes/rocket_launcher/rocket_explosion.ogg";
   description = AudioDefault3d;
   preload = true;
};

RocketEXplosion particles: directory looks good -- no change. Continuing on to include the RocketExplosion datablock. The fields in it should be self-explanatory, the different emitters point to the various rocket explosion particles already decalred above. Note that you load your particle effects before "using" or calling for them.
//-----------------------------------------------------------------------------
// When a rocket explodes upon impact, it will emit smoke like this...
//-----------------------------------------------------------------------------
datablock ParticleData(RocketExplosionSmokeParticle)
{
   textureName = "~/data/shapes/rocket_launcher/smoke";
   useInvAlpha =  true;
   dragCoeffiecient = 100.0;
   inheritedVelFactor = 0.3;
   constantAcceleration = -0.3;
   lifetimeMS = 1200;
   lifetimeVarianceMS = 300;
   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;
   colors[0] = "0.56 0.36 0.26 1.0";
   colors[1] = "0.2 0.2 0.2 1.0";
   colors[2] = "0.0 0.0 0.0 0.0";
   sizes[0] = 4.0;
   sizes[1] = 2.5;
   sizes[2] = 1.0;
};

datablock ParticleEmitterData(RocketExplosionSmokeParticleEmitter)
{
   particles = "RocketExplosionSmokeParticle";
   lifetimeMS = 250;
   lifetimeVarianceMS = 0;
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 4;
   velocityVariance = 0.5;
};

//-----------------------------------------------------------------------------
// When a rocket explodes upon impact, it will emit fire like this...
//-----------------------------------------------------------------------------
datablock ParticleData(RocketExplosionFireParticle)
{
   textureName = "~/data/shapes/rocket_launcher/fire";
   useInvAlpha =  false;
   dragCoeffiecient = 100.0;
   inheritedVelFactor = 0.3;
   lifetimeMS = 1200;
   lifetimeVarianceMS = 300;
   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;
   colors[0] = "0.8 0.4 0.0 0.8";
   colors[1] = "0.2 0.0 0.0 0.8";
   colors[2] = "0.0 0.0 0.0 0.0";
   sizes[0] = 1.5;
   sizes[1] = 0.9;
   sizes[2] = 0.5;
};

datablock ParticleEmitterData(RocketExplosionFireParticleEmitter)
{
   particles = "RocketExplosionFireParticle";
   lifetimeMS = 250;
   lifetimeVarianceMS = 0;
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 0.8;
   velocityVariance = 0.5;
};

//-----------------------------------------------------------------------------
// When a rocket explodes upon impact, it will emit sparks like this...
//-----------------------------------------------------------------------------
datablock ParticleData(RocketExplosionSparksParticles)
{
   textureName = "~/data/shapes/rocket_launcher/spark";
   dragCoefficient      = 1;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS = 500;
   lifetimeVarianceMS = 350;
   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;
   colors[0] = "1.0 0.0 0.0 1.0";
   colors[1] = "1.0 1.0 0.0 0.8";
   colors[2] = "1.0 1.0 1.0 0.1";
   sizes[0] = 0.20;
   sizes[1] = 0.15;
   sizes[2] = 0.5;
};

datablock ParticleEmitterData(RocketExplosionSparksParticleEmitter)
{
   particles = "RocketExplosionSparksParticles";
   lifetimeMS = 150;
    lifetimeVarianceMS = 0;
   ejectionPeriodMS = 2;
   periodVarianceMS = 0;
   ejectionVelocity = 30;
   velocityVariance = 10;
};

#17
07/13/2009 (4:25 am)
//-----------------------------------------------------------------------------
// When a rocket hits something, it will explode like this...
//-----------------------------------------------------------------------------
datablock ExplosionData(RocketExplosion)
{
   soundProfile = RocketExplosionSound;
   lifeTimeMS = 1200;
    lifetimeVarianceMS = 0;
   // Volume particles
   particleEmitter = RocketExplosionFireParticleEmitter;
   particleDensity = 100;
   particleRadius  = 2;
   // Point emission particles
   emitter[0] = RocketExplosionSmokeParticleEmitter;
   emitter[1] = RocketExplosionSparksParticleEmitter;
   // This will make the camera shake when a player gets hit by a rocket.
    // Shoot your own feet to see this effect in action.
   shakeCamera      = true;
   camShakeFreq     = "10.0 11.0 10.0";
   camShakeAmp      = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius   = 10.0;
   // This will create a dynamic lighting effect in the vicinity of the
    // rocket's explosion.
   lightStartRadius = 6;
   lightEndRadius   = 3;
   lightStartColor  = "0.5 0.5 0.0";
   lightEndColor    = "0.0 0.0 0.0";
};

Projectile Trail particle: directory looks good -- no change.
//-----------------------------------------------------------------------------
// When a rocket is flying through the air, it will emit exhaust like this...
//-----------------------------------------------------------------------------
datablock ParticleData(RocketExhaustParticle)
{
   textureName = "~/data/shapes/rocket_launcher/smoke";
   useInvAlpha = false;
   lifetimeMS = 2000;
   lifetimeVarianceMS = 250;
   times[0] = 0.0;
   times[1] = 0.5;
   times[2] = 1.0;
   colors[0] = "0.8 0.3 0.0 1.0";
   colors[1] = "0.1 0.1 0.1 0.7";
   colors[2] = "0.1 0.1 0.1 0.0";
   sizes[0] = 0.1;
   sizes[1] = 0.5;
   sizes[2] = 1.0;
};

datablock ParticleEmitterData(RocketExhaustParticleEmitter)
{
   particles = RocketExhaustParticle;
   ejectionPeriodMS = 5;
   periodVarianceMS = 2;
   ejectionVelocity = 0.1;
   velocityVariance = 0.1;
};

Continuing on to the RocketProjectile datablock. It's projectileShapeName is pointing to the correct file path/name. The other settings can be tweaked by you if you wish a different muzzleVelocity and at some point you may want to modify & balance the damage. Directdamage is how much damage it does when you are hit by the rocket. radiusDamage is how much damage the rocket causes when it explodes. damageRadius is the area size that damage can occur in -- let's go ahead and bumb that up to 5. You can also add some impulse or "kick back" from an explosion, you would add the "areaImpulse" field here with an amount of impulse that gets applied. 2000 is a good starting value -- raise or lower it to taste.
//-----------------------------------------------------------------------------
// When the rocket launcher fires, it will emit a single rocket which behaves
// like this...
//-----------------------------------------------------------------------------
datablock ProjectileData(RocketProjectile)
{
   projectileShapeName = "~/data/shapes/rocket_launcher/rocket.dts";
   muzzleVelocity = 120;
   armingDelay    = 0;
   lifetime       = 5000;
   fadeDelay      = 5000;
   isBallistic    = true;
   gravityMod     = 0.5;
    // The projectile will cast light on the ground as it travels.
   hasLight    = true;
   lightRadius = 5;
   lightColor  = "0.5 0.5 0.25";
    // The rocket will emit exhaust particles using this
   particleEmitter = RocketExhaustParticleEmitter;
    // We'll create one of these if our rocket hits something
   explosion    = RocketExplosion;
   directDamage = 20;
   radiusDamage = 10;
   damageRadius = 1.5;
   areaImpulse = 2000;
};
#18
07/13/2009 (4:28 am)
Notice the RocketProjectile::onCollision() -- it has a comment "// TO DO: Add code here to calculate rocket damage for any object hit." Well we want our rocket to do damage so let's go ahead and do this. You can look at the crossbow.cs for an example of the required code, you would do the same for any and all projectiles. You would want to give your projectile a unique "damage type" if you want to eventually give custom death messages when you kill other players with different weapons. Direct damage is applied on collision, radiusDamage is applied by another "helper" function -- it's here that the explosion damage and impulse is applied.
function RocketProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
    echo("RocketProjectile::onCollision called! ----------------------------");

    // Apply damage to the object all shape base objects
   if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
      %col.damage(%obj, %pos, %this.directDamage, "RocketDamageType");

   // Radius damage is a support script defined in radiusDamage.cs
   // Push the contact point away from the contact surface slightly
   // along the contact normal to derive the explosion center. -dbs
   radiusDamage(%obj, %pos, %this.damageRadius, %this.radiusDamage, "Radius", %this.areaImpulse);
}

Next up is the RocketLauncherImage. It's the image that you see when a weapon is mounted. It is this datablock that controls how the weapon handles. Directory for the "shapeFile" looks good. We do need to add the className property for the weapon Image here in order for it to be compatible with the scripted inventory system.

But wait -- in order to be able to pick this weapon up, as well as ammo we'll need to create datablocks for the weapon ITEM and the ammo ITEM. Make sure that these are placed before the RocketLauncherImage datablock.

Note that the Rocketlauncher ITEM points to the RocketLauncherImage and vice versa. Also note that we need to add the "ammo" field to the image so that it knows what ammo to use.
//-----------------------------------------------------------------------------
// Ammo Item

datablock ItemData(RocketAmmo)
{
   // Mission editor category
   category = "Ammo";

   // Add the Ammo namespace as a parent.  The ammo namespace provides
   // common ammo related functions and hooks into the inventory system.
   className = "Ammo";

   // Basic Item properties
   shapeFile = "~/data/shapes/rocket_launcher/rocket.dts";
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;

   // Dynamic properties defined by the scripts
   pickUpName = "Rockets";
   maxInventory = 5; // THIS IS HOW MANY YOU GET PER PICKUP
};

//--------------------------------------------------------------------------
// Weapon Item.  This is the item that exists in the world, i.e. when it's
// been dropped, thrown or is acting as re-spawnable item.  When the weapon
// is mounted onto a shape, the RocketLauncherImage is used.

datablock ItemData(RocketLauncher)
{
   // Mission editor category
   category = "Weapon";

   // Hook into Item Weapon class hierarchy. The weapon namespace
   // provides common weapon handling functions in addition to hooks
   // into the inventory system.
   className = "Weapon";

   // Basic Item properties
   shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";
   mass = 1;
   elasticity = 0.2;
   friction = 0.6;
   emap = true;

   // Dynamic properties defined by the scripts
   pickUpName = "a Rocketlauncher";
   image = RocketLauncherImage;
};
#19
07/13/2009 (4:30 am)
//-----------------------------------------------------------------------------
// When the player uses the rocket launcher, it will behave like this...
//-----------------------------------------------------------------------------
datablock ShapeBaseImageData(RocketLauncherImage)
{
   shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";
    //fireTimeout = 0; // THIS IS NOT USED
   emap = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = RocketLauncher;
   ammo = RocketAmmo;
   projectile = RocketProjectile;
    projectileType = Projectile;
    // When firing from a point offset from the eye, muzzle correction will
    // adjust the muzzle vector to point to the eye LOS point. Since this
    // weapon doesn't actually fire from the muzzle point, we need to turn
    // this off.
    correctMuzzleVector = false;

   // Specify mountPoint & offset for 3rd person, and eyeOffset for first
    // person rendering.
   mountPoint = 0;
    offset = "0.0 0.0 0.0";
    eyeOffset = "0.0 0.0 0.0";

   // Images have a state system which controls how the animations are run,
   // which sounds are played, script callbacks, etc. This state system is
   // downloaded to the client so that clients can predict state changes and
   // animate accordingly.  The following system supports basic
   // ready->fire->reload transitions as well as a no-ammo->dryfire idle
   // state.

   // Initial start up state
   stateName[0]                     = "Preactivate";
   stateTransitionOnLoaded[0]       = "Activate";
   stateTransitionOnNoAmmo[0]       = "NoAmmo";

   // Activating the gun. Called when the weapon is first mounted and there
   // is ammo.
   stateName[1]                     = "Activate";
   stateTransitionOnTimeout[1]      = "Ready";
   stateTimeoutValue[1]             = 0.5;
   stateSequence[1]                 = "Activate";

   // Ready to fire, just waiting for the trigger
   stateName[2]                     = "Ready";
   stateTransitionOnNoAmmo[2]       = "NoAmmo";
   stateTransitionOnTriggerDown[2]  = "Fire";

   // Fire the weapon. Calls the onFire function when our player shoots.
   stateName[3]                     = "Fire";
   stateTransitionOnTimeout[3]      = "Reload";
   stateTimeoutValue[3]             = 0.1;
   stateFire[3]                     = true;
   stateRecoil[3]                   = LightRecoil;
   stateAllowImageChange[3]         = false;
   stateSequence[3]                 = "Fire";
   stateScript[3]                   = "onFire";
   stateEmitterTime[3]              = 0.3;

   // Play the relead animation, and transition into
   stateName[4]                     = "Reload";
   stateTransitionOnNoAmmo[4]       = "NoAmmo";
   stateTransitionOnTimeout[4]      = "Ready";
   stateTimeoutValue[4]             = 0.1;
   stateAllowImageChange[4]         = false;
   stateSequence[4]                 = "Reload";
   stateEjectShell[4]               = true;

   // No ammo in the weapon, just idle until something shows up. Play the dry
   // fire sound if the trigger is pulled.
   stateName[5]                     = "NoAmmo";
   stateTransitionOnAmmo[5]         = "Reload";
   stateSequence[5]                 = "NoAmmo";
   stateTransitionOnTriggerDown[5]  = "DryFire";

   // No ammo! Just perform a dry fire until the player finds more ammo.
   stateName[6]                     = "DryFire";
   stateTimeoutValue[6]             = 1.0;
   stateTransitionOnTimeout[6]      = "NoAmmo";
};

#20
07/13/2009 (4:30 am)
Last thing we need is the onFire function() that creates the projectile itself when you press the fire button. I went ahead an added an extra line to subtract one rocket when you fire -- otherwise it would have infinite ammo.
function RocketLauncherImage::onFire(%this, %obj, %slot)
{
   %projectile = %this.projectile;

   // Decrement inventory ammo. The image's ammo state is update
   // automatically by the ammo inventory hooks.
   %obj.decInventory(%this.ammo, 1);

   // Determine initial projectile velocity based on the gun's muzzle point
   // and the object's current velocity...
   %muzzleVector   = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();

   %muzzleVelocity = VectorAdd(VectorScale(%muzzleVector, %projectile.muzzleVelocity),
                                VectorScale(%objectVelocity, %projectile.velInheritFactor));

   // Create a new rocket projectile object...
   %p = new (%this.projectileType)()
   {
      dataBlock       = %projectile;
      initialVelocity = %muzzleVelocity;
      initialPosition = %obj.getMuzzlePoint(%slot);
      sourceObject    = %obj;
      sourceSlot      = %slot;
      client          = %obj.client;
   };
   MissionCleanup.add(%p);
   return %p;
}

The rocket_launcher.cs script goes in the "~/server/scripts" directory. You'll need to add an exec command inside of game.cs with the other ones already there: add exec("./rocket_launcher.cs"); right after the crossbow.

Now go into "~/server/scripts/player.cs" and add the Rocketlauncher and the rocket ammo to the player's inventory allowance -- at the end of the player datablock.
maxInv[RocketLauncher] = 1;
maxInv[RocketAmmo] = 20;

One more thing to do. You want to be able to switch weapons right? The crossbow is already setup to be used/mounted by pressing 1. Look in "~client/scripts/default.bind.cs" at around line#223 and you'll see the bind command for this. We just want to duplicate this for the rocketlauncher for the "2" key.

Now since we've made a few changes in a couple of different files you'll want to remove the precompiled scripts, the DSO files. There is a batchfile that will do this for you. It's called "DeleteDSOs.bat" -- let it do it's thing. And since we added a keybind you may as well clear out the old prefs and previous config.cs files -- there's a batch file called "DeletePrefs.bat" that will do this for you.

Now you're good to go. As you can see there was very little modification that needed to be done. So your previous problem was probably something simple. The code for inventory management is already included in starter.fps so there is nothing that we need to do there. Start the game, go into the editor and place a rocketlauncher and ammo -- have fun! NOTE: When you place your items from the World Editor Creator make sure that you select them from the script objects list == the SHAPES category and not the STATIC shapes category. If the rocketlauncher and/or ammo isn't rotating then you haven't place the correct type of object. Static Shapes are non-interactive and are to be used as props or decoration.

If you want to start out with the rocketlauncher when you spawn you would make that addition in game.cs at function GameConnection::createPlayer() -- you'll see where it gives you the crossbow already. Be aware that you can only "mount" one weapon at a time, but you can add anything you want to your inventory here.

This script will work practically without change in TGEa (given the same directory structure). I personally have made it much easier to add new weapons in Torque 3D for the FPS Genre Kit. Easier in regards to the amount of necessary script -- all you need there are the relevant datablocks -- and even easier to handle weapon cycling. But this script would only need minimum changes to work in Torque 3D even without the changes I've made there.