SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 23/02/2016, 03:47 PM   #1
pollo97
Big Clucker
 
pollo97's Avatar
 
Join Date: Sep 2011
Location: Italy
Posts: 83
Reputation: 4
Default Anticheat question

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.
Code:
        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.
pollo97 is offline   Reply With Quote
Old 23/02/2016, 04:01 PM   #2
K0P
Banned
 
Join Date: Nov 2015
Location: *.*.*.*
Posts: 597
Reputation: 87
Default Re: Anticheat question

This can work:-
Code:
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);
K0P is offline   Reply With Quote
Old 23/02/2016, 04:26 PM   #3
pollo97
Big Clucker
 
pollo97's Avatar
 
Join Date: Sep 2011
Location: Italy
Posts: 83
Reputation: 4
Default Re: Anticheat question

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?
pollo97 is offline   Reply With Quote
Old 23/02/2016, 10:52 PM   #4
AmigaBlizzard
Huge Clucker
 
Join Date: Jul 2012
Posts: 320
Reputation: 60
Default Re: Anticheat question

PHP Code:
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.
AmigaBlizzard is offline   Reply With Quote
Old 24/02/2016, 05:39 AM   #5
pollo97
Big Clucker
 
pollo97's Avatar
 
Join Date: Sep 2011
Location: Italy
Posts: 83
Reputation: 4
Default Re: Anticheat question

So i can use this way also for health,armour,weapon and invulnerability?
pollo97 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about Anticheat Blackazur Scripting Help 4 23/01/2013 02:03 PM
Question| AntiCheat _DownLoaD_ Scripting Help 1 01/03/2012 07:23 PM
Question about Anticheat titanak Help Archive 2 17/05/2010 02:54 AM
Best anticheat? ruckfules99 Help Archive 4 09/03/2010 05:23 AM
Need Help With My Anticheat BP13 Help Archive 10 22/12/2009 02:21 PM


All times are GMT. The time now is 05:18 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.