13.04.2018, 14:00
I am using server - side money. When a player dies, I want to give him his $100 back but the code is detecting it as a hack. I want to restore the player's money on death.
My code:
My code:
PHP код:
public OnGameModeInit()
{
moneychecktimer = SetTimer("MoneyHackChecker", 1000, 1);
return 1;
}
PHP код:
public OnPlayerConnect(playerid)
{
SafeResetPlayerMoney(playerid);
return 1;
}
PHP код:
public OnGameModeExit()
{
KillTimer(moneychecktimer);
return 1;
}
PHP код:
public SafeGivePlayerMoney(playerid, money)
{
Player[playerid][pCash] += money;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, Player[playerid][pCash]);
return 1;
}
public SafeSetPlayerMoney(playerid, money)
{
Player[playerid][pCash] = money;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, Player[playerid][pCash]);
return 1;
}
public SafeResetPlayerMoney(playerid)
{
Player[playerid][pCash] = 0;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, Player[playerid][pCash]);
return 1;
}
public SafeGetPlayerMoney(playerid) // Returns the server - side cash of the player
{
return Player[playerid][pCash];
}
PHP код:
public MoneyHackChecker() // Checks for money hack: checks if server - side and client - side money is equal or not and warns the user
{
new name[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if((SafeGetPlayerMoney(i) != GetPlayerMoney(i)))
{
new hackamount = GetPlayerMoney(i) - SafeGetPlayerMoney(i);
name = GetName(i);
printf("%s has used money hack for $%d.", name, hackamount);
ResetPlayerMoney(i); // Resets the money in the original moneybar, Do not remove!
GivePlayerMoney(i, SafeGetPlayerMoney(i)); // Sets the money in the moneybar to the serverside cash, Do not remove!
GameTextForPlayer(i, "~r~Hacking is not allowed. It may result in permanent ban.", 800, 1);
}
}
}
return 1;
}
PHP код:
public OnPlayerDeath(playerid, killerid, reason)
{
SafeGivePlayerMoney(playerid, 100);
return 1;
}