I don't know how to explain it with words in order for you guys to understand, but this may give you an idea
PHP Code:
new g_Money[33]
new g_MsgMoney
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("Money", "event_money", "b")
g_MsgMoney = get_user_msgid("Money")
}
public handle_money_event(id)
{
// This will block any engine money rewards
set_msg_block(g_MsgMoney, BLOCK_SET)
}
// We update the money hud with a little delay to avoid having written in the money flash hud incorrect values
public client_putinserver(id)
{
g_Money[id] = get_cvar_num("mp_startmoney")
set_task(0.1, "UpdateMoney", id)
}
public OnDamage(victim, attacker, etc)
{
g_Money[attacker] += damage
set_task(0.1, "UpdateMoney", id)
}
public OnKill(victim, attacker, etc)
{
g_Money[attacker] += 500
set_task(0.1, "UpdateMoney", id)
}
public OnSpawn(id)
{
// This will manually update the money hud at spawn, since the automatic update is blocked above in the money event
set_task(0.1, "UpdateMoney", id)
}
public UpdateMoney(id)
{
cs_set_user_money(id, g_Money[id], 1)
}
I am wondering if it wouldn't be better to do it with a global task and player loop since to avoid the big number of frequent tasks and checks from the take damage event
PHP Code:
new g_Money[33]
new g_MsgMoney
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("Money", "event_money", "b")
g_MsgMoney = get_user_msgid("Money")
}
public plugin_cfg()
{
set_task(0.1, "UpdateMoney", id, _,_, "b")
}
public handle_money_event(id)
{
set_msg_block(g_MsgMoney, BLOCK_SET)
}
public client_putinserver(id)
{
g_Money[id] = get_cvar_num("mp_startmoney")
}
public OnDamage(victim, attacker, etc)
{
g_Money[attacker] += damage
}
public OnKill(victim, attacker, etc)
{
g_Money[attacker] += 500
}
public UpdateMoney()
{
new iPlayers[32] , iNum , Player;
get_players( iPlayers , iNum , "h" );
for ( new i = 0 ; i < iNum ; i++ )
{
Player = iPlayers[i];
cs_set_user_money(Player, g_Money[Player], 1)
}
}
__________________