/* Plugin generated by AMXX-Studio */

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

#define PLUGIN "Start Q Mode ^^"
#define VERSION "SAMPLE"
#define AUTHOR "nico"

new g_MaxPlayers
new g_q[33], g_itemchan

new cvar_q[5]

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	g_MaxPlayers = get_maxplayers()
	
	g_itemchan = zp_register_extra_item("Start QQ Round" , 25, ZP_TEAM_ANY)
	
	register_forward(FM_PlayerPreThink, "fw_PlayerPreThink")
	
	RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
	RegisterHam(Ham_Killed, "player", "fw_Killed")
	
	cvar_q[0] = register_cvar("zp_quser_health", "600")
	cvar_q[1] = register_cvar("zp_quser_speed", "280.0")
	cvar_q[2] = register_cvar("zp_quser_gravity", "0.7")
	cvar_q[3] = register_cvar("zp_quser_armor", "555")
	cvar_q[4] = register_cvar("zp_quser_dmg_x", "5.0")
	
	register_event("HLTV", "event_round_start", "a", "1=1", "2=2")
	
	register_concmd("zp_q", "cmd_q", ADMIN_MENU, "Start Q Mode", 0)

}
public event_round_start()
{
	for(new i = 0; i <= g_MaxPlayers; i++)
	{
		g_q[i] = false
	}
}
public zp_extra_item_selected(id, itemid)
{
	if(itemid == g_itemchan && !zp_has_round_started())
	{
		changehim(id)
		
		for(new i = 0; i <= g_MaxPlayers; i++)
		{
			if(!g_q[i])
			{
				zp_infect_user(i, 1, 0, 0)
			}
		}
		zp_is_swarm_round()
		
	}
	else if(zp_has_round_started())
	{
		zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) +50)
		client_print(id, print_chat, "You can not buy this item after the round starts")
	}
}  
public changehim(id)
{
	g_q[id] = true
	
	set_user_health(id, get_pcvar_num(cvar_q[0]))
	set_user_gravity(id, get_pcvar_float(cvar_q[2]))
	set_user_armor(id, get_pcvar_num(cvar_q[3]))
	
	give_item(id, "weapon_ak47")
	give_item(id, "weapon_deagle")
	give_item(id, "weapon_hegrenade")
	
}
public fw_PlayerPreThink(id)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED
	
	if(!g_q[id])
		return FMRES_IGNORED
		
	set_user_maxspeed(id, get_pcvar_float(cvar_q[1]))
	
	return PLUGIN_CONTINUE
}
public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
{
	if(!is_user_alive(attacker))
		return HAM_IGNORED
	if(g_q[attacker])
	{
		SetHamParamFloat(4, damage*get_pcvar_num(cvar_q[4]))
	}
	
	return HAM_IGNORED
}
public fw_Killed(victim, attacker, shouldgib)
{
	if(g_q[victim])
		g_q[victim] = false
}
public cmd_q(id, level, cid)
{
	if (!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED;
		
	if(zp_has_round_started())
		return PLUGIN_HANDLED
		
	static arg[32], player
	read_argv(1, arg, charsmax(arg))
	
	player = cmd_target(id, arg, (CMDTARGET_ONLY_ALIVE | CMDTARGET_ALLOW_SELF))
	
	if (!player) return PLUGIN_HANDLED
	
	changehim(player)
	
	for(new i = 0; i <= g_MaxPlayers; i++)
	{
		if(!g_q[i])
		{
			zp_infect_user(i, 1, 1, 1)
		}
	}
	return PLUGIN_HANDLED
}