SA-MP Forums Archive
Anticheat question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Anticheat question (/showthread.php?tid=601596)



Anticheat question - pollo97 - 23.02.2016

Hi, what is the best way to create an anticheat?
Because i know there is some issue about the client lag during PlayerUpdate.

This on OnPlayerUpdate.
Код:
        if(PlayerData[playerid][pMoney]<GetPlayerMoney(playerid))
	{
		if(!CheatGivingMoney[playerid])
		{
			GivePlayerMoney(playerid,PlayerData[playerid][pMoney]-GetPlayerMoney(playerid));
			AccountBan(playerid);
		}
		else
		{
			CheatGivingMoney[playerid]=false;
		}
		PlayerData[playerid][pMoney]=GetPlayerMoney(playerid);
	}
I would know if this is a good way to create an anticheat.


Re: Anticheat question - K0P - 23.02.2016

This can work:-
Код:
if(PlayerData[playerid][pMoney] != GetPlayerMoney(playerid))
{
    GivePlayerMoney(playerid,PlayerData[playerid][pMoney]);
    AccountBan(playerid);
    CheatGivingMoney[playerid] = 0;
}
else CheatGivingMoney[playerid] = 1;
PlayerData[playerid][pMoney] = GetPlayerMoney(playerid);



Re: Anticheat question - pollo97 - 23.02.2016

My code works, there isn't a problem of code logic.
The question is if this anticheat (that check the differents of money on the PlayerUpdate callback) is a good way to punish the cheater; keeping in mind that there is some lag client issue.
So this method is working every time, also if the player have connection problem?


Re: Anticheat question - AmigaBlizzard - 23.02.2016

PHP код:
public OnGameModeInit()
{
    
SetTimer("MoneyTimer"1000true);
    return 
1;
}
forward MoneyTimer();
public 
MoneyTimer()
{
    for (new 
playeridplayerid MAX_PLAYERSplayerid++)
    {
        if (
IsPlayerConnected(playerid))
        {
            
// Update the player's money on the client with the value stoed on the server
            
ResetPlayerMoney(playerid);
            
GivePlayerMoney(playeridPlayerData[playerid][pMoney]);
        }
    }
    return 
1;

Why make it difficult?
Just use a timer with interval of 1 second and let that timer update the client's money with the value stored on the server.

Why even check if the player is cheating? When you have server-sided money, that cheat is useless anyway.

If your script uses the value stored on the server to buy anything on your server, they can cheat as much as they want and get nowhere.

Even if they manage to freeze the displayed money on their client and set it to $2 billion, your server knows they only have $1000 for example.
Your script won't let them buy something that's being sold for $150000.
It would be funny to have $2 billion on their screen and they wanna buy a house worth $150000 and they get the message: "you don't have enough money". Because the server only holds $1000 in their account.

They will only fool themselves by displaying fake money on their own screen.
Never use GetPlayerMoney and you'll be fine.

And using OnPlayerUpdate for such a thing is overkill.


Re: Anticheat question - pollo97 - 24.02.2016

So i can use this way also for health,armour,weapon and invulnerability?