Raised This Month: $ Target: $400
 0% 

Keeping track of how much money a player has


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-19-2008 , 15:55   Keeping track of how much money a player has
Reply With Quote #1

I'm working on a plugin that remembers all of a users game info between connections to the server. I have the score portion complete but now I am working on money.

Right now I am using the below to keep a record of the players money so that when they go to disconnect I will have a record of it so I can save it to a file. Is there a better way to go about this? I put a console_print on the below just to see how often it is updated and every single cash transactions triggers it, which is good, but I was concerned about preserving CPU\efficiency.

PHP Code:
public cmd_Money(id
{
    
g_Money[id] = cs_get_user_moneyid );

__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-22-2008 , 11:48   Re: Keeping track of how much money a player has
Reply With Quote #2

Bump.

Or just knowing how much $ a player has when they disconnect would work as well. The above code works fine but I have another function that cashes in all weapons\equipment a payer is carrying and gives them money credit. This way when they reconnect they can sort of start from where they left off.

It's probably puttng a hurtin' on CPU usage to call that at every money transaction and weapon-pickup/drop. I'm not knowledgeable at all with fakemeta or hamsandwich etc so I don't know if there is some other efficient way to just determine how much $\weapons a player has at disconnect.
__________________
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-22-2008 , 15:17   Re: Keeping track of how much money a player has
Reply With Quote #3

Code:
#include <amxmodx> #include <fakemeta> #define OFFSET_MONEY 115 #define cs_get_user_money(%1) get_pdata_int(%1, OFFSET_MONEY) public client_disconnect(plr) {     new money = cs_get_user_money(plr);         // money holds the player's money         return PLUGIN_CONTINUE; }

And if that doesn't work:

Code:
#include <amxmodx> #include <fakemeta> #define OFFSET_MONEY 115 #define cs_get_user_money(%1) get_pdata_int(%1, OFFSET_MONEY) new g_money[33]; public plugin_init() {     register_event("Money", "EventMoney", "b"); } public client_connect(plr) {     g_money[plr] = 0; } public client_disconnect(plr) {     // g_money[plr] holds the player's money } public EventMoney(plr) {     g_money[plr] = cs_get_user_money(plr);         return PLUGIN_CONTINUE; }

Or, if you don't want to use fakemeta:

Code:
#include <amxmodx> new g_money[33]; public plugin_init() {     register_event("Money", "EventMoney", "b"); } public client_connect(plr) {     g_money[plr] = 0; } public client_disconnect(plr) {     // g_money[plr] holds the player's money } public EventMoney(plr) {     g_money[plr] = read_data(1);         return PLUGIN_CONTINUE; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-22-2008 , 22:08   Re: Keeping track of how much money a player has
Reply With Quote #4

Quote:
Originally Posted by X-olent View Post
Code:
#include <amxmodx> #include <fakemeta> #define OFFSET_MONEY 115 #define cs_get_user_money(%1) get_pdata_int(%1, OFFSET_MONEY) public client_disconnect(plr) {     new money = cs_get_user_money(plr);         // money holds the player's money         return PLUGIN_CONTINUE; }

And if that doesn't work:

Code:
#include <amxmodx> #include <fakemeta> #define OFFSET_MONEY 115 #define cs_get_user_money(%1) get_pdata_int(%1, OFFSET_MONEY) new g_money[33]; public plugin_init() {     register_event("Money", "EventMoney", "b"); } public client_connect(plr) {     g_money[plr] = 0; } public client_disconnect(plr) {     // g_money[plr] holds the player's money } public EventMoney(plr) {     g_money[plr] = cs_get_user_money(plr);         return PLUGIN_CONTINUE; }

Or, if you don't want to use fakemeta:

Code:
#include <amxmodx> new g_money[33]; public plugin_init() {     register_event("Money", "EventMoney", "b"); } public client_connect(plr) {     g_money[plr] = 0; } public client_disconnect(plr) {     // g_money[plr] holds the player's money } public EventMoney(plr) {     g_money[plr] = read_data(1);         return PLUGIN_CONTINUE; }
That's pretty much what I'm doing now but when I make the plugin client_print when the Money event is called, I see it called many many times; at every item buy, every kill, round start. I was trying to find a way that didn't require so many updates. I know probably 90% of the time client_disconnect would allow me to get the users money but since theres that 10% where it won't work (because user is already disconnected) I really don't want to use it.

Thanks for the reply +karma
__________________
Bugsy is offline
Reply


Thread Tools
Display Modes

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 05:36.


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