Author Topic: State system  (Read 948 times)

Someone mind posting an explanation?
Rocket launcher one:
Code: [Select]
   // 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]                     = "Activate";
stateTimeoutValue[0]             = 0.1;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "Fire";
stateAllowImageChange[1]         = true;
   stateTransitionOnNoAmmo[1]       = "NoAmmo";
stateSequence[1] = "Ready";

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Smoke";
stateTimeoutValue[2]            = 0.1;
stateFire[2]                    = true;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "Fire";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = rocketLauncherFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = tailNode;
stateSound[2] = rocketFireSound;
   stateSequence[2]                = "Fire";
//stateEjectShell[2]       = true;

stateName[3] = "Smoke";
stateEmitter[3] = rocketLauncherSmokeEmitter;
stateEmitterTime[3] = 0.05;
stateEmitterNode[3] = "muzzleNode";
stateTimeoutValue[3]            = 0.1;
   stateSequence[3]                = "TrigDown";
stateTransitionOnTimeout[3]     = "CoolDown";

   stateName[5] = "CoolDown";
   stateTimeoutValue[5]            = 0.5;
stateTransitionOnTimeout[5]     = "Reload";
   stateSequence[5]                = "TrigDown";


stateName[4] = "Reload";
stateTransitionOnTriggerUp[4]     = "Ready";
stateSequence[4] = "TrigDown";

   stateName[6]   = "NoAmmo";
   stateTransitionOnAmmo[6] = "Ready";

EDIT: I get it, but a guide for newbies would be nice for others
« Last Edit: August 09, 2009, 01:35:53 PM by Digmaster »


Each 'state' comes with several variables to affect what it does. Explanations of each: [X is state number]

General
stateName[X] - Name of the state. This is used in the transitions between states. (see below)
stateSound[X] - Sound played when it gets to this state. Put your "gun shot" sounds here.
stateSequence[X] - Animation played in the model during this state.
stateAllowImageChange[X] - Allows you to change weapons while in this state. You might want to disable this during the "fire" states of your weapon by setting it to false.
stateScript[X] - The function run when it gets to this state. For instance, "onFire" is a pre-coded state which fires the weapon's projectile directly forwards at the speed set in the projectile datablock. You can also code your own functions.

Emitters
stateEmitter[X] - Emitter datablock used during the state. This could be the gun muzzle flash during each fire state.
stateEmitterTime[X] - How long the emitter lasts, in seconds.
stateEmitterNode[X] - Where on the weapon the emitter is shown. muzzleNode, if on the model of the gun, marks its barrel (for where projectiles normally come out), but other points can also be used.

Shell
stateEjectShell[X] - When set to true, the gun will 'eject' a shell from what is specified by the rest of the variables.
These ones don't have state___[X] in them, they are in the rest of the datablock
casing - a debrisData datablock for the shell/casing that comes out.
shellExitDir - 3-Vector Direction relative to the player the shell comes out. "0 1 0" will eject directly forwards.
shellExitOffset - Offset to the weapon's ejectPoint (I think) the shell will come out.
shellExitVariance - Random amount added to either the exit velocity or the offset (I'm not sure)
shellVelocity - Speed at which the shell comes out.

State Transitions
stateTimeoutValue[X] - The time after which the state will 'time out' and call stateTransitionOnTimeout
stateTransitionOnTimeout[X] - The name of the state this will change to after the specified time.
stateWaitForTimeout[X] - When set to true, it forces the weapon to wait for the time before changing any state. (The ones below will happen as soon as it occurs unless this is set)
stateTransitionOnAmmo[X] - The name of the state this will change to if [holder].setImageAmmo(slot,1) was previously set or is called. This can be used for advanced state transitions.
stateTransitionOnNoAmmo[X] - The name of the state this will change to if [holder].setImageAmmo(slot,0) was previously set or is called. This can be used for advanced state transitions.
stateTransitionOnLoaded[X] - The name of the state this will change to if [holder].setImageLoaded(slot,1) was previously set or is called. This can be used for advanced state transitions.
stateTransitionOnNotLoaded[X] - The name of the state this will change to if [holder].setImageLoaded(slot,0) was previously set or is called. This can be used for advanced state transitions.

Nice little table on Shape Base Image Data



And these are on all the states


I nominate this for a sticky.

This is extremely helpful, thank you.

If someone couldn't figure out what each thing does from the name; they probably wouldn't be too sucecssful in scripting, but to give them a chance I second that sticky nomination.