Ahhh E'z
There's a very simple legacy way of controlling cash:
That is
GivePlayerMoney(playerid, amount);
For negative amounts:
GivePlayerMoney(playerid, -amount);
However with this system, people are gonna hack the shit out of your server.
What you want to do is use that [pCash] variable you are currently employing.
That is achieved by making a stock:
pawn Код:
stock GivePlayerMoneyEx(playerid, value)
{
PlayerInfo[playerid][pCash] = PlayerInfo[playerid][pCash] + value;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
}
This basically means that your cash is actually based on [pCash] instead of the legacy moneybar, and the moneybar @ the HUD is just a display for your [pCash] variable.
So wherever you would use GivePlayerMoney() in your script, write it as GivePlayerMoneyEx().
Also, undertaking this system of money-control allows you to easily check for hacks.
under OnPlayerUpdate, run this block of code:
pawn Код:
if(GetPlayerMoney(playerid) > PlayerInfo[playerid][pCash])
{
new HackedAmount;
HackedAmount = GetPlayerMoney(playerid) - PlayerInfo[playerid][pCash];
OnPlayerHaveHackedMoney(playerid, HackedAmount);
}
This will check if the value displayed on the moneybar is actually larger than the amount of cash the player has received via server functions. If it is? It will run OnPlayerHaveHackedMoney.
OnPlayerHaveHackedMoney is not a native function, so you will need to forward it:
pawn Код:
forward OnPlayerHaveHackedMoney(playerid, HackedAmount);
And then give it functionality.
pawn Код:
public OnPlayerHaveHackedMoney(playerid, value)
{
new hacker[64];
new string[128];
GetPlayerName(playerid, hacker);
if(value > 49) //what bonehead would try and hack less lmao
{
format(string, 256, "<A> HackWarning: [%d]%s attempted to spawn $%d.",playerid, hacker, value);
//you now have 'string' which contains ^^. Insert here your admin broadcast code
//here you also insert your disciplinary code, whether it be warn, Ban(playerid), Kick(playerid) or w/e
}
}
If you don't feel the need to ban a player for attempting to moneyhack, you can run the following code in OnPlayerHaveHackedMoney:
pawn Код:
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
That will simply just reset their moneybar constantly to their [pCash] value and hopefully their frustration will encourage them to give up : D