/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <nvault>

#define PLUGIN "System Orderow"
#define VERSION "1.0"
#define AUTHOR "Play"

new vault;
new g_name[33][48]
new Ordery[33];

native cod_get_user_Ordery(id)
native cod_set_user_Ordery(id, wartosc)

	
public plugin_init()
{

	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_cvar("Ordery[KILL]", "1" );
	register_cvar("Ordery[KILL_HS]", "2" ); 	
	
	register_event("DeathMsg", "DeathMsg", "a")
	
	register_concmd("ustawordery", "UstawOrdery", ADMIN_IMMUNITY, "<name> <amount>");
	
	vault = nvault_open("Ordery")
	if(vault == INVALID_HANDLE)
		set_fail_state("Nie moge otworzyc pliku :/");
}
public plugin_natives()
{
	register_native("cod_get_user_Ordery", "GetOrdery", 1);
	register_native("cod_set_user_Ordery", "SetOrdery", 1);
}
public client_authorized(id) 
{
	WczytajOrdery(id);
}

public plugin_end()
	nvault_close(vault);
	
public client_disconnect(id) 
{	
	ZapiszOrdery(id)
	
}
public DeathMsg(id)
{
	new kid = read_data(1);
	new vid = read_data(2);
	new hs = read_data(3);

	if(kid == vid)
		return;
		
	if(hs) 
		Ordery[kid] += get_cvar_num("Ordery[KILL_HS]")
	
	else 
		Ordery[kid] += get_cvar_num("Ordery[KILL]")
	
	
	
}
public UstawOrdery(id, level, cid)
{
	if(!cmd_access(id, level, cid, 3))
		return PLUGIN_CONTINUE;
	
	new arg[33];
	read_argv(1, arg, 32);
	new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF);
	
	if(!is_user_connected(target))
		return PLUGIN_CONTINUE;
	
	read_argv(2, arg, 32);
	new IleOrderow = str_to_num(arg);
	
	cod_set_user_Ordery(target, IleOrderow);
	
	return PLUGIN_CONTINUE;
}
public SetOrdery(id, wartosc)
	Ordery[id] = wartosc;
	
public GetOrdery(id)
	return Ordery[id];
	
public WczytajOrdery(id)
{
	new name[48]
	get_user_name(id,name,47)
	new vaultkey[64],vaultdata[128]
	formatex(vaultkey,63,"%s-Ordery",name)
	
	if(nvault_get(vault,vaultkey,vaultdata,127)) 
	{ 
		new temp_ordery[16], temp_name[48];
		parse(vaultdata, temp_ordery, 15, temp_name, 47)
		
		Ordery[id] = str_to_num(temp_ordery)
		copy(g_name[id], 47, temp_name);
	}
	
	return PLUGIN_CONTINUE
}
public ZapiszOrdery(id) 
{	
	new name[48]
	get_user_name(id,name,47)
	new vaultkey[64],vaultdata[128]
	formatex(vaultkey,63,"%s-Ordery", name)
	formatex(vaultdata,127,"%d ^"%s^"", Ordery[id], name)
	nvault_set(vault,vaultkey,vaultdata)
	
	return PLUGIN_CONTINUE
}	