[Tutorial] Make your own SIMPLE anti-cheat system!
#1

Hi!
I'm bored, so I've decided to make a tutorial: How do you make your own SIMPLE anti-cheat system
This anti-cheat system includes:
- Anti Money Cheat
- Anti Weapon Cheat
It isn't supposed to use as an filterscript. It's recommended to use it in your gamemode (you need to integrate it -> Or you can make an include
Whatever. First we're gonna begin at the top of the script.
We only need the "a_samp" include (the standard stuff for PAWN scripting)
pawn Код:
#include <a_samp>
If you didn't know you must do that, I recommend you to learn scripting :P (TIP: https://sampforum.blast.hk/showthread.php?tid=177490 )
Whatever. We're gonna use the 'COLOR_RED' define (Just the red color for showing messages).
The code for it is: 0xFF0000AA (I am always using 'AA' at the end: It makes standard colors better). And whatever, you need to place that under #include <a_samp>:
pawn Код:
#define COLOR_RED 0xFF0000AA
Now we are gonna make the variable for the money cheat: pMoney[playerid]. The anti cheat system will work like this: If the player has more money then the string says, he'll be banned
Place the following code under the COLOR_RED define:
pawn Код:
new pMoney[MAX_PLAYERS];
Ok. That wasn't very hard, was it? (If it was hard, I really recommend you to learn scripting (A) )
So we now have: The a_samp include: Basic script stuff, the COLOR_RED define: for showing messages in red color, and the pMoney[playerid]: for the money cheat detector.
We're now gonna use the 'OnPlayerConnect' and the 'OnPlayerDisconnect' callbacks. This will only set the pMoney string of the player to '0'. This is to prevent eventually bugs (loosing connection)
pawn Код:
public OnPlayerConnect(playerid)
{
    pMoney[playerid] = 0;
    return 1;
}
public OnPlayerDisconnect(playerid) //Or: OnPlayerDisconnect(playerid, reason)
{
    pMoney[playerid] = 0;
    return 1;
}
That was easy... again!
And now there'll come one of the important things (everything was important... nvm)
We're gonna check if the player has more money then the string (money cheat!) (I'll do the anti weapon cheat later.. Just scroll down)
It seems like this: if("Money that the player currently has" "is more then" "the pMoney string") //Ban the player
To get the money that a player has, use: GetPlayerMoney(playerid);. For the 'Is more then' you use '>' . You will have this:
pawn Код:
if(GetPlayerMoney(playerid) > pMoney[playerid]) //Ban the player
And now.. Where to put it? In OnPlayerUpdate ofcourse! We don't use the laggy timers
The OnPlayerUpdate will detect updates of a player (switching weapon... getting less/more money.. etc...)
In the callback, we'll make a "string" again: pName[playerid]. This is for the player's name. And a 'string[128]' to show the message. Call the player name with: GetPlayerName(playerid, pName, MAX_PLAYER_NAME)
Here'll come the whole script:
pawn Код:
public OnPlayerUpdate(playerid) //The player changed something
{
    new pName[MAX_PLAYER_NAME], string[128]; //I already explained it. Too much explaination for one line
    if(GetPlayerMoney(playerid) > pMoney[playerid]) //The player has more money then the string says (more 'bout that later)
    {
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME); //Will get the player's name
        format(string, sizeof(string), "* %s has been banned: MONEY CHEAT", pName); //Format's a script: "* 'pName' has been banned: MONEY CHEAT"
        SendClientMessageToAll(COLOR_RED, string); //Send an message to ALL the active players with the formatted string: "* 'pName' has been banned: MONEY CHEAT" in an RED COLOR
        BanEx(playerid, "Money Cheat"); //Bans the player with the reason "Money Cheat"
    }
    return 1;
}
Easy :O
But about the pMoney[playerid]. Does this mean, when you use "GivePlayerMoney" that the player will be banned? The answer is: YES
That's why we aren't going to use "GivePlayerMoney". We're gonna make our own function: a_GivePlayerMoney.
What this function does: Give's the player money, and it will increase the 'money' in the string (just a number)
I'll give it:
pawn Код:
stock a_GivePlayerMoney(playerid, money)
{
    pMoney[playerid] += money; //Will increase the string: "+="
    GivePlayerMoney(playerid, money); //Give's the player money... DUH :P Don't use "a_GivePlayerMoney" here.
}
I told you it was easy! And simple. That's why the topic's title is: ~~~ own SIMPLE ~~~
You can make your own a_SetPlayerMoney of course. Here it is:
pawn Код:
stock a_SetPlayerMoney(playerid, money)
{
    pMoney[playerid] = money; //Will set the string to the money ammount
    ResetPlayerMoney(playerid); //Reset's player money
    GivePlayerMoney(playerid); //Will give the player money. no a_GivePlayerMoney needed!
}
That was the anti money cheat system!
Now the anti weapon cheat system! [b]NOTE: You need to give your own forbidden weapon ID's. I only'll forbid the minigun, the RPG and the heatseeking RPG
We already have the "#include <a_samp>" and the "#define COLOR_RED 0xFF0000AA".
We are gonna make a array string, with the weapon ID's you don't want ingame!
pawn Код:
new ForbiddenWeapons[][] = {
38, //Minigun
35, //RPG
36 //Heatseeking RPG
};
Eaaasy
Now we only need the "OnPlayerUpdate". We still have got the 'pName' and the 'string'. We are gonna make an 'w' too : 'new w = 0;'. That's all
What we're gonna do is the next: We are gonna look if the player got a weapon ID that is in the 'ForbiddenWeapons' array. We're gonna use the function while: while(w < (sizeof(ForbiddenWeapons))){
That's not all. We need to check if the player've got a weapon ID from it, using 'GetPlayerWeapon'. If the weapon ID is "w" the player will be banned.
Here it is:
pawn Код:
public OnPlayerUpdate(playerid)
{
    new w = 0;
    while(w < (sizeof(ForbiddenWeapons))){ //Loop through the weapon ID's in the ForbiddenWeapons array
        if(GetPlayerWeapon(playerid) == w){ //Does the player has a wapon that's in the array? Then...
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);  //Get player name
        format(string, sizeof(string), "* %s has been banned: WEAPON CHEAT", pName); //Format's a script: "* 'pName' has been banned: WEAPON CHEAT"
        SendClientMessageToAll(COLOR_RED, string); //Send an message to ALL the active players with the formatted string: "* 'pName' has been banned: WEAPON CHEAT" in an RED COLOR
        BanEx(playerid, "Weapon Cheat"); //Bans the player with the reason "Weapon Cheat"
    }
    return 1;
}
And that was the anti weapon cheat script! You can make it MUCH better of course, but this is just a basic.
Now, here's the whole script, it should look like this (without the comments)
pawn Код:
#include <a_samp>

#define COLOR_RED 0xFF0000AA

new pMoney[MAX_PLAYERS];
new ForbiddenWeapons[][] = {
38,
35,
36
};

public OnPlayerConnect(playerid)
{
    pMoney[playerid] = 0;
    return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
    pMoney[playerid] = 0;
    return 1;
}
public OnPlayerUpdate(playerid)
{
    new pName[MAX_PLAYER_NAME],
        w = 0,
        string[128];
    if(GetPlayerMoney(playerid) > pMoney[playerid]){
        GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
        format(string, sizeof(string), "* %s has been banned: MONEY CHEAT", pName);
        SendClientMessageToAll(COLOR_RED, string);
        BanEx(playerid, "Money Cheat");
    }
    while(w < (sizeof(ForbiddenWeapons))){
        if(GetPlayerWeapon(playerid) == w){
            GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
            format(string, sizeof(string), "* %s has been banned: WEAPON CHEAT", pName);
            SendClientMessageToAll(COLOR_RED, string);
            BanEx(playerid, "Weapon Cheat");
        }
    }
    return 1;
}

stock a_GivePlayerMoney(playerid, money)
{
    pMoney[playerid] += money;
    GivePlayerMoney(playerid, money);
}
stock a_SetPlayerMoney(playerid, money)
{
    pMoney[playerid] = money;
    ResetPlayerMoney(playerid);
    GivePlayerMoney(playerid, money);
}
Good luck with it
Maybe I'll add more soon.

Kind Regards,
Kevin aka Kwarde
Reply
#2

very very nice detailed tutorial !
Reply
#3

nice Tutorial thanks!!
Reply
#4

Nice tutorial.
Reply
#5

good work
Reply
#6

Quote:
Originally Posted by Kwarde
Посмотреть сообщение
pawn Код:
new ForbiddenWeapons[][] = {
38,
35,
36
};
Did you test that DOUBLE array? [][] < that

Also, a suggestion for the a_GivePlayerMoney thingy:

pawn Код:
#define GivePlayerMoney a_GivePlayerMoney
#define SetPlayerMoney a_SetPlayerMoney
#define ResetPlayerMoney a_ResetPlayerMoney //If using it
Also some (possible) additions:
Basic health and armour hack, works like:
Quote:

Keep a variable that updates only when the player's HP gets higher by the script, like when he spawns or at SetPlayerHealth and stuff. Then check after some times if his HP is higher then the 'scripts' HP variable, and if it is, ban him. If it's lower then the script's variable, set the variable according to that HP.

Note that there's a high chance for this not working with HP, think about sprunk machines and crap. For armor, watch out for pickups and ammunations.

Jetpack hacking using OnPlayerStateChange, but beware of pickups yet again.

Speed hacks, thanks to GetVehicleVelocity pretty accurate. Stunting servers, don't try this.
Reply
#7

I've tested the DOUBLE array :P
I think... MY BAD! :P
But whatever,
ty all.
And I see there's already an anti-cheat tutorial -.-" - My bad again xD
Reply
#8

LOL , All Players Who have money or Weapon Will BANNED
Help ME
Reply
#9

Quote:
Originally Posted by Islam_Gerland_99
Посмотреть сообщение
LOL , All Players Who have money or Weapon Will BANNED
Help ME

If you have take 1 min to read it and not to copy/past you will notice that ban all player who have weapons
Reply
#10

Nice tutorial
Reply


Forum Jump:


Users browsing this thread: 8 Guest(s)