AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detect buy success (https://forums.alliedmods.net/showthread.php?t=51849)

Warthog 02-25-2007 03:35

Detect buy success
 
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?

Warthog 02-25-2007 04:07

Re: Detect buy success
 
Hrmm...after looking a little further, could I use this with the register events like Money, AmmoPickup, WeapPickup, ItemPickup? Seems like I'd have to add a flag to check if the pickup was from a buy event or not (possibly using the Money event as a flag).

VEN 02-25-2007 07:14

Re: Detect buy success
 
You're moving in the right direction. I remember that another user has the similar problem so you have to look here for the technique details: http://forums.alliedmods.net/showthread.php?t=50704

Warthog 02-25-2007 12:13

Re: Detect buy success
 
ya know, out of all my searching, i actually found that thread, but never read it all the way through. :) it looks like using the registered events is a much more accurate and efficient way to detect everything i want.

thank you, i should be all set now. if i have any problems i'll post them back in here.


All times are GMT -4. The time now is 00:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.