Hello. Here's basically what I want to do - detect whenever a player buys something, what it is, and the cost. Right now I'm taking the restmenu.sma code for the detection and modifying it. This works fine to detect what a person tried to buy...but how do you figure out if it was successful or not?
I have one main array for players that stores a lot of values, including money. I figured I'd just compare the old money value to the new money value, and if they're different, then the buy was successful.
The problem is, the player's money doesn't change right away. I have to delay the check, so it looks like this (only relevant parts included):
Code:
register_menucmd(register_menuid("BuyPistol", 1), 511, "menuPistol")
// ... etc.
public menuPistol(id, key) return checkRest(id, 1, key)
checkRest(id, menu, key)
{
new team = get_user_team(id)
if (team != 1 && team != 2) return PLUGIN_HANDLED
new money_parameter[2]
money_parameter[0] = id
money_parameter[1] = mplayers[id][money]
set_task(0.1, "checkUserMoney", 10, money_parameter, 2)
return PLUGIN_CONTINUE
}
public checkUserMoney(money_parameter[])
{
new id = money_parameter[0]
new money = money_parameter[1]
new curr_money = cs_get_user_money(id)
if(money - curr_money != 0)
// do something here, the buy was a success
// update the player's money to the new value
mplayers[id][money] = curr_money
}
I'm thinking there's a better way to do this...I especially dislike the set_task() call because if you buy ammo really quickly, the money values don't update quickly enough and those numbers are incorrect. Any ideas?