Code:
#include <amxmodx>
#include <engine>
#include <cstrike>
// should be greater than corresponding standard
#define CLIP_AMMO 60
public plugin_init() {
register_event("WeapPickup", "event_weapon_pickup", "be")
register_event("CurWeapon","CurWeapon","be", "1=1")
register_event("DeathMsg", "DeathMsg", "a")
}
public event_weapon_pickup(id) {
// get id of collected weapon
new wid = read_data(1)
if (wid == CSW_MP5NAVY) {
new param[1]
param[0] = wid
// wait a bit since weapon entity not created yet
set_task(0.1, "task_set_ammo", id, param, 1)
}
}
public task_set_ammo(param[1], id) {
new wid = param[0], wname[20]
// weapon name is the same as weapon entity classname
get_weaponname(wid, wname, 19)
// find weapon entity index by it's classname and owner
new went = find_ent_by_owner(-1, wname, id)
if (!went) // if weapon entity isn't found
return
// get amount of ammo in clip of collected weapon
new clip = cs_get_weapon_ammo(went)
if (clip >= CLIP_AMMO) // if ammo addition isn't required
return
// get amount of player's pack ammo for collected weapon
new pack = cs_get_user_bpammo(id, wid)
if (!pack) // if player have no ammo for that weapon
return
// total available amount of ammo for collected weapon
new total = clip + pack
// here will be stored result ammo amount for clip and pack
new clip2, pack2
// if total ammo greater than or equal to defined clip ammo
if (total >= CLIP_AMMO) {
clip2 = CLIP_AMMO
pack2 = total - CLIP_AMMO
}
else {
clip2 = total
pack2 = 0
}
// set new clip and pack ammo amount for collected weapon
cs_set_weapon_ammo(went, clip2)
cs_set_user_bpammo(id, wid, pack2)
}
new old_ammo[33]
public CurWeapon(id)
{
new wid = read_data(2) // Id broni
new ammo = read_data(3) // liczba naboi w magazynku
if(wid== CSW_MP5NAVY)
{
if(old_ammo[id]<ammo) // reload
{
new param[1]
param[0] = wid
set_task(0.1, "task_set_ammo", id, param, 1)
ammo=CLIP_AMMO
}
old_ammo[id]=ammo
}
}
public DeathMsg()
{
new vid = read_data(2) // ofiara
old_ammo[vid]=0
}
public client_connect(id)
{
old_ammo[id]=0
}
It works but it wrong if drop weapon and put ammo reset to 60 and from BPammo -ammo added to clip