SA-MP Forums Archive
[Include] OnPlayerMoneyChange - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] OnPlayerMoneyChange (/showthread.php?tid=254019)

Pages: 1 2


OnPlayerMoneyChange - Biesmen - 08.05.2011

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 Код:
#include <OPMC>
Example script:
pawn Код:
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



Re: OnPlayerMoneyChange - Alby Fire - 08.05.2011

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


Re: OnPlayerMoneyChange - Ironboy - 09.05.2011

Good work xD


Re: OnPlayerMoneyChange - justsomeguy - 09.05.2011

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!


Re: OnPlayerMoneyChange - Biesmen - 09.05.2011

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.


Re: OnPlayerMoneyChange - wups - 09.05.2011

I see big mistakes!
pawn Код:
#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 Код:
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;
}



Re: OnPlayerMoneyChange - nuriel8833 - 09.05.2011

Thank you!
Great include


Re: OnPlayerMoneyChange - Biesmen - 09.05.2011

Quote:
Originally Posted by wups
Посмотреть сообщение
pawn Код:
#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
Посмотреть сообщение
pawn Код:
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.


Re: OnPlayerMoneyChange - Jay_ - 09.05.2011

Quote:
Originally Posted by wups
Посмотреть сообщение
new ZmoneyZ[MAX_PLAYERS]; // Are you serious? This is stupid!
Why?


Re: OnPlayerMoneyChange - Biesmen - 09.05.2011

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.


Re: OnPlayerMoneyChange - wups - 09.05.2011

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
Because if you do not have 500 player slots, but 40, it'll be a waste to use 500 as length.

Agree, and I already changed it for version 2.0 before you even noticed this thread.

Thanks.
It's already defined in SA-MP includes, why do you undefine it?

Quote:
Originally Posted by Jay_
Посмотреть сообщение
Why?
Just... You're initiating a variable on every player update FOR every player AND use it for one player.


Re: OnPlayerMoneyChange - justsomeguy - 09.05.2011

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
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.
I am not sure if i believe that as i have seen an include that WAS an cent system but he took away the download.


Re: OnPlayerMoneyChange - Davz*|*Criss - 09.05.2011

Nice job!


Re: OnPlayerMoneyChange - Biesmen - 09.05.2011

Quote:
Originally Posted by wups
Посмотреть сообщение
It's already defined in SA-MP includes, why do you undefine it?
If you define MAX_PLAYERS as 50, it won't use 500 as max players in your server, quite obvious.

@Davz and everyone else
Thanks.


Re: OnPlayerMoneyChange - wups - 09.05.2011

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
If you define MAX_PLAYERS as 50, it won't use 500 as max players in your server, quite obvious.

@Davz and everyone else
Thanks.
Why is the REdefine needed in your include?


Re: OnPlayerMoneyChange - xalith - 17.05.2011

looks great im gonna try to script this to detect cash hackers


Re: OnPlayerMoneyChange - -=Dark=- - 28.05.2011

Quote:
Originally Posted by xalith
Посмотреть сообщение
looks great im gonna try to script this to detect cash hackers
Use this includ as anti-cheat? I do not think that this is true ...


AW: OnPlayerMoneyChange - Forbidden - 01.06.2011

Good job


Re: OnPlayerMoneyChange - Marshall32 - 07.12.2011

Good work i will use it for my IRC Script .


AW: OnPlayerMoneyChange - BigETI - 07.12.2011

It's not compatible for filterscripts tbh