[Tutorial] Making a working Anti - Jetpack system
#1

Introduction

I have decided to make a working and non bugged Anti jetpack system. There are already a few out there but they mostly use OnPlayerUpdate which continues to run forever.





Lets start

We are going to start off by adding a timer variable to the top of our script, this will allow us to Kill the timer once the player has been kicked/banned

pawn Код:
new CheatingTimer[MAX_PLAYERS];
__________________________________________________ ____________________________________________

Now we are going to start the timer when the player connects so it can detect if they are using a jetpack. So under OnPlayerConnect,

pawn Код:
CheatingTimer[ playerid ] = SetTimerEx( "AntiCheat", 100, true, "i", playerid);
The true means that the timer will not stop after 100 milliseconds have passed. We have assigned the Timer to the playerid when they connect to the server

__________________________________________________ ____________________________________________
We will now create a callback which is linked to the timer, 'AntiCheat'. So somewhere in your script you want to forward your callback and use it. Just like this,

pawn Код:
forward AntiCheat( playerid );
public AntiCheat( playerid )
{
    if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_USEJETPACK) // This will detect if the player is using a jetpack
    {
    }
}

__________________________________________________ ____________________________________________

In this callback, we are going to want to ban/kick the player and then kill the timer so it does not continue to run,

pawn Код:
forward AntiCheat( playerid );
public AntiCheat( playerid )
{
    if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_USEJETPACK)
    {
        // Add your messages here
        Ban(playerid);
        KillTimer(CheatingTimer[playerid]);
    }
}


IMPORTANT: If you are thinking of using messages in your ban, remember to use a timer to ban the player around a second after the message has been sent.

If you do not kill the timer after the player has been banned, then it will continue to check if the player is using the jetpack. If you have added a message to send to everyone that the player has been banned, it will flood the chat with the message because it is still noticing that the player is using a jetpack.

Also, when using a MySQL Database to insert the ban, it will flood your database with many bans.

The reason I have not used OnPlayerUpdate is because the callback continues to run forever, and it cannot be stopped. So using a timer and then killing the timer after the player has been banned is a better idea.

I hope I have made this clear for you, Thanks.
Reply
#2

nice
Reply
#3

Good job nice
Reply
#4

Nice.
Reply
#5

I spotted a bug.
You don't kill the timer when the player normally disconnects (OnPlayerDisconnect) by exiting the game, your timer keeps on running for that disconnected player.
If another player connects with the same playerid, there are 2 timers running for that player.
After some time, you've got hundreds of timers running on all players.

It's better to move the KillTimer statement to OnPlayerDisconnect, as that callback also gets called when you ban a player.

Why shouldn't you use OnPlayerUpdate?
That callback only runs for the connected players, so if he's kicked/banned or just leaves, that callback won't be called until the next player connects on that playerid.
No need to create timers and the possible mistake of NOT killing the timer when he disconnects.

Taken from the SAMP wiki:
"This callback is called everytime a client/player updates the server with their status."

A player cannot send updates to the server if he's disconnected, so your server won't get spammed with multiple messages or whatever you do if the jetpack is detected.

For such a simple thing, you could still use OnPlayerUpdate.
Reply
#6

100ms is WAY TOO FAST.
1 second would be good enough.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)