I have been wanting to do this one for a long time, but the proper plan sort of eludes me. Lets say theres a backpack from a fragged player that has (40) shells , (64) nails and (100) cells. The player touches it, and he already has (90) shells (40) nails and (0) Cells.
The ID code merely gives the player (100) shells, (100) nails and (100) cells, and the backpack disappears. I want the player to get the same ammo, but leave the backpack there containing what he cannot carry: (30) shells, (4) nails. Heres the touch function Im using, which I think is pretty much standard. Any help with some good code, or if anyone knows existing code to do this, thanks.
void () BackpackTouch =
{
local string s;
local float best;
local float old;
local float new;
local float bbest;
local entity stemp;
local float acount;
if (((other.classname != "player") && (other.classname != "bot")))
{
return;
}
if ((other.health <= 0))
{
return;
}
if (((other == self.owner) && ((self.nextthink - time) > 118)))
{
return;
}
acount = 0;
if ((cvar ("temp1") < 65535))
{
if ((other.classname == "player"))
{
sprint (other, "You get ");
}
}
stemp = self;
self = other;
best = W_BestWeapon ();
if (self.classname == "bot")
{
if (stemp.altname == "tossedpack")
fBotSayTeam (": Thanks.\n");
else if ((stemp.ammo_shells + stemp.ammo_nails) > 175 || (stemp.ammo_rockets + stemp.ammo_cells) > 100)
{
bprint (self.talkname);
bprint ("º ");
BotSayMiddle ("Nice Pack ");
if (stemp.owner.team != self.team)
BotSayMiddle (stemp.owner.netname);
BotSayEnd ();
}
}
self = stemp;
other.ammo_shells = (other.ammo_shells + self.ammo_shells);
other.ammo_nails = (other.ammo_nails + self.ammo_nails);
other.ammo_rockets = (other.ammo_rockets + self.ammo_rockets);
other.ammo_cells = (other.ammo_cells + self.ammo_cells);
new = self.items;
if (!new)
new = other.weapon;
old = other.items;
other.items = (other.items | new);
bound_other_ammo ();
if ((other.classname == "player"))
{
if ((cvar ("temp1") < 65535))
{
if (self.ammo_shells)
{
if (acount)
{
sprint (other, ", ");
}
acount = WEAPON_SHOTGUN;
s = ftos (self.ammo_shells);
sprint (other, s);
sprint (other, " shells");
}
if (self.ammo_nails)
{
if (acount)
{
sprint (other, ", ");
}
acount = WEAPON_SHOTGUN;
s = ftos (self.ammo_nails);
sprint (other, s);
sprint (other, " nails");
}
if (self.ammo_rockets)
{
if (acount)
{
sprint (other, ", ");
}
acount = WEAPON_SHOTGUN;
s = ftos (self.ammo_rockets);
sprint (other, s);
sprint (other, " rockets");
}
if (self.ammo_cells)
{
if (acount)
{
sprint (other, ", ");
}
acount = WEAPON_SHOTGUN;
s = ftos (self.ammo_cells);
sprint (other, s);
sprint (other, " cells");
}
sprint (other, "\n");
stuffcmd (other, "bf\n");
}
}
if (((deathmatch & DM_START_SMALL) || (deathmatch & DM_START_BIG)))
{
other.health = (other.health + 5);
}
sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, SUB_Db());
remove (self);
self = other;
if ((other.classname == "player"))
{
if ((WeaponCode (new) <= other.best_wep))
{
if ((self.flags & FL_INWATER))
{
if ((new != IT_LIGHTNING))
{
Deathmatch_Weapon (old, new);
}
}
else
{
Deathmatch_Weapon (old, new);
}
}
}
else
{
Deathmatch_Weapon (old, new);
}
W_SetCurrentAmmo ();
};