SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 08/05/2011, 09:06 PM   #1
Biesmen
High-roller
 
Biesmen's Avatar
 
Join Date: May 2009
Posts: 1,060
Reputation: 665
Default OnPlayerMoneyChange

OnPlayerMoneyChange 2.0
Created by: Biesmen

About
Previously I made an include called OnPlayerEarnMoney and OnPlayerLoseMoney. After thinking wisely I came up with an conclusion that include wouldn't work properly as it should do. I decided to recreate it and rename it. The script is very easy to understand. The script will check the player's money once he spawns and store it in a variable. This will support servers who have a register/login system. If the player's money changes, negative or positive, it will call the callback "OnPlayerMoneyChange", with the amount that has been changed.

Version
Version 2.0

Change log:
Version 2.0
-Added one parameter to the callback: TotalAmount. This will return the money you have when the callback OnPlayerMoneyChange is being called.
-Modified a variable in the OnPlayerUpdate callback, in the include. Unnecessarily usage of MAX_PLAYERS is not needed.

How-to
Copy the script of the pastebin url.
Open a new notepad file. Paste the script you copied at the pastebin url.
Go to your GTA San Andreas server files folder.
Save the notepad file as OPMC.inc at /pawno/include.

In your gamemode/filterscript/script:
Type this at your includes list, at the top of your script:
pawn Code:
#include <OPMC>

Example script:
pawn Code:
public OnPlayerMoneyChange(playerid, amount, totalamount)
{
    new string[100];
    format(string, sizeof(string), "Your money has been changed with a value of $%i. Your total balance is: $%i", amount, totalamount);
    SendClientMessage(playerid, -1, string);
    return 1;
}

Download
Pastebin Version: 2.0
Pastebin Version: 1.0
No mirrors allowed!

Known bugs
None so far.
Feel free to post bugs on this section, if you found any.

Credits
  • Biesmen
  • Wups - Idea for the ALS Hooking

Last edited by Biesmen; 09/05/2011 at 05:04 PM.
Biesmen is offline   Reply With Quote
Old 08/05/2011, 10:23 PM   #2
Alby Fire
Big Clucker
 
Join Date: Dec 2010
Posts: 125
Reputation: 2
Default Re: OnPlayerMoneyChange

I liked very much the way you scripted it.. nice job
__________________

Thank blewert for this signature
Alby Fire is offline   Reply With Quote
Old 09/05/2011, 07:33 AM   #3
Ironboy
High-roller
 
Ironboy's Avatar
 
Join Date: Nov 2010
Location: Isle of Man
Posts: 1,933
Reputation: 429
Default Re: OnPlayerMoneyChange

Good work xD
__________________
Ironboy is offline   Reply With Quote
Old 09/05/2011, 09:12 AM   #4
justsomeguy
High-roller
 
justsomeguy's Avatar
 
Join Date: Apr 2010
Location: At rBn's fissa
Posts: 2,481
Reputation: 1976
Default Re: OnPlayerMoneyChange

I got an great idea!

Cents! like $1.75 dollars, and i know it is possible i've seen a script like that.
Anyway i am going to use this!
__________________
Mooi verhaal, man.
justsomeguy is offline   Reply With Quote
Old 09/05/2011, 09:30 AM   #5
Biesmen
High-roller
 
Biesmen's Avatar
 
Join Date: May 2009
Posts: 1,060
Reputation: 665
Default Re: OnPlayerMoneyChange

Then we have to make the player money amount function as a float.
We'll have to redefine/recreat GivePlayerMoney for this. But we can't do that in an include.
Biesmen is offline   Reply With Quote
Old 09/05/2011, 04:14 PM   #6
wups
High-roller
 
wups's Avatar
 
Join Date: Apr 2010
Location: Lithuania
Posts: 1,216
Reputation: 141
Default Re: OnPlayerMoneyChange

I see big mistakes!
pawn Code:
#undef MAX_PLAYERS
#define MAX_PLAYERS 500 // Change 500 to your server's playerslots.
// Why is this needed?
...
public OnPlayerUpdate(playerid)
{
        new ZmoneyZ[MAX_PLAYERS]; // Are you serious? This is stupid!
        if(GetPlayerMoney(playerid) != OPMCMoney[playerid]) // 1
        {
                ZmoneyZ[playerid] = GetPlayerMoney(playerid)-OPMCMoney[playerid]; // 2
                CallLocalFunction("OnPlayerMoneyChange", "ii", playerid, ZmoneyZ[playerid]);
                OPMCMoney[playerid] = GetPlayerMoney(playerid); // 3 - You use GetPlayerMoney function 3 times, when you can store it in a variable.
        }
        return (PlayerUP)?CallLocalFunction("Inc_OnPlayerUpdate","i", playerid):1;
}

Here's the correct code:
pawn Code:
public OnPlayerUpdate(playerid)
{
        new P_Money = GetPlayerMoney(playerid);
        if(P_Money != OPMCMoney[playerid])
        {
                CallLocalFunction("OnPlayerMoneyChange", "ii", playerid, (P_Money - OPMCMoney[playerid]));
                OPMCMoney[playerid] = P_Money;
        }
        return (PlayerUP)?CallLocalFunction("Inc_OnPlayerUpdate","i", playerid):1;
}
wups is offline   Reply With Quote
Old 09/05/2011, 04:25 PM   #7
nuriel8833
High-roller
 
nuriel8833's Avatar
 
Join Date: Jun 2009
Location: Israel
Posts: 1,158
Reputation: 16
Default Re: OnPlayerMoneyChange

Thank you!
Great include
__________________
Back to forums
Although I am not scripting much,only my gamemode on my free time

My works:
80.179.219.89:7778
[Tutorial] Kills Table BonusLast.fm
nuriel8833 is offline   Reply With Quote
Old 09/05/2011, 04:41 PM   #8
Biesmen
High-roller
 
Biesmen's Avatar
 
Join Date: May 2009
Posts: 1,060
Reputation: 665
Default Re: OnPlayerMoneyChange

Quote:
Originally Posted by wups View Post
pawn Code:
#undef MAX_PLAYERS
#define MAX_PLAYERS 500 // Change 500 to your server's playerslots.
// Why is this needed?
Because if you do not have 500 player slots, but 40, it'll be a waste to use 500 as length.
Quote:
Originally Posted by wups View Post
pawn Code:
new ZmoneyZ[MAX_PLAYERS]; // Are you serious? This is stupid!
Agree, and I already changed it for version 2.0 before you even noticed this thread.

Thanks.
Biesmen is offline   Reply With Quote
Old 09/05/2011, 04:53 PM   #9
Jay_
Gangsta
 
Jay_'s Avatar
 
Join Date: Jul 2009
Posts: 653
Reputation: 197
Default Re: OnPlayerMoneyChange

Quote:
Originally Posted by wups View Post
new ZmoneyZ[MAX_PLAYERS]; // Are you serious? This is stupid!
Why?
Jay_ is offline   Reply With Quote
Old 09/05/2011, 05:06 PM   #10
Biesmen
High-roller
 
Biesmen's Avatar
 
Join Date: May 2009
Posts: 1,060
Reputation: 665
Default Re: OnPlayerMoneyChange

Version 2.0 is now released
Changes:
-Added one parameter to the callback: TotalAmount. This will return the money you have when the callback OnPlayerMoneyChange is being called.
-Modified a variable in the OnPlayerUpdate callback, in the include. Unnecessarily usage of MAX_PLAYERS is not needed.
Biesmen is offline   Reply With Quote
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



All times are GMT. The time now is 11:03 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.