Author Topic: Gun wont work  (Read 1323 times)

I have been working on a server for a while now a DM server and 1 of my top priorities is getting a weapon ammo system in place and so far iv been doing well but i cant get 2 of the weapons to work with the system no matter what i do iv pasted the files bellow if someone could find the problem and explain what i did wrong that would be a big help.

The 1st gun is the autoLaser:

//LaserAutoRifle.cs
//based off of gun, edited to rapid fire and spread
//green version
//after 17 edits it was done, thusly it is the ALR-17G

exec("Add-Ons/Resource_Lasers.code");

//bullet trail effects
datablock ParticleData(autolaserTrailParticle)
{
   dragCoefficient      = 3;
   gravityCoefficient   = -0.0;
   inheritedVelFactor   = 1.0;
   constantAcceleration = 0.0;
   lifetimeMS           = 1000;
   lifetimeVarianceMS   = 25;
   textureName          = "base/data/particles/dot";
   spinSpeed      = 10.0;
   spinRandomMin      = -500.0;
   spinRandomMax      = 500.0;
   colors[0]     = "0.0 0.8 0.0 0.4";
   colors[1]     = "0.0 0.9 0.0 0.0";
   sizes[0]      = 0.15;
   sizes[1]      = 0.25;

   useInvAlpha = false;
};
datablock ParticleEmitterData(autolaserTrailEmitter)
{
   ejectionPeriodMS = 0.01;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "autolaserTrailParticle";
};

datablock ExplosionData(autoLaserExplosion)
{
   //explosionShape = "";
   soundProfile = laserHitSound;

   lifeTimeMS = 150;

   particleEmitter = LaserExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Dynamic light
   lightStartRadius = 0;
   lightEndRadius = 2;
   lightStartColor = "0.0 0.9 0.0";
   lightEndColor = "0 0 0";
};


AddDamageType("autoLaser",   '<bitmap:add-ons/ci/autoLaser> %1',    '%2 <bitmap:add-ons/ci/autoLaser> %1',0.5,1);
datablock ProjectileData(autoLaserProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 10;
   directDamageType    = $DamageType::autoLaser;
   radiusDamageType    = $DamageType::autoLaser;

   brickExplosionRadius = 0;
   brickExplosionImpact = true;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 10;
   brickExplosionMaxVolume = 3;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloati ng = 6;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse        = 200;
   verticalImpulse     = 200;
   explosion           = autoLaserExplosion;
   particleEmitter     = autolaserTrailEmitter;

   muzzleVelocity      = 60;
   velInheritFactor    = 1;

   armingDelay         = 00;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = false;
   gravityMod = 0.0;

   hasLight    = True;
   lightRadius = 6.0;
   lightColor  = "0.0 0.9 0.0";
};

//////////
// item //
//////////
datablock ItemData(autoLaserItem)
{
   category = "Weapon";  // Mission editor category
   className = "Weapon"; // For inventory system

    // Basic Item Properties
   shapeFile = "./shapes/LaserAssaultRifle.dts";
   rotate = false;
   mass = 1;
   density = 0.2;
   elasticity = 0.2;
   friction = 0.6;
   emap = true;

   //gui stuff
   uiName = "ALR-17G";
   iconName = "./ItemIcons/LaserAutoRifle";
   doColorShift = true;
   colorShiftColor = "1.0 1.0 1.0 1.000";

    // Dynamic properties defined by the scripts
   image = autoLaserImage;
   canDrop = true;
};

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(autoLaserImage)
{
   // Basic Item properties
   shapeFile = "./shapes/laserAssaultRifle.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 = autoLaserProjectile;
   projectileType = Projectile;

   casing = autoLaserShellDebris;
   shellExitDir        = "1.0 -1.3 1.0";
   shellExitOffset     = "0 0 0";
   shellExitVariance   = 15.0;   
   shellVelocity       = 7.0;

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

   doColorShift = true;
   colorShiftColor = autoLaserItem.colorShiftColor;//"0 0.5 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.05;
   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.05;
   stateFire[2]                    = true;
   stateAllowImageChange[2]        = false;
   stateSequence[2]                = "Fire";
   stateScript[2]                  = "onFire";
   stateWaitForTimeout[2]         = true;
   stateEmitterTime[2]            = 0.05;
   stateEmitterNode[2]            = "muzzleNode";
   stateSound[2]               = LaserShotSound;
   stateEjectShell[2]       = true;

   stateName[3] = "Smoke";
   stateEmitterTime[3]            = 0.05;
   stateEmitterNode[3]            = "muzzleNode";
   stateTimeoutValue[3]            = 0.05;
   stateTransitionOnTimeout[3]     = "Ready";

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

};

function autolaserImage::onFire(%this,%obj,%slot)
{
   %projectile = %this.projectile;
   %spread = 0.0025;
   %shellcount = 1;

   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;
}

The second gun is the Flak Cannon:

//flakCannon.cs
//Ephialtes

if(!isObject(rocketExplosionEmitter))
   exec("Add-Ons/Weapon_Rocket Launcher.cs");
if(!isObject(gunExplosionEmitter))
   exec("Add-Ons/Weapon_Gun.cs");

//audio
datablock AudioProfile(flakShot1Sound)
{
   filename = "./sound/gunShot1.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(flakExplosionSound)
{
   filename = "./sound/spearHit.wav";
   description = AudioClose3d;
   preload = false;
};

datablock AudioProfile(flakHitSound)
{
   filename = "./sound/arrowHit.wav";
   description = AudioClose3d;
   preload = true;
};

//muzzle flash effects
datablock ParticleData(flakFlashParticle)
{
   dragCoefficient      = 6;
   gravityCoefficient   = 0;
   inheritedVelFactor   = 0;
   constantAcceleration = 0.0;
   lifetimeMS           = 350;
   lifetimeVarianceMS   = 15;
   textureName          = "base/data/particles/star1";
   spinSpeed      = 10.0;
   spinRandomMin      = -500.0;
   spinRandomMax      = 500.0;
   colors[0]     = "0.9 0.9 0.0 0.9";
   colors[1]     = "0.9 0.5 0.0 0.0";
   sizes[0]      = 0.2;
   sizes[1]      = 0.3;

   useInvAlpha = false;
};
datablock ParticleEmitterData(flakFlashEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 3.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0;
   thetaMin         = 0;
   thetaMax         = 40;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "flakFlashParticle";
};

datablock ParticleData(flakSmokeParticle)
{
   dragCoefficient      = 3;
   gravityCoefficient   = -0.5;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 525;
   lifetimeVarianceMS   = 55;
   textureName          = "base/data/particles/cloud";
   spinSpeed      = 10.0;
   spinRandomMin      = -500.0;
   spinRandomMax      = 500.0;
   colors[0]     = "0.5 0.5 0.5 0.2";
   colors[1]     = "0.5 0.5 0.5 0.0";
   sizes[0]      = 0.15;
   sizes[1]      = 0.15;

   useInvAlpha = false;
};
datablock ParticleEmitterData(flakSmokeEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 1.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "flakSmokeParticle";
};

//trails
datablock ParticleData(flakTrailParticle)
{
   dragCoefficient      = 3;
   gravityCoefficient   = -0.0;
   inheritedVelFactor   = 0.0;
   constantAcceleration = 0.0;
   lifetimeMS           = 225;
   lifetimeVarianceMS   = 55;
   textureName          = "base/data/particles/dot";
   spinSpeed      = 10.0;
   spinRandomMin      = -500.0;
   spinRandomMax      = 500.0;
   colors[0]     = "0.9 0.2 0.2 0.4";
   colors[1]     = "0.6 0.4 0.0 0.0";
   sizes[0]      = 0.15;
   sizes[1]      = 0.25;

   useInvAlpha = false;
};
datablock ParticleEmitterData(flakTrailEmitter)
{
   ejectionPeriodMS = 4;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "flakTrailParticle";
};

datablock ParticleData(flakTrailParticleB)
{
   dragCoefficient      = 3;
   gravityCoefficient   = -0.0;
   inheritedVelFactor   = 0.0;
   constantAcceleration = 0.0;
   lifetimeMS           = 225;
   lifetimeVarianceMS   = 55;
   textureName          = "base/data/particles/cloud";
   spinSpeed      = 10.0;
   spinRandomMin      = -500.0;
   spinRandomMax      = 500.0;
   colors[0]     = "0.9 0.2 0.2 0.4";
   colors[1]     = "0.6 0.4 0.0 0.0";
   sizes[0]      = 0.55;
   sizes[1]      = 0.65;

   useInvAlpha = false;
};
datablock ParticleEmitterData(flakTrailEmitterB)
{
   ejectionPeriodMS = 4;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "flakTrailParticleB";
};

//Explosion particles
datablock ParticleData(flakExplosionParticle)
{
   dragCoefficient      = 8;
   gravityCoefficient   = -0.5;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 700;
   lifetimeVarianceMS   = 400;
   textureName          = "base/data/particles/cloud";
   spinSpeed      = 10.0;
   spinRandomMin      = -50.0;
   spinRandomMax      = 50.0;
   colors[0]     = "0.9 0.9 0.6 0.9";
   colors[1]     = "0.9 0.5 0.6 0.0";
   sizes[0]      = 0.25;
   sizes[1]      = 1.0;

   useInvAlpha = true;
};
datablock ParticleEmitterData(flakExplosionEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "flakExplosionParticle";
};

datablock ParticleData(flakExplosionRingParticle)
{
   dragCoefficient      = 8;
   gravityCoefficient   = -0.5;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 300;
   lifetimeVarianceMS   = 100;
   textureName          = "base/data/particles/star1";
   spinSpeed      = 10.0;
   spinRandomMin      = -50.0;
   spinRandomMax      = 50.0;
   colors[0]     = "1 1 0.0 0.9";
   colors[1]     = "0.9 0.0 0.0 0.0";
   sizes[0]      = 0.2;
   sizes[1]      = 0.2;

   useInvAlpha = false;
};
datablock ParticleEmitterData(flakExplosionRingEmitter)
{
   lifeTimeMS = 50;

      ejectionPeriodMS = 1;
      periodVarianceMS = 0;
      ejectionVelocity = 5;
      velocityVariance = 0.0;
      ejectionOffset   = 0.0;
      thetaMin         = 89;
      thetaMax         = 90;
      phiReferenceVel  = 0;
      phiVariance      = 360;
      overrideAdvance = false;
      particles = "flakExplosionRingParticle";
};

//Explosion datablocks
datablock ExplosionData(flakShellExplosion)
{
   //explosionShape = "";
   explosionShape = "./shapes/explosionSphere1.dts";
   soundProfile = flakExplosionSound;

   lifeTimeMS = 150;

   particleEmitter = rocketExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = rocketExplosionRingEmitter;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "3.0 10.0 3.0";
   camShakeDuration = 0.5;
   camShakeRadius = 20.0;

   // Dynamic light
   lightStartRadius = 5;
   lightEndRadius = 20;
   lightStartColor = "1 1 1 1";
   lightEndColor = "0 0 0 0";

   damageRadius = 7;
   radiusDamage = 100;

   impulseRadius = 10;
   impulseForce = 4000;
};

datablock ExplosionData(flakExplosion)
{
   //explosionShape = "";
   soundProfile = bulletHitSound;

   lifeTimeMS = 150;

   particleEmitter = gunExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = gunExplosionRingEmitter;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Dynamic light
   lightStartRadius = 0;
   lightEndRadius = 2;
   lightStartColor = "0.3 0.6 0.7";
   lightEndColor = "0 0 0";

   damageRadius = 0;
   radiusDamage = 100;

   impulseRadius = 0;
   impulseForce = 4000;
};

//Projectiles
AddDamageType("FlakShellDirect",   '<bitmap:add-ons/ci/flakCannon> %1',    '%2 <bitmap:add-ons/ci/flakCannon> %1',1,1);
AddDamageType("FlakShellRadius",   '<bitmap:add-ons/ci/flakCannonRadius> %1',    '%2 <bitmap:add-ons/ci/flakCannonRadius> %1',1,0);
datablock ProjectileData(flakProjectileA)
{
   projectileShapeName = "./shapes/flakShell.dts";
   directDamage        = 60;
   directDamageType    = $DamageType::FlakShellDirect;
   radiusDamageType    = $DamageType::FlakShellRadius;

   brickExplosionRadius = 4;
   brickExplosionImpact = false;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 30;
   brickExplosionMaxVolume = 30;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloati ng = 60;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse        = 1000;
   verticalImpulse     = 1000;
   explosion           = flakShellExplosion;
   particleEmitter     = flakTrailEmitterB;

   muzzleVelocity      = 30;
   velInheritFactor    = 1;

   armingDelay         = 0;
   lifetime            = 5000;
   fadeDelay           = 5000;
   bounceElasticity    = 0.6;
   bounceFriction      = 0.5;
   isBallistic         = true;
   gravityMod = 1.0;
   explodeOnDeath = true;

   hasLight    = true;
   lightRadius = 4.0;
   lightColor  = "0.9 0.3 0.1";
};

AddDamageType("FlakDirect",   '<bitmap:add-ons/ci/flakShrapnel> %1',    '%2 <bitmap:add-ons/ci/flakShrapnel> %1',1,0);
datablock ProjectileData(flakProjectileB)
{
   projectileShapeName = "./shapes/bullet.dts";
   directDamage        = 20;
   directDamageType    = $DamageType::FlakDirect;
   radiusDamageType    = $DamageType::FlakDirect;

   brickExplosionRadius = 0;
   brickExplosionImpact = true;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 10;
   brickExplosionMaxVolume = 1;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloati ng = 2;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse        = 5;
   verticalImpulse     = 10;
   explosion           = flakExplosion;
   particleEmitter     = flakTrailEmitter;

   muzzleVelocity      = 90;
   velInheritFactor    = 1;

   armingDelay         = 5000;
   lifetime            = 5000;
   fadeDelay           = 5000;
   bounceElasticity    = 0.6;
   bounceFriction      = 0.5;
   isBallistic         = true;
   gravityMod = 0.8;
   explodeOnDeath = false;

   hasLight    = true;
   lightRadius = 1.0;
   lightColor  = "0.9 0.3 0.1";
};

datablock ProjectileData(flakProjectileBCol)
{
   projectileShapeName = "./shapes/bullet.dts";
   directDamage        = 20;
   directDamageType    = $DamageType::FlakDirect;
   radiusDamageType    = $DamageType::FlakDirect;

   brickExplosionRadius = 0;
   brickExplosionImpact = true;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 10;
   brickExplosionMaxVolume = 1;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloati ng = 2;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse        = 5;
   verticalImpulse     = 10;
   explosion           = flakExplosion;
   particleEmitter     = flakTrailEmitter;

   muzzleVelocity      = 1;
   velInheritFactor    = 1;

   armingDelay         = 0;
   lifetime            = 1000;
   fadeDelay           = 1000;
   bounceElasticity    = 0.6;
   bounceFriction      = 0.3;
   isBallistic         = true;
   explodeOnDeath      = true;
   gravityMod          = 0.8;

   hasLight    = false;
   lightRadius = 3.0;
   lightColor  = "0 0 0.5";
};

//Item
datablock ItemData(FlakItem)
{
   category = "Weapon";  // Mission editor category
   className = "Weapon"; // For inventory system

    // Basic Item Properties
   shapeFile = "./shapes/flakcannon.dts";
   rotate = false;
   mass = 1;
   density = 0.2;
   elasticity = 0.2;
   friction = 0.6;
   emap = true;

   //gui stuff
   uiName = "Flak Cannon";
   iconName = "./ItemIcons/flakCannon";
   doColorShift = false;
   colorShiftColor = "0.25 0.25 0.25 1.000";

    // Dynamic properties defined by the scripts
   image = flakImage;
   canDrop = true;
};

//Image
datablock ShapeBaseImageData(flakImage)
{
   // Basic Item properties
   shapeFile = "./shapes/flakcannon.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "-0.1 0.68 -0.2";
   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 = flakProjectileA;
   projectileType = Projectile;
   minShotTime = 1800;   //minimum time allowed between shots (needed to prevent equip/dequip exploit)

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

   doColorShift = false;
   colorShiftColor = flakItem.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.15;
   stateTransitionOnTimeout[0]      = "Ready";
   stateSound[0]            = weaponSwitchSound;

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

   stateName[2]                     = "Fire";
   stateTransitionOnTimeout[2]      = "Smoke";
   stateTimeoutValue[2]             = 0.2;
   stateFire[2]                     = true;
   stateAllowImageChange[2]         = false;
   stateSequence[2]                 = "Fire";
   stateScript[2]                   = "onFire";
   stateWaitForTimeout[2]         = true;
   stateEmitter[2]            = flakFlashEmitter;
   stateEmitterTime[2]         = 0.05;
   stateEmitterNode[2]         = "muzzleNode";
   stateSound[2]            = flakShot1Sound;

   stateName[3]             = "Smoke";
   stateEmitter[3]               = flakSmokeEmitter;
   stateEmitterTime[3]         = 1.2;
   stateEmitterNode[3]         = "muzzleNode";
   stateTimeoutValue[3]             = 0.4;
   stateTransitionOnTimeout[3]      = "CoolDown";

   stateName[4]            = "CoolDown";
   stateEmitter[4]            = flakSmokeEmitter;
   stateSequence[4]            = "eject";
   stateEmitterNode[4]         = "ejectPoint";
   stateEmitterTime[4]         = 0.3;
   stateTimeoutValue[4]             = 0.4;
   stateTransitionOnTimeout[4]      = "Reload";

   stateName[5]             = "Reload";
   stateSequence[5]            = "reload";
   stateTimeoutValue[5]             = 0.8;
   stateTransitionOnTimeout[5]      = "Ready";
};

function flakImage::onFire(%this,%obj,%slot)
{
   if(%obj.getImageAmmo(%slot))
   {
      %projectile = flakProjectileB;
      %spread = 0.003;
      %shellcount = getRandom(10,15);
   
      for(%shell=0; %shell<%shellcount; %shell++)
      {
         %vector = %obj.getMuzzleVector(%slot);
         %objectVelocity = %obj.getVelocity();
         %vector1 = VectorScale(%vector,(%projectile.muzzleVelocity+getRandom(-30,30)));
         %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;
   }
   else
   {
      %projectile = flakProjectileA;
      %spread = 0.0015;
      %shellcount = 1;

      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;   
   }
}

function flakProjectileB::onCollision(%this,%obj,%col,%fade,%pos,%norm)
{
   if(%col.getClassName() $= "Player")
      %obj.setDataBlock(flakProjectileBCol);
   else
   {
      %obj.numBounces++;
      serverPlay3D(hammerHitSound,%obj.getTransform());
   }
   Parent::onCollision(%this,%obj,%col,%fade,%pos,%norm);
}

function flakProjectileB::Damage(%this,%obj,%col,%fade,%pos,%norm)
{
   %bounces = %obj.numBounces;
   %damage = %this.directDamage-(%bounces*3);   
   %col.damage(%obj,%pos,%damage);
}

function flakProjectileBCol::Damage(%this,%obj,%col,%fade,%pos,%norm)
{
   %bounces = %obj.numBounces;
   %damage = %this.directDamage-(%bounces*3);   
   %col.damage(%obj,%pos,%damage);
}

package FlakCannon
{
   function armor::onTrigger(%this,%player,%slot,%val)
   {
      if(%slot $= 4 && %player.getMountedImage(0) $= flakImage.getID())
      {
         if(%val)
         {
            %player.setImageAmmo(0,0);
            %player.setImageTrigger(0,1);
            %player.setImageTrigger(0,0);
            %player.setImageAmmo(0,1);
         }
      }
      else
         Parent::onTrigger(%this,%player,%slot,%val);
   }
};
ActivatePackage(FlakCannon);

Then this is the ammo system script:


$inv[1,0] = nametoID(IonCannonProjectile);         //Projectile
$inv[1,1] = "Ion Cannon Battery";            //Inv Name
$inv[1,2] = "ioncannonbattery";            //Shortcut Name
$inv[1,3] = 1;                       //Amount
$inv[2,0] = nametoID(MinigunProjectile);         //Projectile
$inv[2,1] = "Minigun Ammo Box";            //Inv Name
$inv[2,2] = "minigunammobox";            //Shortcut Name
$inv[2,3] = 500;               //Amount
$inv[3,0] = nametoID(autoLaserProjectile);         //Projectile
$inv[3,1] = "autoLaser Ammo Box";            //Inv Name
$inv[3,2] = "autolaserammobox";            //Shortcut Name
$inv[3,3] = 250;               //Amount
$inv[4,0] = nametoID(flakProjectileA);         //Projectile
$inv[4,1] = "Flak Cannon Ammo Box";            //Inv Name
$inv[4,2] = "flakcannonammobox";            //Shortcut Name
$inv[4,3] = 100;               //Amount
$inv[5,0] = nametoID(flamethrowerProjectile);         //Projectile
$inv[5,1] = "Flamethrower Ammo Box";            //Inv Name
$inv[5,2] = "flamethrowerammobox";            //Shortcut Name
$inv[5,3] = 1000;               //Amount
$invX = 5;

package WeaponAmmo
{
   function GameConnection::CreatePlayer(%this,%a,%b,%c,%d,%e)
   {
      Parent::CreatePlayer(%this,%a,%b,%c,%d,%e);
      for(%i=1;%i<=$invX;%i++)
      {
         for(%j=0;%j<=5;%j++)
         {
            %this.inv[%i,%j] = $inv[%i,%j];
         }
      }
   }

   function WeaponImage::onFire(%this,%obj,%slot)
   {
      if(!%this.ammotype){Parent::onFire(%this,%obj,%slot);return;}
      %client = %obj.client;
      if(%client.ammotype[%this] && %client.inv[%client.ammotype[%this],3])
      {
      echo("Secondary Ammo");
      %projectile = %client.inv[%client.ammotype[%this],0];
          %client.inv[%client.ammotype[%this],3]--;
          commandtoclient(%client,'centerprint',"<just:left>" @ %client.inv[%client.ammotype[%this],1] @ ": " @ %client.inv[%client.ammotype[%this],3],1,1,10);
      }else if(%client.inv[%this.ammotype,3])
      {
       %projectile = %client.inv[%this.ammotype,0];
       %client.inv[%this.ammotype,3]--;
       commandtoclient(%client,'centerprint',"<just:left>" @ %client.inv[%this.ammotype,1] @ ": " @ %client.inv[%this.ammotype,3],1,1,10);
      }
      else{return;}
   
      // Determin initial projectile velocity based on the
      // gun's muzzle point and the object's current velocity
      %muzzleVector = %obj.getMuzzleVector(%slot);
      %objectVelocity = %obj.getVelocity();
      %muzzleVelocity = VectorAdd(
         VectorScale(%muzzleVector, %projectile.muzzleVelocity),
         VectorScale(%objectVelocity, %projectile.velInheritFactor));
   
      // Create the projectile object
      %p = new (%this.projectileType)() {
         dataBlock        = %projectile;
         initialVelocity  = %muzzleVelocity;
         initialPosition  = %obj.getMuzzlePoint(%slot);
         sourceObject     = %obj;
         sourceSlot       = %slot;
         client           = %obj.client;
      };
      MissionCleanup.add(%p);
      return %p;
   }
   
   function WeaponImage::onMount(%this,%obj,%slot)
   {
      Parent::onMount(%this,%obj,%slot);
      %client = %obj.client;
      if(%client.ammotype[%this] && %client.inv[%client.ammotype[%this],3])
      {
       commandtoclient(%client,'centerprint',"<just:left>" @ %client.inv[%client.ammotype[%this],1] @ ": " @ %client.inv[%client.ammotype[%this],3],1,1,10);
      }else if(%client.inv[%this.ammotype,3])
      {
       commandtoclient(%client,'centerprint',"<just:left>" @ %client.inv[%this.ammotype,1] @ ": " @ %client.inv[%this.ammotype,3],1,1,10);
      }
      else{return;}
   }
   
   function GameConnection::onDeath(%this,%a,%b,%c,%d)
   {
      makeitem(AmmoItem,%this.player.position);
      Parent::onDeath(%this,%a,%b,%c,%d);
   }
};
activatePackage(WeaponAmmo);

ioncannonImage.ammotype = 1;
minigunImage.ammotype = 2;
autolaserImage.ammotype = 3;
flakImage.ammotype = 4;
flamethrowerImage.ammotype = 5;

function servercmdInv(%client)
{
   messageclient(%client,"","\c5Inventory List:");
   for(%i=1;%i<=$invX;%i++)
   {
      if(%client.inv[%i,3] > 0)
      {
         messageclient(%client,"","\c5" @ %client.inv[%i,1] @ "\c0 (" @ %client.inv[%i,2] @ ") \c5x" @ %client.inv[%i,3]);
      }
   }
}

function servercmdUse(%client,%name)
{
   for(%i=1;%i<=$invX;%i++)
   {
      if(%client.inv[%i,2] $= %name && %client.inv[%i,3] > 0)
      {
         echo("Found1");
         if(%client.inv[%i,4] !$= "")
         {
            echo("Found2");
            %client.ammotype[%client.inv[%i,4]] = %i;
            messageclient(%client,"","\c0" @ %client.inv[%i,5] @ " \c5ammo set to \c0" @ %client.inv[%i,1]);
            return;
         }
         else
         {
            echo("Abort1");
            messageclient(%client,"","\c5Can't use that right now.");
            return;
         }
      }
   }
   echo("Abort2");
   messageclient(%client,"","\c5Inventory item \c0" @ %name @ " \c5not found.");
}