#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <zombieplague>

#define m_LastHitGroup		75
#define OFFSET_LINUX		5
#define AMMO_FOR_KILL	10 //Сколько давать аммо за убийство зомби в хед-шот.

new cvar_spawndelay
new g_hamczbots, cvar_botquota

public plugin_init() 
{
	register_plugin("Kill Head Ammo", "1.0", "LARS-BLOODLIKER, magneTo")  
	RegisterHam(Ham_Killed, "player", "fw_PlayerKilled") 
	cvar_spawndelay = register_cvar("zp_spawn_delay", "3.0") //Через сколько секунд возрождать зомби, если его не убили в хед-шот.
	cvar_botquota = get_cvar_pointer("bot_quota")
}

public fw_PlayerKilled(victim, attacker, shouldgib)
{
	if(!is_user_connected(attacker) || !is_user_connected(victim) || attacker == victim)
		return HAM_IGNORED
	
    	if(!zp_get_user_zombie(attacker) || zp_get_user_zombie(victim))
	{
		if(get_pdata_int(victim, m_LastHitGroup, OFFSET_LINUX) == HIT_HEAD) 
        	{
			zp_set_user_ammo_packs(attacker, zp_get_user_ammo_packs(attacker) + AMMO_FOR_KILL)
			client_print(attacker, print_center, "You killed the zombie in the head, the more he will not be disturbed")
		}
		else if(get_pdata_int(victim, m_LastHitGroup, OFFSET_LINUX) != HIT_HEAD) 
		{
 			set_task(get_pcvar_float(cvar_spawndelay), "PlayerRespawn", victim)
			client_print(attacker, print_center, "You killed a zombie, but he still return from the dead to take revenge")
		}
	}	
	return PLUGIN_HANDLED
} 

public PlayerRespawn(id)
{
	zp_respawn_user(id, ZP_TEAM_ZOMBIE)
}

public register_ham_czbots(Player)
{
	if(g_hamczbots || !is_user_connected(Player) || !get_pcvar_num(cvar_botquota)) return
	
	RegisterHamFromEntity(Ham_Killed, Player, "fw_PlayerKilled")

	g_hamczbots = true
}

public client_putinserver(Player)
{
	if(is_user_bot(Player) && !g_hamczbots && cvar_botquota) set_task(0.1, "register_ham_czbots", Player)
}