/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <codmod>
#include <fakemeta>
#include <ColorChat>
#include <colorstatus.inc>

new cvar_lvl, 
cvar_steam_lvl,
cvar_steam_ordery;

new cvar_wylacz_info

public plugin_init() 
{
	register_plugin("Darmowy Level na start", "1.0", "Play");
	
	register_event( "ResetHUD", "eventUpdateStatus", "be");
	register_event( "StatusValue", "eventUpdateStatus", "be", "1=1"	,"2=0");
		
	register_clcmd("say /dajlvl", "UstawPoziom");
	register_clcmd("say /dodajlvl", "UstawPoziom");
	register_clcmd("say /freelvl", "UstawPoziom");
	register_clcmd("say /free", "UstawPoziom");

	cvar_lvl = register_cvar("cod_free_level", "49");
	cvar_steam_lvl = register_cvar("cod_steam_free_level", "70");
	cvar_steam_ordery = register_cvar("cod_free_ordery", "150");
	cvar_wylacz_info = register_cvar("wylacz_info", "0");  // 0 - wlacza plugin | 1 - wylacza plugin
	
	initColorStatus();
}

public UstawPoziom(id)
{
	if(is_user_steam(id) && cod_get_user_level(id) < get_pcvar_num(cvar_steam_lvl))
	{
		cod_set_user_xp(id, cod_get_level_xp(get_pcvar_num(cvar_steam_lvl)));
		cod_set_user_Ordery(id, cod_get_user_Ordery(id) + get_pcvar_num(cvar_steam_ordery));
		ColorChat(id, RED, "[COD Elite]^x01 Dzieki^x04 STEAM^x01 pobrales^x03 %i^x01 darmowych leveli i^x03 %i^x01 orderow na start!"
		, get_pcvar_num(cvar_steam_lvl), get_pcvar_num(cvar_steam_ordery));			
	}
	else if (cod_get_user_level(id) < get_pcvar_num(cvar_lvl))
	{
		cod_set_user_xp(id, cod_get_level_xp(get_pcvar_num(cvar_lvl)));
		ColorChat(id, GREEN, "[COD Elite]^x01 Pobrales^x03 %i^x01 darmowych leveli na start", get_pcvar_num(cvar_lvl));
	}
	else
		ColorChat(id, GREEN, "[COD Elite]^x01 Tylko raz na jednej klasie mozesz pobrac level");
}
public eventUpdateStatus(id)
{		
	if(get_pcvar_num(cvar_wylacz_info) > 0)
		return PLUGIN_HANDLED;
		
	if (cod_get_user_level(id) < get_pcvar_num(cvar_lvl))
	{	
		makeStatusText(id, GREY_STATUS, 0.0,", nie skorzystales jeszcze z darmowego bonusu ! Wpisz /freelvl");
	}
	return PLUGIN_CONTINUE;
}

stock bool:is_user_steam(id)
{
	static dp_pointer;
	if(dp_pointer || (dp_pointer = get_cvar_pointer("dp_r_id_provider")))
	{
		server_cmd("dp_clientinfo %d", id)
		server_exec()
		return (get_pcvar_num(dp_pointer) == 2) ? true : false
	}
	
	new szAuthid[34];
	get_user_authid(id, szAuthid, charsmax(szAuthid))
	
	return (containi(szAuthid, "LAN") < 0)
}
