Weapon makes firing sound when I have no ammo! Help
by Jesse P · in Torque Game Engine · 07/28/2008 (4:59 pm) · 3 replies
When I have picked up ammo and fire my weapon until it runs out it makes the appropriate clicking sound when empty, HOWEVER when I change weapons and then change back to the empty weapon it makes the shooting sound as if it has ammo but no bullets come out. It does the same if I pick up the weapon for the first time but do not pick up ammo.
Any suggestions?
Any suggestions?
#2
I added:
&& %this.ammoInClip > 0
to the if statement in the following:
07/28/2008 (5:29 pm)
Ok I fixed HALF of it. Now when I change weapons when it is empty it gives the correct click noise when firing, but still when I pick up the weapon for the first time it does not display any ammo and plays the firing sound. Here is what I changed to fix the first half:I added:
&& %this.ammoInClip > 0
to the if statement in the following:
function famas62Image::onLoad(%this, %obj, %slot) // Single Shot onFire
{
%obj.client.setAmmoAmountHud(%obj.getInventory(%this.ammo));
if(%this.clipSize > 0 && %this.ammoInClip > 0)//&& %this.ammoInClip > 0
{
%obj.setImageAmmo(%slot, true);
}
}
#3
in the player.cs so the player starts out with ammo for that weapon so when he finds it and picks it up he already has 10 rounds.
07/28/2008 (5:34 pm)
Ok I fixed it, it's kinda a cheap way to fix it but hey it works, I simply set %player.setInventory(famas62Ammo,10);in the player.cs so the player starts out with ammo for that weapon so when he finds it and picks it up he already has 10 rounds.
Torque Owner Jesse P
datablock ShapeBaseImageData(famas62Image) // Single Shot Fire { shapeFile = "~/data/shapes/weapons/famas62/famas62.dts"; ammo = famas62Ammo; projectile = famas62Projectile; projectileType = Projectile; projectileSpread = 4 / 1000.0; emap = true; item = famas62; imageNum = 1; useCrosshair = true; crosshair = "starter.fps/data/shapes/weapons/famas62/crosshair.png"; useScope = false; clipSize = 30; ammoInClip = 30; correctMuzzleVector = false; eyeOffset = "0.0971429 0.4 -0.34"; stateName[0] = "Preactivate"; stateTransitionOnLoaded[0] = "Activate"; stateName[1] = "Activate"; stateTransitionOnTimeout[1] = "Carry"; stateScript[1] = "onLoad"; stateName[2] = "Carry"; stateTransitionOnTimeout[2] = "Carry"; stateTransitionOnNoAmmo[2] = "NoAmmoCarry"; stateTransitionOnTriggerDown[2] = "SingleShot"; stateAllowImageChange[2] = true; stateSequence[2] = "Sequence_Carry"; stateName[3] = "NoAmmoCarry"; stateTransitionOnTimeout[3] = "NoAmmoCarry"; stateTransitionOnTriggerDown[3] = "EmptyShot"; stateAllowImageChange[3] = true; stateSequence[3] = "Sequence_Carry"; stateName[4] = "Reload"; stateTransitionOnTimeout[4] = "Carry"; stateTimeoutValue[4] = 2; stateAllowImageChange[4] = true; stateSequence[4] = "Sequence_Reload"; stateScript[4] = "onReload"; stateSound[4] = famas62ReloadSound; stateName[5] = "EmptyShot"; stateTransitionOnTimeout[5] = "NoAmmoCarry"; stateTransitionOnAmmo[5] = "Reload"; stateTimeoutValue[5] = 0.28; stateAllowImageChange[5] = true; stateSequence[5] = "Sequence_Fire"; stateScript[5] = "onEmptyShot"; stateSound[5] = famas62EmptyShotSound; stateName[6] = "SingleShot"; stateTransitionOnTimeout[6] = "Carry"; stateTransitionOnNoAmmo[6] = "NoAmmoCarry"; stateTimeoutValue[6] = 0.17; stateAllowImageChange[6] = true; stateFire[6] = true; stateSequence[6] = "Sequence_Fire"; stateScript[6] = "onFire"; stateSound[6] = famas62SingleShotSound; }; function famas62Image::onLoad(%this, %obj, %slot) // Single Shot onFire { if(%this.clipSize > 0) { %obj.setImageAmmo(%slot, true); %obj.client.setAmmoAmountHud(%obj.getInventory(%this.ammo)); } } function famas62Image::onFire(%this, %obj, %slot) // Single Shot onFire { if(%this.ammo !$="") { %obj.setImageAmmo(%slot, true); if(%obj.getInventory(%this.ammo) <= 0) return; %obj.decInventory(%this.ammo, 1); %currentAmmo = %obj.getInventory(%this.ammo); %obj.client.setAmmoAmountHud(%currentAmmo); %this.ammoInClip--; } if(%this.ammoInClip <= 0) { %obj.setImageAmmo(%slot, false); } %this.lightStart = getSimTime(); if(%this.projectileSpread) { %vec = %obj.getMuzzleVector(%slot); %x = (getRandom() - 0.5) * 2 * 3.1415926 * %this.projectileSpread; %y = (getRandom() - 0.5) * 2 * 3.1415926 * %this.projectileSpread; %z = (getRandom() - 0.5) * 2 * 3.1415926 * %this.projectileSpread; %mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z); %muzzleVector = MatrixMulVector(%mat, %vec); } else { %muzzleVector = MatrixMulVector("0 0 0 0 0 1 0", %obj.getMuzzleVector(%slot)); } %objectVelocity = %obj.getVelocity(); %muzzleVelocity = VectorAdd(VectorScale(%muzzleVector, %this.projectile.muzzleVelocity), VectorScale(%objectVelocity, %this.projectile.velInheritFactor)); %p = new (%this.projectileType)() { dataBlock = %this.projectile; initialVelocity = %muzzleVelocity; initialDirection = %muzzleVector; initialPosition = %obj.getMuzzlePoint(%slot); sourceObject = %obj; sourceSlot = %slot; origin = %obj; client = %obj.client; }; if (isObject(%obj.lastProjectile) && %obj.deleteLastProjectile) %obj.lastProjectile.delete(); %obj.deleteLastProjectile = %this.deleteLastProjectile; if(%obj.client) %obj.client.projectile = %p; MissionCleanup.add(%p); return %p; } function famas62Image::onReload(%this, %obj, %slot) // Single Shot onReload { if(%obj.getInventory(%this.ammo) < %this.clipSize) { %this.ammoInClip = %obj.getInventory(%this.ammo); } else { %this.ammoInClip = %this.clipSize; } } function famas62Image::onEmptyShot(%this, %obj, %slot) // Single Shot onEmptyShot { if(%ammoInClip <= 0 && %obj.getInventory(%this.ammo) > 0) { %obj.setImageAmmo(%slot, true); } }