Author Topic: 6-Round burst fire script not working  (Read 721 times)

Trying to make a weapon fire in a burst of 6 boolets, for some reason it's only firing a burst of 3 and the triggercheck doesn't work. I'm too lazy to figure it out myself atm and I gotta go somewhere, so here's the code

Code: [Select]
  minShotTime = 1000;

stateName[0] = "Activate";
stateTimeoutValue[0] = 0.2;
stateTransitionOnTimeout[0] = "LoadCheckA";

stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Fire1";
stateAllowImageChange[1] = true;
stateSequence[1] = "Ready";
stateTransitionOnNoAmmo[1] = "Reload";
stateTransitionOnTimeout[1] = "weaponLoop";
stateTimeoutValue[1] = 0.05;

stateName[2] = "Fire1";
stateTransitionOnTimeout[2] = "FireLoadCheckA1";
stateTimeoutValue[2] = 0.01;
stateFire[2] = true;
stateAllowImageChange[2] = false;
stateScript[2] = "onFire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = ME3Flash1Emitter;
stateEmitterTime[2] = 0.1;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = M4SFireSound;

stateName[3] = "LoadCheckA";
stateScript[3] = "onLoadCheck";
stateAllowImageChange[3] = false;
stateTimeoutValue[3] = 0.05;
stateTransitionOnTimeout[3] = "LoadCheckB";

stateName[4] = "LoadCheckB";
stateAllowImageChange[4] = false;
stateTransitionOnAmmo[4] = "Ready";
stateTransitionOnNoAmmo[4] = "ReloadWait";

stateName[5] = "Reload";
stateAllowImageChange[5] = true;
stateEjectShell[5] = true;
stateTimeoutValue[5] = 0.63;
stateScript[5] = "OnReload";
stateTransitionOnTimeout[5] = "Reloaded";
stateWaitForTimeout[5] = true;

stateName[6] = "Reloaded";
stateAllowImageChange[6] = false;
stateTimeoutValue[6] = 0.35;
stateScript[6] = "onReloaded";
stateTransitionOnTimeout[6] = "Ready";

stateName[7] = "weaponLoop";
stateTransitionOnTriggerDown[7] = "LoadCheckA";
stateTimeoutValue[7] = 0.0;
stateTransitionOnTimeout[7] = "Ready";
stateAllowImageChange[7] = True;
stateScript[7] = "onWeaponLoop";

stateName[8] = "ReloadWait";
stateAllowImageChange[8] = false;
stateTimeoutValue[8] = 0.4;
stateTransitionOnTimeout[8] = "Reload";

stateName[9] = "TriggerCheck";
stateTransitionOnTriggerUp[9] = "LoadCheckA";

stateName[10] = "FireLoadCheckA1";
stateScript[10] = "onLoadCheck";
stateAllowImageChange[10] = false;
stateTimeoutValue[10] = 0.05;
stateTransitionOnTimeout[10]= "FireLoadCheckB1";

stateName[11] = "FireLoadCheckB1";
stateAllowImageChange[11] = false;
stateTransitionOnAmmo[11] = "Fire2";
stateTransitionOnNoAmmo[11]= "ReloadWait";

stateName[12] = "Fire2";
stateTransitionOnTimeout[12]= "FireLoadCheckA2";
stateTimeoutValue[12] = 0.01;
stateFire[12] = true;
stateAllowImageChange[12] = false;
stateScript[12] = "onFire";
stateWaitForTimeout[12] = true;
stateEmitter[12] = ME3Flash1Emitter;
stateEmitterTime[12] = 0.1;
stateEmitterNode[12] = "muzzleNode";
stateSound[12] = M4SFireSound;

stateName[13] = "FireLoadCheckA2";
stateScript[13] = "onLoadCheck";
stateAllowImageChange[13] = false;
stateTimeoutValue[13] = 0.05;
stateTransitionOnTimeout[13]= "FireLoadCheckB2";

stateName[14] = "FireLoadCheckB2";
stateAllowImageChange[14] = false;
stateTransitionOnAmmo[14] = "Fire3";
stateTransitionOnNoAmmo[14]= "ReloadWait";

stateName[15] = "Fire3";
stateTransitionOnTimeout[15]= "FireLoadCheckA3";
stateTimeoutValue[15] = 0.01;
stateFire[15] = true;
stateAllowImageChange[15] = false;
stateScript[15] = "onFire";
stateWaitForTimeout[15] = true;
stateEmitter[15] = ME3Flash1Emitter;
stateEmitterTime[15] = 0.1;
stateEmitterNode[15] = "muzzleNode";
stateSound[15] = M4SFireSound;

stateName[16] = "FireLoadCheckA3";
stateScript[16] = "onLoadCheck";
stateAllowImageChange[16] = false;
stateTimeoutValue[16] = 0.05;
stateTransitionOnTimeout[16]= "FireLoadCheckB3";

stateName[17] = "FireLoadCheckB3";
stateAllowImageChange[17] = false;
stateTransitionOnAmmo[17] = "Fire4";
stateTransitionOnNoAmmo[17]= "ReloadWait";

stateName[18] = "Fire4";
stateTransitionOnTimeout[18]= "FireLoadCheckA4";
stateTimeoutValue[18] = 0.01;
stateFire[18] = true;
stateAllowImageChange[18] = false;
stateScript[18] = "onFire";
stateWaitForTimeout[18] = true;
stateEmitter[18] = ME3Flash1Emitter;
stateEmitterTime[18] = 0.1;
stateEmitterNode[18] = "muzzleNode";
stateSound[18] = M4SFireSound;

stateName[19] = "FireLoadCheckA4";
stateScript[19] = "onLoadCheck";
stateAllowImageChange[19] = false;
stateTimeoutValue[19] = 0.05;
stateTransitionOnTimeout[19]= "FireLoadCheckB4";

stateName[20] = "FireLoadCheckB4";
stateAllowImageChange[20] = false;
stateTransitionOnAmmo[20] = "Fire5";
stateTransitionOnNoAmmo[20]= "ReloadWait";

stateName[21] = "Fire5";
stateTransitionOnTimeout[21]= "FireLoadCheckA5";
stateTimeoutValue[21] = 0.01;
stateFire[21] = true;
stateAllowImageChange[21] = false;
stateScript[21] = "onFire";
stateWaitForTimeout[21] = true;
stateEmitter[21] = ME3Flash1Emitter;
stateEmitterTime[21] = 0.1;
stateEmitterNode[21] = "muzzleNode";
stateSound[21] = M4SFireSound;

stateName[22] = "FireLoadCheckA5";
stateScript[22] = "onLoadCheck";
stateAllowImageChange[22] = false;
stateTimeoutValue[22] = 0.05;
stateTransitionOnTimeout[22]= "FireLoadCheckB5";

stateName[23] = "FireLoadCheckB5";
stateAllowImageChange[23] = false;
stateTransitionOnAmmo[23] = "Fire6";
stateTransitionOnNoAmmo[23]= "ReloadWait";

stateName[24] = "Fire6";
stateTransitionOnTimeout[24]= "TriggerCheck";
stateTimeoutValue[24] = 0.01;
stateFire[24] = true;
stateAllowImageChange[24] = false;
stateScript[24] = "onFire";
stateWaitForTimeout[24] = true;
stateEmitter[24] = ME3Flash1Emitter;
stateEmitterTime[24] = 0.1;
stateEmitterNode[24] = "muzzleNode";
stateSound[24] = M4SFireSound;

Fixed, thanks Jetz
« Last Edit: April 03, 2012, 04:57:56 PM by Zloff »


Oh god don't use 24 states to do this.  It is a debugging nightmare, as you can tell, and it is a bitch to read, let alone edit.

Create a "fire" state and an "ammoCheck" state. Edit your ready state so the state script is "onReady."

In the onReady method, you want to set a variable on the person holding the weapon (%obj) that keeps track of the number of shots left to fire, and calls %obj.setImageAmmo(%slot, true) to let the state system know that the burst has more than 0 bullets left in it. Set your onReady method to transition into the ammoCheck when the trigger is down.

ammoCheck just consists of 3 bits of information - the name, stateTransitionOnAmmo, which is set to the name of the fire state, and stateTransitionOnNoAmmo, which is set to some delay or cooldown state.

In the onFire method (you can define it yourself and call the parent if you haven't already), decrease that variable for number of shots left in the burst, and call %obj.setImageAmmo(%slot, false) if that variable is zero.

If you need further explanation on the methods, I may be able to help when I'm back on my main computer. If you don't understand the state system, then you may want to practice with other weapons a bit more.