14
« on: November 13, 2007, 07:07:04 PM »
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.");
}