PDA

View Full Version : [Tutorial] Serverside Money. (Impossible to hack)



SergiuOfficial
29-05-17, 17:46
Serverside Money Tutorial


Information:
* This tutorial was intended for roleplay gamemodes.
* This will not work with clientside features, etc stunt bonuses, sprunk machines and burger shot, they will just be able to purchase stuff for free.


Functions:
Code:
#define ResetMoneyBar ResetPlayerMoney
#define UpdateMoneyBar GivePlayerMoney

new Cash[MAX_PLAYERS];

stock GivePlayerCash(playerid, money)
{
Cash[playerid] += money;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return Cash[playerid];
}
stock SetPlayerCash(playerid, money)
{
Cash[playerid] = money;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return Cash[playerid];
}
stock ResetPlayerCash(playerid)
{
Cash[playerid] = 0;
ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
return Cash[playerid];
}
stock GetPlayerCash(playerid)
{
return Cash[playerid];
}

OnPlayerConnect
Code:
ResetPlayerCash(playerid); //Resetting the players cash variable to zero.

OnGameModeInit
Code:
SetTimer("MoneyTimer", 1000, 1);

Money check timer, this will reset there money to there serverside money if they attempted to hack/picked up money in an interior.
Code:
public MoneyTimer()
{
new username[MAX_PLAYER_NAME];
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(GetPlayerCash(i) != GetPlayerMoney(i))
{
ResetMoneyBar(i);//Resets the money in the original moneybar, Do not remove!
UpdateMoneyBar(i,GetPlayerCash(i));//Sets the money in the moneybar to the serverside cash, Do not remove!
new hack = GetPlayerMoney(i) - GetPlayerCash(i);
GetPlayerName(i,username,sizeof(username));
printf("%s has picked up/attempted to spawn $%d.", username,hack);
}
}
}
}