#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <zombieplague>

new const g_item_name[] = { "RedBull" }

new const PLUGIN[]  = "[ZP] RedBull";
new const VERSION[] = "1.0";
new const AUTHOR[]  = "x";
new const zp_redbull_speed[]  = "zp_rb_speed";

new g_redbull_cost, g_redbull, g_redbull_time
new bool:RedBull[33];


public plugin_init()
{
	register_plugin(PLUGIN , VERSION , AUTHOR);
	register_cvar(zp_redbull_speed, "270");
        g_redbull_time = register_cvar("zp_redbull_time", "8")
        g_redbull_cost = register_cvar("zp_redbull_cost", "8")
        g_redbull = zp_register_extra_item(g_item_name, get_pcvar_num(g_redbull_cost), ZP_TEAM_HUMAN)
        register_clcmd("say /redbull", "buy_RedBull")
        register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
}

public client_PreThink(id) 
{
	if(!is_user_alive(id) || zp_get_user_zombie(id) || zp_get_user_survivor(id) || !RedBull[id] ) return PLUGIN_CONTINUE
	
	new Float:fAim[3] , Float:fVelocity[3];
	VelocityByAim(id , get_cvar_num(zp_redbull_speed) , fAim);
 
	if(!(get_user_button(id) & IN_JUMP))
	{
		fVelocity[0] = fAim[0];
		fVelocity[1] = fAim[1];
		fVelocity[2] = fAim[2];

		set_user_velocity(id , fVelocity);
	}
	return PLUGIN_CONTINUE;
}

public zp_extra_item_selected(player, itemid)
{		
	if (itemid == g_redbull)
	{
                set_task(get_pcvar_float(g_redbull_time), "Redbull_over", player)
		client_print(player, print_chat, "[ZP-RedBull] Вы купили RedBull! Приятного полёта..." )
		RedBull[player] = true
	}	
}

public buy_RedBull(id)
{
        if( !is_user_alive(id) || zp_get_user_zombie(id) )
        {
        client_print(id, print_chat, "[ZP-RedBull] Зомби не могут купить RedBull" )
        return PLUGIN_HANDLED
	}

	new iMoney = zp_get_user_ammo_packs(id)
	new iCost = get_pcvar_num(g_redbull_cost)
	if(iMoney >= iCost)
	{
	zp_set_user_ammo_packs(id, iMoney - iCost)	
        client_print(id, print_chat, "[ZP-RedBull] Вы купили RedBull!")
        set_task(get_pcvar_float(g_redbull_time), "Redbull_over", id)
        RedBull[id] = true
	return PLUGIN_HANDLED
	}
	else
	{
         client_print(id, print_chat, "[ZP-RedBull] У вас нехватает АММО packs! Стоимость %i A.P. ", iCost)
	}
	return PLUGIN_HANDLED
}

public Redbull_over(id)
{
	RedBull[id] = false
	client_print(id, print_chat, "[ZP-RedBull] RedBull перестал действовать.")
}

public EVENT_round_start()
{
         for (new id; id <= 32; id++) RedBull[id] = false;
}

