/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <halomod>

#define PLUGIN "HaloMod Spawn Protection"
#define VERSION HALOVERSION
#define AUTHOR "Soccdoodcss"

new pProtect, pOn

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	pOn = register_cvar("halo_protection", "1", FCVAR_SERVER)
	pProtect = register_cvar("halo_protection_time", "3.0", FCVAR_SERVER)
	
	register_event("RoundTime", "onRound", "be")
}

public onRound(id)
{
	if(!is_halo_on() || !is_user_alive(id) || !get_pcvar_num(pOn))
		return PLUGIN_HANDLED
	
	set_user_protection(id, 1)
	
	return PLUGIN_HANDLED
}

public unProtect(id)
{
	if (!is_user_connected(id))
		return PLUGIN_HANDLED
		
	set_user_protection(id, 0)
	
	return PLUGIN_HANDLED
}


public set_user_protection(id, protect)
{
	
	if(protect)
	{
		set_pev(id, pev_takedamage, 0.0)
		
		set_task(get_pcvar_float(pProtect), "unProtect", id)
	}
	
	else
	{
		set_pev(id, pev_takedamage, 2.0)
	}
}
