09.09.2013, 15:06
(
Last edited by Dragonsaurus; 05/10/2014 at 09:23 AM.
Reason: Updated!
)
Introduction:
This seems to be my first released include... Maybe this looks too simple, but may come very handy for your server!
This include will check when money is given to/taken from a player.
So let's explain something about this include:
There are 2 new callbacks:
As shown above, these callbacks contain the new and the old score/money values of the player.
These callbacks get called every time the SetPlayerMoney, GivePlayerMoney, SetPlayerScore, GivePlayerScore (Read below) functions or generally when the money status of the player changes.
This include also contains one new function:
This function gives score instead of setting it.
New:
OnPlayerMoneyStateChange has a new paramerer, unlike the previous version.
Now you will be able to detect if the given or lost money is called by default SA-MP functions, or gained by stunt bonuses, sprunk machines, gambling or even money hacks!
Using OnPlayerUpdate instead of a timer for better performance (Money or score could change frequently per second, so OnPlayerUpdate seemed more accurate).
Usage:
Installation:
You don't need to use these callbacks in every script, they'll work fine if used only once (Gamemode recommended).
Download: Credits:
This seems to be my first released include... Maybe this looks too simple, but may come very handy for your server!
This include will check when money is given to/taken from a player.
So let's explain something about this include:
There are 2 new callbacks:
pawn Code:
public OnPlayerMoneyStateChange(playerid, newmoney, oldmoney, bool:scripted)
public OnPlayerScoreStateChange(playerid, newscore, oldscore)
As shown above, these callbacks contain the new and the old score/money values of the player.
These callbacks get called every time the SetPlayerMoney, GivePlayerMoney, SetPlayerScore, GivePlayerScore (Read below) functions or generally when the money status of the player changes.
This include also contains one new function:
pawn Code:
GivePlayerScore(playerid, score);
This function gives score instead of setting it.
New:
OnPlayerMoneyStateChange has a new paramerer, unlike the previous version.
Now you will be able to detect if the given or lost money is called by default SA-MP functions, or gained by stunt bonuses, sprunk machines, gambling or even money hacks!
Using OnPlayerUpdate instead of a timer for better performance (Money or score could change frequently per second, so OnPlayerUpdate seemed more accurate).
Usage:
pawn Code:
public OnPlayerMoneyStateChange(playerid, newmoney, oldmoney, bool:scripted)
{
// Printing cash informations from the callback:
new cashdiff = newmoney-oldmoney;
if(cashdiff < 0) cashdiff = -cashdiff;
printf("Current Money: $%i | Old Money: $%i | %s: $%i | %s", newmoney, oldmoney, (cashdiff > 0) ? ("Received") : ("Lost"), cashdiff, (scripted) ? ("Given by script") : ("Not scripted"));
// Checking for possible negative cash:
new ccash = newmoney - GetPlayerMoney(playerid);
if((ccash) < 0) printf("ID %i | Negative money: $%i", playerid, ccash);
// Reseting money if taken by non scripted ways:
if(!scripted)
{
SetPlayerMoney(playerid, oldmoney);
new difference = newmoney - oldmoney;
printf("ID: %s | %s $%d (Not given by script)", playerid, (difference > 0) ? ("Earned") : ("Lost"), (difference > 0) ? difference : -difference);
}
// Updating any textdraws:
new _str_[30];
format(_str_, sizeof(_str_), "Last money earned: $%i", newmoney - oldmoney);
TestDrawSetString(MoneyTD[playerid], _str_);
return 1;
}
pawn Code:
public OnPlayerScoreStateChange(playerid, newscore, oldscore)
{
// Updating any textdraws, by getting rid of 0.5 - 5 second timers or OnPlayerUpdate...
new _str_[8 + 10];
format(_str_, sizeof(_str_), "Score: %i", newscore);
TextDrawSetString(ScoreTD[playerid], _str_);
return 1;
}
- Put msc.inc inside pawno/include folder.
- Add this line under the defines ON EVERY SCRIPT you have:
pawn Code:#include <msc> - Recompile your scripts!
You don't need to use these callbacks in every script, they'll work fine if used only once (Gamemode recommended).
Download: Credits:
- wups - Inspiration from OnPlayerShootPlayer <3
- Emmet_ - Suggested something really useful
- Rajat_Pawar - Suggestion + pointed out a little mistake, which is now fixed!
Opinions and ratings are welcome!