Author Topic: Support_AmmoReserve - Ammo System  (Read 2944 times)

Basically I am doing what Rotondo did for his Ammo in his Zombie mod, but in what would probably be a little cleaner and flexible way.
Basically it would work like this:

We choose the weapon to use this ammunition script and give it the following variables:

MaxAmmo = # [Maximum ammo capacity. Overflowing this much ammo by picking up ammo results in resetting total ammo to this value. If this variable does not exist this weapon does not use this ammo system.]
SpawnAmmo = # [How much ammo one begins with this weapon. If this does not exist or is set to 0, one spawns with no ammo for this weapon.]
DropAmmo = # [This determines how much ammunition is given to each item in the inventory if picked up after being dropped. This number represents the percent of each item's MaxAmmo that is refilled to each item. If this number is zero or is not implemented, it does not act like ammunition upon being picked up. This action of picking-up-and-getting-ammunition should probably be disable-able via RTB preferences.]

Subtracting ammo that would probably be the variable %this.curammo or something would have to be mandatory and added to the OnFire script for flexibility purposes. (as to say you wanted to subtract ammo or add ammo in different states)
And one should probably add a statement that if that variable is at zero, it does not execute the parent of onfire or does not fire the projectiles stated in the onfire function.

Now my only problem is that the names collide with Space Guy's ammo mod that causes weapons to reload. What do you think I should call these ammo variables instead?
Also, I would appreciate it if people told me if they had a better idea for the layout of this script and I would not appreciate it if people called me a stupid douche-bag of a handicap.

inb4everyonecallingmeastupiddouche-bagofahandicapandmeregrettinggivingthemthatidea


I believe it actually works now.
Code: [Select]
package AmmoReserve
{
function ItemData::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
{
if(%obj.weaponReserveLoaded >= 1 && (%col.getType() & $TypeMasks::PlayerObjectType))
{
echo("ONCOLLISION");
%col.pickup(%obj);
}
else
Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
}
function ItemData::onPickup(%this,%obj,%user,%amt)
{
echo("hi");
%data = %obj.dataBlock;
%dropReserve = %obj.weaponReserveLoaded;
%p = %dropReserve / 100;
%addslot0 = %user.maxReserve[0] * %p;
%addslot1 = %user.maxReserve[1] * %p;
%addslot2 = %user.maxReserve[2] * %p;
%addslot3 = %user.maxReserve[3] * %p;
%addslot4 = %user.maxReserve[4] * %p;
if(%dropReserve >= 1)
{
//if(%user.tool[0].getID() !$= "" && %user.toolReserve[%user.tool[0]] !$= "")
//if(%user.getID[%user.tool[0]] !$= "" && %user.toolReserve[%user.tool[0]] !$= "")
if(%user.toolReserve[0] !$= "")
%user.toolReserve[0] += %addslot0;

if(%user.toolReserve[1] !$= "")
%user.toolReserve[1] += %addslot1;

if(%user.toolReserve[2] !$= "")
%user.toolReserve[2] += %addslot2;

if(%user.toolReserve[3] !$= "")
%user.toolReserve[3] += %addslot3;

if(%user.toolReserve[4] !$= "")
%user.toolReserve[4] += %addslot4;

echo("err");
%user.playAudio(0,ErrorSound);
%obj.delete();
schedule(10,0,ResetReserve,%user);
schedule(10,0,DisplayAmmo,%user);
return;
}
else
Parent::OnPickup(%this,%obj,%user,%amt);
}
function ItemData::onAdd(%this,%obj)
{
if($weaponReserveLoaded !$= "")
{
%obj.weaponReserveLoaded = $weaponReserveLoaded;
$weaponReserveLoaded = "";
echo("lol");
}
Parent::onAdd(%this,%obj);
}
function WeaponImage::onMount(%this, %obj, %slot)
{
if(%obj.currTool == -1 || %obj.toolReserve[%obj.currTool] $= "")
{
%obj.maxReserve[%obj.currTool] = %this.item.maxReserve;
%obj.dropReserve[%obj.currTool] = %this.item.dropReserve;
%obj.toolReserve[%obj.currTool] = %this.item.spawnReserve;
echo("onmount");
}
Parent::onMount(%this, %obj, %slot);
}
function servercmdDropTool(%client,%slot)
{
if(!isObject(%client.player))
return Parent::servercmdDropTool(%client,%slot);

//if(!isObject(%client.player.tool[%slot]) || %client.player.tool[%slot].maxReserve <= 0)
// return Parent::servercmdDropTool(%client,%slot);

//$weaponAmmoLoaded = %client.player.dropReserve[%client.player.currTool];
//if(%client.player.tool[%slot].dropReserve >= 0)
//if(%client.player.maxReserve[%client.player.currTool] == 800)
//$WeaponReserveLoaded = 1;
if(%client.player.dropReserve[%client.player.currTool] !$= "")
$WeaponReserveLoaded = %client.player.dropReserve[%client.player.currTool];

%client.player.maxReserve[%client.player.currTool] = "";
%client.player.dropReserve[%client.player.currTool] = "";
%client.player.toolReserve[%client.player.currTool] = "";
return Parent::servercmdDropTool(%client,%slot);
}
function ResetReserve(%this)
{
if(%this.toolReserve[0] > %this.maxReserve[0])
%this.toolReserve[0] = %this.MaxReserve[0];

if(%this.toolReserve[1] > %this.maxReserve[1])
%this.toolReserve[1] = %this.MaxReserve[1];

if(%this.toolReserve[2] > %this.maxReserve[2])
%this.toolReserve[2] = %this.MaxReserve[2];

if(%this.toolReserve[3] > %this.maxReserve[3])
%this.toolReserve[3] = %this.MaxReserve[3];

if(%this.toolReserve[4] > %this.maxReserve[4])
%this.toolReserve[4] = %this.MaxReserve[4];

if(%this.toolReserve[0] < 0)
%this.toolReserve[0] = 0;

if(%this.toolReserve[1] < 0)
%this.toolReserve[1] = 0;

if(%this.toolReserve[2] < 0)
%this.toolReserve[2] = 0;

if(%this.toolReserve[3] < 0)
%this.toolReserve[3] = 0;

if(%this.toolReserve[4] < 0)
%this.toolReserve[4] = 0;
}
function DisplayAmmo(%this)
{
%this.client.bottomprint("<just:right><color:FFFF00>Ammo <color:FFFFFF>:<color:FF0000>" SPC %this.toolReserve[%this.currTool], 3);
}
};activatePackage(AmmoReserve);
« Last Edit: September 03, 2010, 04:00:05 PM by The Titanium »

Spoke with Jurttu, he thinks 'Ammunition' is best.
I think since no-one really cares about this topic, I'll use this post to try and keep track of my pathetic attempts at scripting. But not now.

MaxReserve = # [Maximum ammunition capacity. Overflowing this much ammunition by picking up ammunition results in resetting total ammunition to this value. If this variable does not exist this weapon does not use this ammunition system.]
SpawnReserve = # [How much ammunition one begins with this weapon. If this does not exist or is set to 0, one spawns with no ammunition for this weapon.]
DropReserve = # [This determines how much ammunition is given to each item in the inventory if picked up after being dropped. This number represents the percent of each item's Maxammunition that is refilled to each item. If this number is zero or is not implemented, it does not act like ammunition upon being picked up. This action of picking-up-and-getting-ammunition should probably be disable-able via RTB preferences.]
« Last Edit: September 01, 2010, 04:39:16 PM by The Titanium »

inb4everyonecallingmeastupiddouche-bagofahandicapandmeregrettinggivingthemthatidea
lol

"Reserve" ammo for example "maxReserve"?

Wow, that's actually a perfect name.
Now lets see my stupid script kiddy skills:
Code: [Select]
package ReserveAmmo
{
function ItemData::onCollision(%data,%obj,%col)
{
%type = %col.getType();
%p = %obj.WeaponDropReserve / 100;
%addslot1 = %col.MaxReserve[tool[0]] * %p;
%addslot2 = %col.MaxReserve[tool[1]] * %p;
%addslot3 = %col.MaxReserve[tool[2]] * %p;
%addslot4 = %col.MaxReserve[tool[3]] * %p;
%addslot5 = %col.MaxReserve[tool[4]] * %p;
if(%obj.WeaponDropReserve >= 1 && (%type & $TypeMasks::PlayerObjectType))
{
          %col.toolReserve[%col.tool[0]] + %addslot1;
          %col.toolReserve[%col.tool[1]] + %addslot2;
          %col.toolReserve[%col.tool[2]] + %addslot3;
          %col.toolReserve[%col.tool[3]] + %addslot4;
          %col.toolReserve[%col.tool[4]] + %addslot5;
%obj.delete();
}
else
Parent::onCollision(%data,%obj,%col);
}
function ItemData::onAdd(%this,%obj)
{
if($WeaponDropReserve !$= "")
{
%obj.WeaponDropReserve = $WeaponDropReserve;
$WeaponDropReserve = "";
}
Parent::onAdd(%this,%obj);
}
function WeaponImage::onMount(%this,%obj,%slot)
{
if(this.MaxReserve >= 1 && this.SpawnReserve >= 1 && (%obj.currTool == -1 || %obj.toolReserve[%obj.currTool] $= ""))
{
%obj.toolReserve[%obj.currTool] = %this.SpawnReserve;
}
}
function servercmdDropTool(%client,%slot)
{
if(!isObject(%client.player))
return Parent::servercmdDropTool(%client,%slot);

if(!isObject(%client.player.tool[%slot]) || %client.player.getMountedImage(0).MaxReserve <= 0)
return Parent::servercmdDropTool(%client,%slot);

if(%client.player.getMountedImage(0).DropReserve >= 1)
$WeaponDropReserve = %client.player.getMountedImage(0).DropReserve;

%client.player.toolReserve[%client.player.currTool] = "";
return Parent::servercmdDropTool(%client,%slot);
}
};activatePackage(ReserveAmmo);
I did just completely rip off of Space Guy.
I can definitely tell I am doing it wrong.
« Last Edit: September 01, 2010, 05:05:59 PM by The Titanium »

Instead of the item giving a percent of max ammo when picked up, make it give what ever ammo is left?



From my perspective, do whatever you want, since I have little/no idea what you are going on about with all the script.

Just make it give machine guns ammo...Rotondo's fails in that area.


From my perspective, do whatever you want, since I have little/no idea what you are going on about with all the script.

Just make it give machine guns ammo...Rotondo's fails in that area.
His fails on many guns.

I think it's because some guns (For example: Ephi's Shotgun) have a spread script and when firing, they do not use the default "click and just one projectile comes straight out of the barrel."

If he's planning to use it with my ammo clip mod then that doesn't actually affect anything by default - since you had to code special parts into the weapon image it'll just ignore any weapons except the ones you set max ammo etc. on so you are able to also adjust the firing function to decrement the ammo remaining.

and if i do that its probably a little less prone to problems, no?

dear god what am i doing
Code: [Select]
package ReserveAmmo
{
//function ItemData::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
//{
// if(%obj.weaponReserveLoaded == 1 && (%col.getType() & $TypeMasks::PlayerObjectType))
// {
// echo("ONCOLLISION");
// %col.pickup(%obj);
// }
// else
// Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
//}
function Player::pickup(%this,%item)
{
echo("hi");
%p = %item.dropReserve / 100;
%addslot1 = %this.maxReserve[%this.tool[0]] * %p;
%addslot2 = %this.maxReserve[%this.tool[1]] * %p;
%addslot3 = %this.maxReserve[%this.tool[2]] * %p;
%addslot4 = %this.maxReserve[%this.tool[3]] * %p;
%addslot5 = %this.maxReserve[%this.tool[4]] * %p;
%data = %item.dataBlock;
%ammo = %item.weaponReserveLoaded;
%val = Parent::pickup(%this,%item);
//if(%data.dropReserve > 0 && isObject(%this.client) && %item.weaponReserveLoaded == 1)// && %val == 1)
if(%item.weaponReserveLoaded == 1)
{
if(%this.tool[0].getID() !$= "" && %this.toolReserve[%this.tool[0]] !$= "")
%this.toolReserve[0] += %addslot1;

if(%this.tool[1].getID() !$= "" && %this.toolReserve[%this.tool[1]] !$= "")
%this.toolReserve[1] += %addslot2;

if(%this.tool[2].getID() !$= "" && %this.toolReserve[%this.tool[2]] !$= "")
%this.toolReserve[2] += %addslot3;

if(%this.tool[3].getID() !$= "" && %this.toolReserve[%this.tool[3]] !$= "")
%this.toolReserve[3] += %addslot4;

if(%this.tool[4].getID() !$= "" && %this.toolReserve[%this.tool[4]] !$= "")
%this.toolReserve[4] += %addslot5;

echo("err");
}
return %val;
}
function ItemData::onAdd(%this,%obj)
{
if($weaponReserveLoaded !$= "")
{
%obj.weaponReserveLoaded = $weaponReserveLoaded;
$weaponReserveLoaded = "";
echo("lol");
}
Parent::onAdd(%this,%obj);
}
function WeaponImage::onMount(%this, %obj, %slot)
{
if(%obj.currTool == -1 || %obj.toolReserve[%obj.currTool] $= "")
{
%obj.maxReserve[%obj.currTool] = %this.item.maxReserve;
%obj.dropReserve[%obj.currTool] = %this.item.dropReserve;
%obj.toolReserve[%obj.currTool] = %this.item.spawnReserve;
echo("onmount");
}
Parent::onMount(%this, %obj, %slot);
}
function servercmdDropTool(%client,%slot)
{
if(!isObject(%client.player))
return Parent::servercmdDropTool(%client,%slot);

//if(!isObject(%client.player.tool[%slot]) || %client.player.tool[%slot].maxReserve <= 0)
// return Parent::servercmdDropTool(%client,%slot);

//$weaponAmmoLoaded = %client.player.dropReserve[%client.player.currTool];
//if(%client.player.tool[%slot].dropReserve >= 0)
//if(%client.player.maxReserve[%client.player.currTool] == 800)
$WeaponReserveLoaded = 1;

%client.player.maxReserve[%client.player.currTool] = "";
%client.player.dropReserve[%client.player.currTool] = "";
%client.player.toolReserve[%client.player.currTool] = "";
return Parent::servercmdDropTool(%client,%slot);
}
};activatePackage(ReserveAmmo);
sdfdsadfd player::pickup cant recognize that the item has WeaponReserveLoaded at 1 :c
HEAVY: HELP NAO :C
« Last Edit: September 02, 2010, 07:41:06 PM by The Titanium »

Once you pick up a dropped item it's deleted. That is why the "%ammo = %item.weaponReserveLoaded;" part is there.