Raised This Month: $ Target: $400
 0% 

Detect buy success


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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