Author Topic: Manual Reloading Glitch  (Read 2239 times)

I've been using Cystalwarrior's HL2 Ammo System, but I've came to this glitch where I'm able to reload even when I got no ammo left. (0/0)

here's da code:

Code: [Select]
//########## Ammo System
if($KhainMods::Server::wstldrAmmoSystemVersion > 1)
{
return;
}

$KhainMods::Server::wstldrAmmoSystemVersion = 1;
function wstldrAmmoCheck(%this,%obj,%slot)
{
if(!$wstldrWeapons::ammoSystem)
{
return;
}

if(%obj.toolMag[%obj.currTool] $= "")
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
}

if(%obj.toolAltMag[%this.item.altammotype] $= "" && %this.item.altmaxmag !$= "")
{
%obj.toolAltMag[%this.item.altammotype] = 0;//%this.item.altmaxmag;
}

if(%obj.toolAmmo[%this.item.ammotype] $= "")
{
%obj.toolAmmo[%this.item.ammotype] = $wstldrWeapons::AddAmmo[%this.item.ammotype];
}

if(%obj.toolMag[%obj.currTool] < 1)
{
%obj.toolMag[%obj.currTool] = 0;
%obj.setImageAmmo(0,0);
if(%obj.toolAmmo[%this.item.ammotype] < 1)
{
%obj.toolMag[%obj.currTool] = %obj.toolAmmo[%this.item.ammotype] = 0;
}
}

if(%obj.toolMag[%obj.currTool] > %this.item.maxmag)
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
}
}

function wstldrAmmoOnReload(%this,%obj,%slot)
{
if(!$wstldrWeapons::ammoSystem)
{
return;
}
if($wstldrWeapons::Ammo)
{
if(%this.item.nochamber)
{
%a = %this.item.maxmag - %obj.toolMag[%obj.currTool];
if(%a > %obj.toolAmmo[%this.item.ammotype])
%a = %obj.toolAmmo[%this.item.ammotype];
%obj.toolMag[%obj.currTool] += %a;
%obj.toolAmmo[%this.item.ammotype] -= %a;
%obj.setImageAmmo(0,1);
}
else
{
if(%obj.toolMag[%obj.currTool] > 0)
{
%a = (%this.item.maxmag) - %obj.toolMag[%obj.currTool];
if(%a > %obj.toolAmmo[%this.item.ammotype])
%a = %obj.toolAmmo[%this.item.ammotype];
%obj.toolMag[%obj.currTool] += %a;
%obj.toolAmmo[%this.item.ammotype] -= %a;
%obj.setImageAmmo(0,1);
}
else
{
%a = %this.item.maxmag - %obj.toolMag[%obj.currTool];
if(%a > %obj.toolAmmo[%this.item.ammotype])
%a = %obj.toolAmmo[%this.item.ammotype];
%obj.toolMag[%obj.currTool] += %a;
%obj.toolAmmo[%this.item.ammotype] -= %a;
%obj.setImageAmmo(0,0);
}
}
}
else
{
if(%this.item.nochamber)
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
%obj.setImageAmmo(0,1);
}
else
{
if(%obj.toolMag[%obj.currTool] > 0)
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
%obj.setImageAmmo(0,1);
}
else
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
%obj.setImageAmmo(0,0);
}
}
}
}

function wstldrAmmoOnReloadSingle(%this,%obj,%slot)
{
if(!$wstldrWeapons::ammoSystem)
{
return;
}
if($wstldrWeapons::Ammo)
{
%obj.toolMag[%obj.currTool]++;
%obj.toolAmmo[%this.item.ammotype]--;
if(%obj.toolAmmo[%this.item.ammotype] < 1) {
%obj.setImageAmmo(0,1);
return; }
else
%obj.setImageAmmo(0,0);
if(%obj.toolMag[%obj.currTool] < %this.item.maxmag)
%obj.setImageAmmo(0,0);
else
%obj.setImageAmmo(0,1);
}
else
{
%obj.toolMag[%obj.currTool]++;
if(%obj.toolMag[%obj.currTool] < %this.item.maxmag)
%obj.setImageAmmo(0,0);
else
%obj.setImageAmmo(0,1);
}
}

function wstldrDisplayAmmo(%this, %obj, %slot, %delay) {
if (!$wstldrWeapons::ShowAmmo || !isObject(%obj.client)) {
return;
}

if (%delay == -1) {
clearBottomPrint(%obj.client);
return;
}

%altMag = %obj.toolAltMag[%this.item.altAmmoType];

if (%altMag !$= "") {
%altAmmoText = "    " SPC %altmag;
}

if ($wstldrWeapons::Ammo == 0) {
%str = %obj.toolMag[%obj.currTool] @ "/" @ %this.item.maxMag;
}
else {
%str = %obj.toolMag[%obj.currTool] @ "/" @ %obj.toolAmmo[%this.item.ammoType];
}

%ammocol = "<color:FFFFFF>";
%str = %str SPC "<font:impact:22>" @ ( %altAmmoText !$= "" ? %altAmmoText SPC "<font:impact:20>ALT" : "" );
%obj.client.bottomPrint(%ammocol @ "<font:impact:22><just:right>" @ %str SPC "\n", %delay, 1);
}

package wstldrAmmoSystem
{
function gameConnection::onDeath( %client, %source, %killer, %type, %location )
{
wstldrDisplayAmmo(0, %client.player, %slot, -1);
parent::onDeath( %client, %source, %killer, %type, %location );
}

function Player::pickUp(%this,%item)
{
%data = %item.dataBlock;

if(%item.mag !$= "")
{
%mag = %item.mag;
}
%parent = parent::pickUp(%this,%item);
if(!%data.reload || !$wstldrWeapons::ammoSystem)
{
return %parent;
}

%slot = -1;
for(%i=0;%i<%this.dataBlock.maxTools;%i++)
{
if(isObject(%this.tool[%i]) && %this.tool[%i].getID() == %data.getID())
{
%slot = %i;
break;
}
}
if(%slot == -1)
{
return;
}
if(%mag !$= "")
{
%this.toolMag[%slot] = %mag;
}
else
{
%this.toolmag[%slot] = %data.maxmag;
}
}

function serverCmdDropTool(%client,%slot)
{
if(isObject(%client.player))
{
%item = %client.player.tool[%client.player.currTool];
$wstldrweaponMag = %client.player.toolMag[%client.player.currTool];
%client.player.toolMag[%client.player.currTool] = "";
}
parent::serverCmdDropTool(%client,%slot);
%client.player.unMountImage(0);
}

function ItemData::onAdd(%this,%obj)
{
parent::onAdd(%this,%obj);
if($wstldrweaponMag !$= "") { %obj.mag = $wstldrweaponMag; $wstldrweaponMag = ""; }
}

function serverCmdLight(%client)
{
if(isObject(%client.player)) {
%player = %client.player;
%image = %player.getMountedImage(0);
if(%image.item.reload && $wstldrWeapons::ammoSystem)
{
if(%player.getImageState(0) $= "Ready" || %player.getImageState(0) $= "Empty")
{
if(%player.toolMag[%player.currTool] < %image.item.maxmag)
{
if($wstldrWeapons::Ammo && %player.toolAmmo[%image.item.ammotype] < 1) { parent::serverCmdLight(%client); return; }
%player.setImageAmmo(0,0);
%player.Schedule(50,setImageAmmo,0,1);
}
else
parent::serverCmdLight(%client);
}
return;
}
}
parent::serverCmdLight(%client);
}

function Armor::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f)
{
if(%col.dataBlock.reload $= "" && %col.dataBlock.ammoBox $= "" || !$wstldrWeapons::Ammo || !$wstldrWeapons::ammoSystem)
{
if(%col.dataBlock.ammoBox)
{
return;
}
parent::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f);
return;
}

if(%col.dataBlock.ammoBox && ( %col.dataBlock.ammoType !$= "" || %col.dataBlock.altAmmoType !$= "" ) && %col.canPickup && %obj.getDamagePercent() < 1 && minigameCstar fishe(%obj.client,%col))
{
if( %col.dataBlock.ammoType $= "ALL" )
{
for(%i=0; %i < %obj.dataBlock.maxTools; %i++)
{
if(isObject(%obj.tool[%i]) && %obj.toolAmmo[%obj.tool[%i].ammotype] < $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype])
{
%newAmmo = $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
if(%obj.toolAmmo[%obj.tool[%i].ammotype] + $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype] > $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype])
{
%newAmmo = ( %obj.toolAmmo[%obj.tool[%i].ammotype] - $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype] ) * -1;
%obj.toolAmmo[%obj.tool[%i].ammotype] = $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype];
}
else
{
%obj.toolAmmo[%obj.tool[%i].ammotype] += $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
}
%item = %obj.tool[%obj.currTool];
for(%a = 0; %a <= 3; %a++)
{
if(%obj.line[%a] $= "")
{
//%obj.line[%a] = "<just:right><font:Tahoma:22><color:DBA901>+" @ %newAmmo SPC %obj.tool[%i].ammoType;
//break;
}
}
if( %item $= %obj.tool[%i] )
{
wstldrDisplayAmmo(%item.image, %obj, %obj.currTool);
}
}
}
for(%a = 0; %a <= 3; %a++)
{
if(%obj.line[%a] !$= "")
{
%text = %text @ %obj.line[%a] @ "<br>";
}
else
{
break;
}
}
commandToClient(%obj.client, 'centerPrint', %text, 2);
for(%a = 0; %a <= 4; %a++)
{
%obj.line[%a] = "";
}
}
else
{
for(%i=0; %i < %obj.dataBlock.maxTools; %i++)
{
if(isObject(%obj.tool[%i]) && %obj.tool[%i].ammotype $= %col.dataBlock.ammoType && %obj.toolAmmo[%obj.tool[%i].ammotype] < $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype])
{
%obj.toolAmmo[%obj.tool[%i].ammotype] += $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
%newAmmo = $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
if(%obj.toolAmmo[%obj.tool[%i].ammotype] + $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype] > $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype])
{
%newAmmo = ( %obj.toolAmmo[%obj.tool[%i].ammotype] - $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype] ) * -1;
%obj.toolAmmo[%obj.tool[%i].ammotype] = $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype];
}
else
{
%obj.toolAmmo[%obj.tool[%i].ammotype] += $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
}
%item = %obj.tool[%obj.currTool];
if( %item $= %obj.tool[%i] )
{
wstldrDisplayAmmo(%item.image, %obj, %obj.currTool);
}

//commandToClient(%obj.client, 'centerPrint', "<just:right><font:Tahoma:22><color:DBA901>+" @ %newammo SPC %obj.tool[%i].ammoType, 2);
}
else
{
if(isObject(%obj.tool[%i]) && %obj.tool[%i].altammotype $= %col.dataBlock.altammotype && %obj.toolAltMag[%obj.tool[%i].altammotype] < %obj.tool[%i].altmaxmag)
{   
%newAmmo = %col.dataBlock.altAmmoAdd;
if(%obj.toolAltMag[%obj.tool[%i].altammotype] + %col.dataBlock.altAmmoAdd > %obj.tool[%i].altmaxmag)
{
%newAmmo = (%obj.toolAltMag[%obj.tool[%i].altammotype] - %obj.tool[%i].altmaxmag) * -1;
%obj.toolAltMag[%obj.tool[%i].altammotype] = %obj.tool[%i].altmaxmag;
}
else
{
%obj.toolAltMag[%obj.tool[%i].altammotype] += %col.dataBlock.altAmmoAdd;
}
%item = %obj.tool[%obj.currTool];
if( %item $= %obj.tool[%i] )
{
wstldrDisplayAmmo(%item.image, %obj, %obj.currTool);
}
if( %newAmmo > 0 )
{
//commandToClient(%obj.client, 'centerPrint', "<just:right><font:Tahoma:22><color:DBA901>+" @ %newammo SPC %obj.tool[%i].altammotype, 2);
}
}
}
}
}
serverPlay3D(AmmoPickUpSound,%obj.getHackPosition());

//parent::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f);

if(isObject(%col.spawnBrick))
{
%col.fadeOut();
%col.schedule(%col.spawnBrick.itemRespawnTime,fadein);
}
else
{
%col.schedule(10,delete);
}
return;
}

for(%i=0; %i < %obj.dataBlock.maxTools; %i++)
{
if(isObject(%obj.tool[%i]) && %obj.toolAmmo[%obj.tool[%i].ammotype] < $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype])
{
if(%obj.tool[%i].getName() $= %col.dataBlock && %col.canPickup && %obj.getDamagePercent() < 1 && minigameCstar fishe(%obj.client,%col))
{
if(isObject(%col.spawnBrick))
{
%newAmmo = $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
if(%obj.toolAmmo[%obj.tool[%i].ammotype] + $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype] > $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype])
{
%newAmmo = ( %obj.toolAmmo[%obj.tool[%i].ammotype] - $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype] ) * -1;
%obj.toolAmmo[%obj.tool[%i].ammotype] = $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype];
}
else
{
%obj.toolAmmo[%obj.tool[%i].ammotype] += $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
}

serverPlay3D(wstldrPickUpSound,%obj.getHackPosition());
commandToClient(%obj.client, 'centerPrint', "<just:right><font:Tahoma:22><color:DBA901>+" @ %newAmmo SPC %obj.tool[%i].ammoType, 2);

%item = %obj.tool[%obj.currTool];
if( %item $= %obj.tool[%i] )
{
wstldrDisplayAmmo(%item.image, %obj, %obj.currTool);
}

%col.fadeOut();
%col.schedule(%col.spawnBrick.itemRespawnTime,fadein);
break;
}
else
{
%mag = %col.mag;
if(%mag !$= 0)
{
if(%mag $= "")
{
%mag = $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype];
}


%newAmmo = %mag;
if(%obj.toolAmmo[%obj.tool[%i].ammotype] + $wstldrWeapons::AddAmmo[%obj.tool[%i].ammotype] > $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype])
{
%newAmmo = ( %obj.toolAmmo[%obj.tool[%i].ammotype] - $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype] ) * -1;
%obj.toolAmmo[%obj.tool[%i].ammotype] = $wstldrWeapons::MaxAmmo[%obj.tool[%i].ammotype];
}
else
{
%obj.toolAmmo[%obj.tool[%i].ammotype] += %mag;
}
%col.mag = %mag - %newAmmo;
serverPlay3D(AmmoPickUpSound,%obj.getHackPosition());

if(%newAmmo > 0)
{
//commandToClient(%obj.client, 'centerPrint', "<just:right><font:Tahoma:22><color:DBA901>+" @ %newAmmo SPC %obj.tool[%i].ammoType, 2);
}
break;
respawn(%col);
}
}
%item = %obj.tool[%obj.currTool];
if( %item $= %obj.tool[%i] )
{
wstldrDisplayAmmo(%item.image, %obj, %obj.currTool);
}
}
}
}
parent::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f);
}
};
activatePackage(wstldrAmmoSystem);

aaaaaand the code for the gun:

Code: [Select]
AddDamageType("wstldrARifle",   '<bitmap:add-ons/Weapon_Gun/CI_Gun> %1',    '%2 <bitmap:add-ons/Weapon_Gun/CI_Gun> %1',0.2,1);
datablock ProjectileData(wstldrARifleProjectile)
{
projectileShapeName = "Add-Ons/Weapon_Gun/bullet.dts";
directDamage        = 30;
directDamageType    = $DamageType::wstldrARifle;
radiusDamageType    = $DamageType::wstldrARifle;

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

impactImpulse       = 450;
verticalImpulse     = 150;
explosion           = SmallExplosion;
particleEmitter     = SmallTrailEmitter;

muzzleVelocity      = 175;
velInheritFactor    = 1;

armingDelay         = 00;
lifetime            = 4000;
fadeDelay           = 4000;
bounceElasticity    = 0.0;
bounceFriction      = 0.0;
isBallistic         = true;
gravityMod = 0.3;

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

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

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

//gui stuff
uiName = "Automatic Rifle";
//iconName = "./icon_RIFLE1";
doColorShift = true;
colorShiftColor = "0.65 0.6 0.55 1.000";

maxmag = 18;
ammotype = "rifle";
reload = true;

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

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(wstldrARifleImage)
{
// Basic Item properties
shapeFile = "./automatic_rifle.1.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 = wstldrARifleItem;
ammo = " ";
projectile = wstldrARifleProjectile;
projectileType = Projectile;

casing = GunShellDebris;
shellExitDir        = "0.5 -1.3 0.5";
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 = wstldrARifleItem.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]      = "AmmoCheck";
stateSound[0]                    = "DrawSound";

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

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

stateName[3]                     = "AmmoCheck";
stateTransitionOnTimeout[3]      = "Ready";
stateAllowImageChange[3]         = true;
stateScript[3]                   = "onAmmoCheck";

stateName[4]                     = "Reload";
stateTransitionOnTimeout[4]      = "ReloadReady";
stateTimeoutValue[4]             = 1.75;
stateAllowImageChange[4]         = true;
stateScript[4]                   = "onReloadStart";

stateName[5]                    = "ReloadReady";
stateTransitionOnTimeout[5]      = "CheckChamber";
stateTimeoutValue[5]             = 0.25;
stateAllowImageChange[5]         = true;
stateScript[5]                   = "onReload";

stateName[6]                     = "Empty";
stateTransitionOnTriggerDown[6]  = "EmptyFire";
stateAllowImageChange[6]         = true;
stateScript[6]                   = "onEmpty";
stateTransitionOnAmmo[6]         = "Reload";

stateName[7]                     = "EmptyFire";
stateTransitionOnTriggerUp[7]    = "Empty";
stateTimeoutValue[7]             = 0.15;
stateAllowImageChange[7]         = false;
stateWaitForTimeout[7]           = true;
stateSound[7]                    = EmptySound;

stateName[8]                     = "CheckChamber";
stateTransitionOnTimeOut[8]      = "Ready";
stateTransitionOnNoAmmo[8]       = "roostering";
stateAllowImageChange[8]         = true;
 
stateName[9]                     = "roostering";
stateTransitionOnTimeOut[9]      = "Ready";
stateTimeoutValue[9]             = 0.25;
stateAllowImageChange[9]         = true;
stateWaitForTimeout[9]           = true;
stateScript[9]                   = "onrooster";

stateName[10] = "Smoke";
stateTransitionOnTimeout[10]     = "AmmoCheck";
stateTimeoutValue[10]            = 0.05;
stateEmitter[10] = gunSmokeEmitter;
stateEmitterTime[10] = 0.75;
stateEmitterNode[10] = "muzzleNode";
};

function wstldrARifleImage::onReloadStart( %this, %obj, %slot )
{
%obj.playThread(2, plant);
%obj.schedule(100, playThread, 2, shiftright);
%obj.schedule(250, playThread, 2, shiftaway);
serverPlay3D(Block_MoveBrick_Sound,%obj.getPosition());
wstldrDisplayAmmo(%this,%obj,%slot);
}

function wstldrARifleImage::onAmmoCheck( %this, %obj, %slot )
{
wstldrAmmoCheck(%this,%obj,%slot);
wstldrDisplayAmmo(%this,%obj,%slot);
}

function wstldrARifleImage::onReload( %this, %obj, %slot )
{
%obj.playThread(2, plant);
serverPlay3D(RifleReload2Sound,%obj.getPosition());
wstldrAmmoOnReload(%this,%obj,%slot);
wstldrDisplayAmmo(%this,%obj,%slot);
}

function wstldrARifleImage::onrooster( %this, %obj, %slot )
{
%obj.schedule(80, playThread, 2, shiftleft);
%obj.schedule(160, playThread, 2, plant);
serverPlay3D(RifleReload1Sound,%obj.getPosition());
%obj.setImageAmmo(0,1);
wstldrDisplayAmmo(%this,%obj,%slot);
}

function wstldrARifleImage::onMount( %this, %obj, %slot )
{
parent::onMount(%this,%obj,%slot);
wstldrDisplayAmmo(%this,%obj,%slot,0);
}
function wstldrARifleImage::onUnMount( %this, %obj, %slot )
{
parent::onUnMount(%this,%obj,%slot);
wstldrDisplayAmmo(%this,%obj,%slot,-1);
}

function wstldrARifleImage::onEmpty(%this,%obj,%slot)
{
if( $wstldrWeapons::Ammo && %obj.toolAmmo[%this.item.ammotype] < 1 )
{
return;
}

if(%obj.toolMag[%obj.currTool] < 1)
{
serverCmdLight(%obj.client);
}
}

function wstldrARifleImage::onFire( %this, %obj, %slot )
{
if(%obj.getDamagePercent() > 1.0)
{
return;
}

if($wstldrWeapons::ammoSystem)
{
%obj.toolMag[%obj.currTool] -= 1;

if(%obj.toolMag[%obj.currTool] < 1)
{
%obj.toolMag[%obj.currTool] = 0;
%obj.setImageAmmo(0,0);
}
wstldrDisplayAmmo(%this,%obj,%slot);
}

if(getSimTime() - %obj.lastShotTime > 300)
{
%projectile = wstldrARifleProjectile;
%spread = 0.0005;
%shellcount = 1;
%obj.playThread(2, plant);
}
else
{
%projectile = wstldrARifleProjectile;
%spread = 0.001;
%shellcount = 1;
%obj.playThread(2, plant);
}

%obj.lastShotTime = getSimTime();
Parent::onFire(%this,%obj,%slot);
 
serverPlay3D(RifleShot2Sound,%obj.getPosition());

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

Code: [Select]
function wstldrAmmoOnReload(%this,%obj,%slot)
{
if(!$wstldrWeapons::ammoSystem)
{
return;
}
if($wstldrWeapons::Ammo)
{
if(%this.item.nochamber)
{
%a = %this.item.maxmag - %obj.toolMag[%obj.currTool];
if(%a > %obj.toolAmmo[%this.item.ammotype])
%a = %obj.toolAmmo[%this.item.ammotype];
%obj.toolMag[%obj.currTool] += %a;
%obj.toolAmmo[%this.item.ammotype] -= %a;
%obj.setImageAmmo(0,1);
}
else
{
if(%obj.toolMag[%obj.currTool] > 0)
{
%a = (%this.item.maxmag) - %obj.toolMag[%obj.currTool];
if(%a > %obj.toolAmmo[%this.item.ammotype])
%a = %obj.toolAmmo[%this.item.ammotype];
%obj.toolMag[%obj.currTool] += %a;
%obj.toolAmmo[%this.item.ammotype] -= %a;
%obj.setImageAmmo(0,1);
}
else
{
%a = %this.item.maxmag - %obj.toolMag[%obj.currTool];
if(%a > %obj.toolAmmo[%this.item.ammotype])
%a = %obj.toolAmmo[%this.item.ammotype];
%obj.toolMag[%obj.currTool] += %a;
%obj.toolAmmo[%this.item.ammotype] -= %a;
%obj.setImageAmmo(0,0);
}
}
}
else
{
if(%this.item.nochamber)
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
%obj.setImageAmmo(0,1);
}
else
{
if(%obj.toolMag[%obj.currTool] > 0)
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
%obj.setImageAmmo(0,1);
}
else
{
%obj.toolMag[%obj.currTool] = %this.item.maxmag;
%obj.setImageAmmo(0,0);
}
}
}
}
Lots of codes. Well by looking at the reload function that is called it looks like after the if(%this.item.nochamber) there's no check to make sure that the weapon has another mag/enough ammo to reload. I say try adding another if statement to this.

a second IF statement with the same lines?

im not a scripter :c can u explain to me how it should be?

a second IF statement with the same lines?

im not a scripter :c can u explain to me how it should be?
If you can't script then why are you posting here? It should be in suggestions and requests because you're asking someone else to do it for you and you have no idea what you're doing.

you know, you could like help me instead

idk just a suggestion man

you know, you could like help me instead

idk just a suggestion man
it's pretty much

if(%mag == "0")
    return;


thats pretty much it, (Don't use it, it's psuedocode and will not work)

This is coding help. If you want someone else to make it for you, go to S&R

This is coding help. If you want someone else to make it for you, go to S&R
in that case, you might want to go stuff on every single other topic in coding help because they all ask for, guess what, help from other people.
« Last Edit: September 30, 2014, 06:07:04 AM by ZombieDude »

Well, i guess it's a thing of taste for code helpers. How much of doings someone's work is doing it for them. I'm all for people helping people and if someone wants to help, they are more than welcome to. I guess i was too abrupt with my post.