Author Topic: Holding down to spam fire  (Read 615 times)

I'm trying to make a gun that more or less spams, and I don't know of any addons off the top of my head for seeing code to copy.
I thought that making the 2nd state recursive (so that fire loops right back to fire when used).

How can I make it so that the 2nd state (fire) repeats when held down until it's no longer held down? How can I make it spammy by working with something other than having no delay?

Code: [Select]
datablock ShapeBaseImageData(gunImage)
{
   // Basic Item properties
   shapeFile = "./pistol.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = 0; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 0" );

   // 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 = true;

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

   // Projectile && Ammo.
   item = BowItem;
   ammo = " ";
   projectile = gunProjectile;
   projectileType = Projectile;

casing = gunShellDebris;
shellExitDir        = "1.0 -1.3 1.0";
shellExitOffset     = "0 0 0";
shellExitVariance   = 0;
shellVelocity       = 7;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = false;

   doColorShift = true;
   colorShiftColor = gunItem.colorShiftColor;//"0.400 0.196 0 1.000";

   //casing = " ";

   // 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;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

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

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Fire";
stateTimeoutValue[2]            = 0.25;
stateFire[2]                    = true;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "Fire";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = false;
stateEmitter[2] = gunFlashEmitter;
stateEmitterTime[2] = 5;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = gunShot1Sound;
stateEjectShell[2]       = true;
}

Never mind, I figured it out.
EDIT: Nope
« Last Edit: March 20, 2017, 11:46:18 AM by theviacom »

if you have the fire state always transition to itself, it will go on forever. just have it transition to the ready state and it should work. you can just change the fire timeout values to something smaller to make it faster.

edit: also make sure stateWaitForTimeout[2] = true
« Last Edit: March 20, 2017, 05:54:57 PM by EcstaticEggplant »

there are many automatic weapons
a few that come to mind is ephi's shotgun, the minigun, there was an uzi, and the TF2 weapons (shotgun, flamethrower, minigun...), and I think the default rocket launcher

if you have the fire state always transition to itself, it will go on forever. just have it transition to the ready state and it should work. you can just change the fire timeout values to something smaller to make it faster.

edit: also make sure stateWaitForTimeout[2] = true


Thank you!