Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <nvault>
#define PLUGIN ""
#define VERSION ""
#define AUTHOR ""
#define STATS_COINS 0
#define UPDATETIME 5.0
new g_coins[33][1];
new vault, wid, hs;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
RegisterHam(Ham_Killed, "player", "fw_PlayerKilled", 1)
register_clcmd( "amx_setcoins", "SetCoins", ADMIN_MENU );
set_task( UPDATETIME, "ShowCoinDetails", _, _, _, "b" );
vault = nvault_open("SaveCoins")
}
public fw_PlayerKilled(victim, attacker)
{
if (victim == attacker || !is_user_alive(attacker) )
return
new A_name[32], V_name[32];
get_user_name( attacker , A_name , charsmax( A_name ) );
get_user_name( victim , V_name , charsmax( V_name ) );
attacker = get_user_attacker(victim,wid,hs)
if(get_user_weapon(attacker) == CSW_KNIFE)
{
g_coins[attacker][STATS_COINS]+=1
//client_print (attacker, print_chat, "You killed %s with a knife", V_name)
//client_print (victim, print_chat, "You were killed by %s with a knife", A_name)
}
else if(hs==HIT_HEAD)
{
g_coins[attacker][STATS_COINS]+=2
//client_print (victim, print_chat, "%s got you a headshoot", A_name)
}
g_coins[attacker][STATS_COINS]++
client_print( attacker, print_center, "Coins %d", g_coins[attacker]);
}
public SetCoins( id, level, cid )
{
if (!cmd_access(id,level,cid,2))
return PLUGIN_HANDLED ;
new sxName[ 50 ], szName[ 32 ];
get_user_name( id , szName , charsmax( szName ) );
read_argv( 1, sxName, 49 );
new valSz[ 50 ], val;
read_argv( 2, valSz, 49 );
val = str_to_num( valSz );
new user = cmd_target( id, sxName, CMDTARGET_ALLOW_SELF );
g_coins[user][STATS_COINS] = val * 1;
client_print_color(0, "!t%s !greceive [%d] !tfrom the admin !g%s",sxName, g_coins[user][STATS_COINS], szName);
return PLUGIN_HANDLED;
}
public ShowCoinDetails()
{
new Players[ 32 ];
new playerCount, i, player;
get_players(Players, playerCount, "ach");
for (i=0; i<playerCount; i++)
{
player = Players[ i ];
new name[ 50 ];
get_user_name( player, name, 49 );
new x_coins = g_coins[player][STATS_COINS]
if(is_user_alive(player))
{
set_hudmessage( 0, 255, 255, 0.02, 0.17, 0, 6.0, UPDATETIME );
show_hudmessage( player, "[Coins : %i]",x_coins);
}
}
}
public client_putinserver(id)
{
new name[32],data[512],raw[1][20]
get_user_name(id,name,31)
if(!nvault_get(vault,name,data,511))
return PLUGIN_CONTINUE
parse(data,raw[0],19)
g_coins[id][STATS_COINS]=str_to_num(raw[0])
return PLUGIN_CONTINUE
}
public client_disconnect(id)
{
new name[32],data[512]
get_user_name(id,name,31)
formatex(data,511,"%d",g_coins[id][STATS_COINS])
nvault_set(vault,name,data)
}
stock client_print_color(const id, const input[], any:...)
{
new count = 1, players[32];
static msg[191];
vformat(msg, 190, input, 3);
replace_all(msg, 190, "!g", "^x04"); // Green Color
replace_all(msg, 190, "!y", "^x01"); // Default Color
replace_all(msg, 190, "!t", "^x03"); // Team Color
if (id) players[0] = id; else get_players(players, count, "ch");
{
for (new i = 0; i < count; i++)
{
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
}