Game Development Community

Changing states for weapon in default crossbow script

by Paul Fassett · in Technical Issues · 02/08/2004 (8:26 am) · 8 replies

I have a Para-ordinance CCW weapon that can hold a fifteen bullet clip in my game at the moment and it is using the default crossbow script to get it into the game. I need to somehow change the states so that the gun only reloads once every 15 shots instead of once everytime a bullet is fired. Here is the original.

// 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.6;
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 fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.3;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = CrossbowFireSound;

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

// 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 dry fire
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateSound[6] = CrossbowFireEmptySound;
};

How do you change the states to accomplish this, or is there some other way?

#1
02/10/2004 (8:04 am)
No takers on this?
#2
02/10/2004 (10:39 am)
I don't think the state machine natively supports clips. Maybe you can do something like only put a clip's worth of ammo into the gun at a time, then require the player to reload to get more. That way you'd still be using the state machine...
#3
02/10/2004 (1:16 pm)
So it's not as simple as adding a state then.
#4
02/10/2004 (4:28 pm)
Hmm... add a couple script functions and change the order of the states and it should be possible.

I may see if I can come up with something
#5
02/10/2004 (5:09 pm)
I Like ben's Idea..
it is simple
add feature to inv clips and reload
where it add's clip ammo to ammo count.
so now the gun is empty press reload and your inv script does all the work.

simply modify the weapon script to not reload like you say and set state empty
#6
02/11/2004 (9:20 am)
After some looking... here is the one basic change you need to make:

// Fire the weapon. Calls the fire script which does 
   // the actual work.
   stateName[3]                     = "Fire";
   stateTransitionOnTimeout[3]      = "Ready";  // Do not go through reload, go immediatly to ready
   stateTimeoutValue[3]             = 0.2;
   stateFire[3]                     = true;
   stateRecoil[3]                   = LightRecoil;
   stateAllowImageChange[3]         = false;
   stateSequence[3]                 = "Fire";
   stateScript[3]                   = "onFire";
   stateSound[3]                    = CrossbowFireSound;

You will have to change your inventory control system to work with clips, but that shouldn't be too much work. There are a few examples in the resources section for this.
#7
07/06/2007 (11:14 pm)
Hi , I create a new weapon and , make the reload scene dsq ,
I over write sucessful the crossbow but not the fire and reload animation ,..
Anyybody knows how to change the fire animation of crossbow for other?
#8
07/07/2007 (9:48 am)
The code block directly above is right on point:

In the state where you are actively "firing" (in stock, it's what Labrat has in codeblocks--state 3), change the stateSequence[3] = "Fire"; to the animation in your shape.

It's important to note that the ShapeBaseImage system expects all weapon animations to be within the weapon's dts, not as separate dsq files. DSQ files are only intended to be used for objects at the Player class level in the hierarchy.