/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <biohazard>
#include <cstrike>
#include <fun>
#include <hamsandwich>
#include <fakemeta>

#define PLUGIN "[BIO]Umbrella soldier"
#define VERSION "0.1"
#define AUTHOR "MAN?"

new cvar_cost,cvar_hp,cvar_armor,cvar_speed,cvar_ammo
new bool:g_soldier[33],Ham:Ham_Player_ResetMaxSpeed = Ham_Item_PreFrame

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	RegisterHam(Ham_Player_PreThink, "player", "Player_PreThink_Pre")
	RegisterHam(Ham_Killed, "player", "Player_Killed_Post", 1)
	RegisterHam(Ham_Spawn, "player", "Spawn", 1)
	
	//COMMANDS//
	register_clcmd("say /soldier","buy_soldier")
	register_clcmd("say soldier","buy_soldier")
	
	//CVA?S//
	cvar_cost = register_cvar("bh_usoldier_cost","8000")
	cvar_hp = register_cvar("bh_usoldier_hp","150")
	cvar_armor = register_cvar("bh_usoldier_armor","150")
	cvar_speed = register_cvar("bh_usoldier_speed","300.0")
	cvar_ammo = register_cvar("bh_usoldier_g36_ammo","200")
}

public buy_soldier(id){
	//IS USE? CONNECTED//
	if(!is_user_connected(id))
	return PLUGIN_CONTINUE
	//IS USE? ALIVE//
	if(!is_user_alive(id)){
	client_print(id,print_chat,"[BIOSCAN]You are dead.")
	return PLUGIN_CONTINUE
	}
	//IS USE? ZOMBIE//
	if(is_user_zombie(id)){
	client_print(id,print_chat,"[BIOSCAN]You are zombie.")
	return PLUGIN_CONTINUE
	}
	//IS USE? DON'T HAVE MONEY//
	if(cs_get_user_money(id)< get_pcvar_num(cvar_cost)){
	client_print(id,print_chat,"[BIOSCAN]You need $%s",get_pcvar_num(cvar_cost))
	return PLUGIN_CONTINUE
	}
	cs_set_user_money(id,cs_get_user_money(id) - get_pcvar_num(cvar_cost),1)
	set_hudmessage(0, 146, 0, -1.0, -1.0, 0, 6.0, 5.0)
	show_hudmessage(id, "Press 'N' to use nightvision")
	g_soldier[id] = true
	set_user_health(id,get_pcvar_num(cvar_hp))
	set_user_armor(id,get_pcvar_num(cvar_armor))
	give_item(id,"weapon_g3sg1")
	give_item(id,"weapon_hegrenade")
	cs_set_user_bpammo(id,CSW_HEGRENADE,2)
	cs_set_user_bpammo(id,CSW_G3SG1,get_pcvar_num(cvar_ammo))
	cs_set_user_nvg(id,1)
	return PLUGIN_HANDLED
}

public Player_PreThink_Pre(id)
{
	if(is_user_alive(id))
	{
		if(!g_soldier[id])
		{
			ExecuteHamB(Ham_Player_ResetMaxSpeed, id)
			return PLUGIN_CONTINUE
		}
		set_pev(id, pev_maxspeed, get_pcvar_float(cvar_speed))
	}
	return PLUGIN_CONTINUE
}

public Player_Killed_Post(victim)
{
	g_soldier[victim] = false
}

public Spawn(id){
	g_soldier[id] = false
}

public event_infect(id){
        g_soldier[id] = false
}
	
