#include <amxmodx>
// Some special includes
#include <hamsandwich>
#include <nvault>
#include <colorchat>
new const PLUGIN [] = "Gold System";
new const VERSION [] = "1.1";
new const AUTHOR [] = "LordOfNothing";
/* g var */
new cvar,savegold,gold[33];
public plugin_init()
{
register_plugin(PLUGIN,VERSION,AUTHOR);
/* Some Cvars : */
cvar = register_cvar("gold_kill","600");
/* Some Events : */
RegisterHam(Ham_Spawn, "player", "GoldKill", 1);
/* Show Your gold command */
register_clcmd("say /gold","GoldCmd");
register_clcmd("say_team /gold","GoldCmd");
/* Save Gold */
savegold = nvault_open("goldvault");
}
public plugin_natives()
{
register_native("get_user_gold","_get_gold");
register_native("set_user_gold","_set_gold");
}
public _get_gold(plugin, params)
{
return gold[get_param(1)];
}
public _set_gold(plugin, params)
{
new client = get_param(1);
gold[client] = max(0, get_param(2));
return gold[client];
}
public SaveGold(id)
{
new PlayerName[35];
get_user_authid(id,PlayerName,34);
new vaultkey[64],vaultdata[256];
format(vaultkey,63,"%s",PlayerName);
format(vaultdata,255,"%i",gold[id]);
nvault_set(savegold,vaultkey,vaultdata);
return PLUGIN_CONTINUE;
}
public LoadGold(id)
{
new PlayerName[35];
get_user_authid(id,PlayerName,34);
new vaultkey[64],vaultdata[256];
format(vaultkey,63,"%s",PlayerName);
nvault_get(savegold,vaultkey,vaultdata,255);
replace_all(vaultdata, 255, " ", " ");
new playerlives[33];
parse(vaultdata, playerlives, 31);
gold[id] = str_to_num(playerlives);
return PLUGIN_CONTINUE;
}
public GoldKill(victim,attacker,shouldgib)
{
if(!attacker || attacker == victim)
return PLUGIN_HANDLED;
gold[attacker] += get_pcvar_num(cvar);
return PLUGIN_CONTINUE
}
public GoldCmd(id)
{
ColorChat(id, RED, "[GOLD] ^4You have %i gold !",gold[id]);
return;
}
public client_authorized(id)
{
LoadGold(id);
}
public client_disconnect(id)
{
SaveGold(id);
}