Raised This Month: $ Target: $400
 0% 

Detect buy success


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Warthog
Junior Member
Join Date: Feb 2007
Old 02-25-2007 , 03:35   Detect buy success
Reply With Quote #1

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?

Last edited by Warthog; 02-25-2007 at 03:38.
Warthog is offline
Warthog
Junior Member
Join Date: Feb 2007
Old 02-25-2007 , 04:07   Re: Detect buy success
Reply With Quote #2

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).
Warthog is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 02-25-2007 , 07:14   Re: Detect buy success
Reply With Quote #3

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
VEN is offline
Warthog
Junior Member
Join Date: Feb 2007
Old 02-25-2007 , 12:13   Re: Detect buy success
Reply With Quote #4

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.
Warthog is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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