Author Topic: Shotgun script  (Read 2558 times)

stateName[0]                     = "Activate";
   stateTimeoutValue[0]             = 0.15;
   stateTransitionOnTimeout[0]       = "Ready";
   stateSound[0]               = weaponSwitchSound;

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

   stateName[2]                    = "Fire";
   stateTransitionOnTimeout[2]     = "Smoke";
   stateTimeoutValue[2]            = 0.40;
   stateFire[2]                    = true;
   stateAllowImageChange[2]        = false;
   stateSequence[2]                = "Fire";
   stateScript[2]                  = "onFire";
   stateWaitForTimeout[2]         = true;
   stateEmitter[2]               = ShotgunHL2FlashEmitter;
   stateEmitterTime[2]            = 0.05;
   stateEmitterNode[2]            = "muzzleNode";
   stateSound[2]               = ShotgunHL2Shot1Sound;
   stateEjectShell[2]       = true;

   stateName[3] = "Smoke";
   stateEmitter[3]               = ShotgunHL2SmokeEmitter;
   stateEmitterTime[3]            = 0.05;
   stateEmitterNode[3]            = "muzzleNode";
   stateTimeoutValue[3]            = 0.01;
   stateTransitionOnTimeout[3]     = "Reload";

   stateName[4]                 = "Reload";
   stateSequence[4]                = "Action";
   stateSound[4]                   = gunreloadSound;
   stateTransitionOnTriggerUp[4]     = "Ready";
   

};


OK, I just tested it out, and the bullet spread doesn't work. Only a single bullet comes out. Jeez, making addons is tougher than I expected.

Could you post the most up-to-date version of this add-on you have?

The one I have right now uses this
Code: (server.cs) [Select]
function shotgunImage::onFire(%this,%obj,%slot)
{
if(%obj.getDamagePercent() < 1.0)
%obj.playThread(2, shiftAway);
Parent::onFire(%this,%obj,%slot);
}

And I'm pretty sure that wouldn't even fire at all.

function ShotgunImage::onFire(%this,%obj,%slot)
{
   if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
      return;
   %obj.lastFireTime = getSimTime();
     
   %obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
   %obj.playThread(2, shiftAway);

   %projectile = %this.projectile;
   %spread = 0.0015;
   %shellcount = 3;

   for(%shell=0; %shell<%shellcount; %shell++)
   {
      %vector = %obj.getMuzzleVector(%slot);
      %objectVelocity = %obj.getVelocity();
      %vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
      %vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
      %velocity = VectorAdd(%vector1,%vector2);
      %x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
      %y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
      %z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
      %mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
      %velocity = MatrixMulVector(%mat, %velocity);

      %p = new (%this.projectileType)()
      {
         dataBlock = %projectile;
         initialVelocity = %velocity;
         initialPosition = %obj.getMuzzlePoint(%slot);
         sourceObject = %obj;
         sourceSlot = %slot;
         client = %obj.client;
      };
      MissionCleanup.add(%p);
   }
   return %p;
}

I fixed the reload by the way. The problem was stateTransitionOnTriggerUp was making it so that the animation played until you stopped holding the fire button. Silly me.

Okay, problem with the spread fixed. I needed to change Shotgun to ShotgunHL2 (Name of my gun).

So, are any problems left? Or did you fix them all?

So, are any problems left? Or did you fix them all?
All fixed. Thanks to everyone that helped, and I hope this helps other people as well.