#include <amxmodx>
#include <amxmisc>
#include <fun>


public plugin_init()
{
	register_plugin("Ochrona na Spawnie PL", "7.0", "Peli")
	register_concmd("amx_sptime", "cmd_sptime", ADMIN_CVAR, "Od 1 do 10 - Czas przez jaki ma byc ochrona na poczatku rundy")
	register_concmd("amx_spmessage", "cmd_spmessage", ADMIN_CVAR, "1 - Wlaczona wiadomosc o ochronie na poczatku rundy, 0 - wylaczona")
	register_concmd("amx_spshellthickness", "cmd_spshellthickness", ADMIN_CVAR, "Od 1 do 100 - Grubosc powloki ochronnej")
	register_cvar("sv_sp", "1") // 1 - wlacza plugin, 0 wylacza 
	register_cvar("sv_sptime", "5") // Od 1 do 10 - Czas przez jaki ma byc ochrona na poczatku rundy
	register_cvar("sv_spmessage", "1") // 1 - Wlaczona wiadomosc o ochronie na poczatku rundy, 0 - wylaczona
	register_cvar("sv_spshellthick", "25") // Od 1 do 100 - Grubosc powloki ochronnej
	register_event("ResetHUD", "sp_on", "be")
	register_clcmd("fullupdate", "clcmd_fullupdate")
}

public client_disconnect(id)
{
	remove_task(id)
	return PLUGIN_HANDLED
}

public cmd_sptime(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED
	
	new arg_str[3]
	read_argv(1, arg_str, 3)
	new arg = str_to_num(arg_str)
	
	if(arg > 10 || arg < 1)
	{
		client_print(id, print_chat, "Mozesz ustawic czas ochrony od 1 do 10 sekund")
		return PLUGIN_HANDLED
	}
	
	else if (arg > 0 || arg < 11)
	{
		set_cvar_num("sv_sptime", arg)
		client_print(id, print_chat, "Ochrona trwa 5sek", arg)
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}
//----------------------------------------------------------//
public cmd_spmessage(id, level, cid)
{
	if (!cmd_access(id, level, cid, 2))
	{
		return PLUGIN_HANDLED
	}
	
	new sp[3]
	read_argv(1, sp, 2)
	
	if (sp[0] == '1')
	{
		set_cvar_num("amx_spmessage", 1)
	}
	
	else if (sp[0] == '0')
	{
		set_cvar_num("amx_spmessage", 0)
	}
	
	else if (sp[0] != '1' || sp[0] != '0')
	{
		console_print(id, "1 - Wlaczona wiadomosc o ochronie na poczatku rundy, 0 - wylaczona")
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_HANDLED
}
//----------------------------------------------------------//
public cmd_spshellthickness(id, level, cid)
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED
	
	new arg_str[3]
	read_argv(1, arg_str, 3)
	new arg = str_to_num(arg_str)
	
	if(arg > 100 || arg < 1)
	{
		client_print(id, print_chat, "Od 1 do 100 - Grubosc powloki ochronnej")
		return PLUGIN_HANDLED
	}
	
	else if (arg > 0 || arg < 101)
	{
		set_cvar_num("sv_spshellthickness", arg)
		client_print(id, print_chat, "Grubosc powloki ochronnej to 25", arg)
		return PLUGIN_HANDLED
	}
	return PLUGIN_CONTINUE
}
//----------------------------------------------------------//
public sp_on(id)
{
	if(get_cvar_num("sv_sp") == 1)
	{
		set_task(0.1, "protect", id)
	}
	
	return PLUGIN_CONTINUE
}
//----------------------------------------------------------//
public protect(id)
{
	new Float:SPTime = get_cvar_float("sv_sptime")
	new SPSecs = get_cvar_num("sv_sptime")
	new FTime = get_cvar_num("mp_freezetime")
	new SPShell = get_cvar_num("sv_spshellthick")
	set_user_godmode(id, 1)
	
	if(get_user_team(id) == 1)
	{
		set_user_rendering(id, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, SPShell)
	}
	
	if(get_user_team(id) == 2)
	{
		set_user_rendering(id, kRenderFxGlowShell, 0, 0, 255, kRenderNormal, SPShell)
	}
	
	if(get_cvar_num("sv_spmessage") == 1)
	{
		set_hudmessage(1, 255, 1, -1.0, -1.0, 0, 6.0, SPTime+FTime, 0.1, 0.2, 4)
		show_hudmessage(id, "Ochrona trwa %d sekund", SPSecs)
	}
	
	set_task(SPTime+FTime, "sp_off", id)
	return PLUGIN_HANDLED
}
//----------------------------------------------------------//
public sp_off(id)
{
	new SPShell = get_cvar_num("sv_spshellthick")
	if(!is_user_connected(id))
	{
		return PLUGIN_HANDLED
	}
	
	else
	{
		set_user_godmode(id, 0)
		set_user_rendering(id, kRenderFxGlowShell, 0, 0,0, kRenderNormal, SPShell)
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_HANDLED
}
//----------------------------------------------------------//
public clcmd_fullupdate(id)
{
	return PLUGIN_HANDLED
}
//----------------------------------------------------------//
