public plugin_init()
{
RegisterHookChain(RG_CBasePlayer_Spawn, "user_spawn", 1);
}
public user_spawn(const this)
{
if(is_user_alive(this))
{
if(!task_exists(task_id[this]))
{
task_id[this] = set_task(0.1, "timer_handler", this, _, _, "b", false);
}
}
}
public timer_handler(id)
{
if(is_user_alive(id))
{
if(ad[id][upgrade][UPGRADE_AMMUNITION_REGENERATION])
{
ad[id][miliseconds_ammunition_regeneration]--;
if(ad[id][miliseconds_ammunition_regeneration] <= 0)
{
ad[id][miliseconds_ammunition_regeneration] = 30;
new weapon_ammo, weapon_id = get_user_weapon(id, _, weapon_ammo);
if(weapon_id < 33 && weapon_id != CSW_HEGRENADE && CSW_FLASHBANG && CSW_SMOKEGRENADE && CSW_C4)
{
if(weapon_ammo < max_weapons_ammo[weapon_id] && weapon_ammo + ad[id][upgrade][UPGRADE_AMMUNITION_REGENERATION] < max_weapons_ammo[weapon_id])
{
cs_set_user_bpammo(id, weapon_id, weapon_ammo + ad[id][upgrade][UPGRADE_AMMUNITION_REGENERATION]);
}
else
{
cs_set_user_bpammo(id, weapon_id, max_weapons_ammo[weapon_id]);
}
}
}
}
}
else if(task_exists(task_id[id]))
{
remove_task(task_id[id]);
task_id[id] = 0;
}
}