[Include] OnPlayerMoneyChange
#1

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
Reply
#2

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

Good work xD
Reply
#4

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!
Reply
#5

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.
Reply
#6

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;
}
Reply
#7

Thank you!
Great include
Reply
#8

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.
Reply
#9

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

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.
Reply
#11

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.
Reply
#12

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.
Reply
#13

Nice job!
Reply
#14

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.
Reply
#15

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?
Reply
#16

looks great im gonna try to script this to detect cash hackers
Reply
#17

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 ...
Reply
#18

Good job
Reply
#19

Good work i will use it for my IRC Script .
Reply
#20

It's not compatible for filterscripts tbh
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)