Code:
public clcmd_buyammo(id)
{
// Not alive or infinite ammo setting enabled
if (get_pcvar_num(cvar_infammo) || !is_user_alive(id))
return PLUGIN_HANDLED;
// Not human
if (g_zombie[id])
{
client_print(id, print_chat, "[ZP] %L", id, "CMD_HUMAN_ONLY")
return PLUGIN_HANDLED;
}
if (g_survivor[id])
{
client_print(id, print_chat, "[ZP] %L", id, "CMD_HUMAN_ONLY")
return PLUGIN_HANDLED;
}
// Not enough ammo packs
if (g_ammopacks[id] < 1)
{
client_print(id, print_chat, "[ZP] %L", id, "NOT_ENOUGH_AMMO")
return PLUGIN_HANDLED;
}
// Get user weapons
static weapons[32], num, i, currentammo, weaponid
num = 0 // reset passed weapons count (bugfix)
get_user_weapons(id, weapons, num)
// Loop through them and give the right ammo type
for (i = 0; i < num; i++)
{
// Prevents re-indexing the array
weaponid = weapons[i]
if ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM) // primary
{
// Get current ammo of the weapon
currentammo = fm_get_user_bpammo(id, weaponid)
// Check if we are close to the BP ammo limit
if (currentammo <= MAXBPAMMO[weaponid]-BUYAMMO[weaponid])
{
// Flash ammo in hud
message_begin(MSG_ONE_UNRELIABLE, g_msgAmmoPickup, _, id)
write_byte(AMMOID[weaponid]) // ammo id
write_byte(BUYAMMO[weaponid]) // ammo amount
message_end()
// Increase BP ammo
fm_set_user_bpammo(id, weaponid, currentammo + BUYAMMO[weaponid])
// Deduce ammo packs, play clip purchase sound, and notify the player
g_ammopacks[id]--
engfunc(EngFunc_EmitSound, id, CHAN_ITEM, sound_buyammo, 1.0, ATTN_NORM, 0, PITCH_NORM)
client_print(id, print_chat, "[ZP] %L", id, "AMMO_BOUGHT")
}
else
{
// Flash ammo in hud
message_begin(MSG_ONE_UNRELIABLE, g_msgAmmoPickup, _, id)
write_byte(AMMOID[weaponid]) // ammo id
write_byte(MAXBPAMMO[weaponid]-currentammo) // ammo amount
message_end()
// Reached the limit
fm_set_user_bpammo(id, weaponid, MAXBPAMMO[weaponid])
}
}
else if ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM) // secondary
{
// Get current ammo of the weapon
currentammo = fm_get_user_bpammo(id, weaponid)
// Check if we are close to the BP ammo limit
if (currentammo <= MAXBPAMMO[weaponid]-BUYAMMO[weaponid])
{
// Flash ammo in hud
message_begin(MSG_ONE_UNRELIABLE, g_msgAmmoPickup, _, id)
write_byte(AMMOID[weaponid]) // ammo id
write_byte(BUYAMMO[weaponid]) // ammo amount
message_end()
// Increase BP ammo
fm_set_user_bpammo(id, weaponid, currentammo + BUYAMMO[weaponid])
// Deduce ammo packs, play clip purchase sound, and notify the player
g_ammopacks[id]--
engfunc(EngFunc_EmitSound, id, CHAN_ITEM, sound_buyammo, 1.0, ATTN_NORM, 0, PITCH_NORM)
client_print(id, print_chat, "[ZP] %L", id, "AMMO_BOUGHT")
}
else
{
// Flash ammo in hud
message_begin(MSG_ONE_UNRELIABLE, g_msgAmmoPickup, _, id)
write_byte(AMMOID[weaponid]) // ammo id
write_byte(MAXBPAMMO[weaponid]-currentammo) // ammo amount
message_end()
// Reached the limit
fm_set_user_bpammo(id, weaponid, MAXBPAMMO[weaponid])
}
}
}
return PLUGIN_HANDLED;
}