[Tutorial] Deduction - Anti-Weapon Hack
#1

Learn how to make an Anti Weapon Hack System

Guaranteed to Ban Every single Weapon Hacker!
Only Scripted for Weapons

Welcome SA-MP Community, In this Tutorial I will teach you how to create a fair system which bans players who weapon hack on your servers.
How it works?:

This Script reads from enum Weapons which stores the Categories of the Weapons.
Within Grand Theft Auto, there are 11 Categories for Weapons, but we are only dealing with
9 Categories, since the other 2 are fairly harmless.

Each Category is sort into:

Melee
Thrown
Pistols
Shotguns
SubMachine
Assault
Rifles
Heavy
Handheld

The server checks the player for weapons OnPlayerUpdate to see if they match to the weapons on file in each of the categories, since you can't have twice of the weapons in the same category, it makes it much easier for us to store it in categories.

If Weapon is on file, it allows the player to use it as normal.

I won't add the code to reset the Categories, unless somebody needs it for OnPlayerDeath or something.

Ive created a Macro for when an admin is giving a weapon or somebody is recieving a weapon.
Instead of
pawn Код:
GivePlayerWeapon(playerid, weaponid, ammo);

It is now:
pawn Код:
ServerWeapon(playerid, weaponid);

This allows the weapon to now be serverside. Allowing the use of the weapon.


Code:

You will need to place this at the top of the script below
pawn Код:
#include <a_samp>

Like so,
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>

If you don't have ZCMD or SSCANF2 don't get too worried, it is only for testing the script just check at the bottom of this tutorial for references to the downloads of them.

Below the Includes, we need to add this bit of code:
pawn Код:
enum weapons
{
    Melee,
    Thrown,
    Pistols,
    Shotguns,
    SubMachine,
    Assault,
    Rifles,
    Heavy,
    Handheld,

}
new Weapons[MAX_PLAYERS][weapons];


These are the categories for all the weapons, every weapon will belong to one of those categories.

Now next we need to Add CheckWeapons to OnPlayerUpdate.
So Add it like this:
pawn Код:
public OnPlayerUpdate(playerid)
{
CheckWeapons(playerid);
return 1;
}


Now to add the Macros,
Why Macros you ask? Because they run faster then what Functions do.

So Now Adding the CheckWeapons Macro:
Add this at the bottom of the script.

pawn Код:
CheckWeapons(playerid)
{
    new weaponid = GetPlayerWeapon(playerid);//This will cause the "weaponid not defined" Error

    if(weaponid >= 1 && weaponid <= 15)
    {
        if(weaponid == Weapons[playerid][Melee])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }

        if( weaponid >= 16 && weaponid <= 18 || weaponid == 39 ) // Checking Thrown
    {
        if(weaponid == Weapons[playerid][Thrown])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }
    if( weaponid >= 22 && weaponid <= 24 ) // Checking Pistols
    {
        if(weaponid == Weapons[playerid][Pistols])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }

    if( weaponid >= 25 && weaponid <= 27 ) // Checking Shotguns
    {
        if(weaponid == Weapons[playerid][Shotguns])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }
    if( weaponid == 28 || weaponid == 29 || weaponid == 32 ) // Checking Sub Machine Guns
    {
        if(weaponid == Weapons[playerid][SubMachine])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }

    if( weaponid == 30 || weaponid == 31 ) // Checking Assault
    {
        if(weaponid == Weapons[playerid][Assault])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }

    if( weaponid == 33 || weaponid == 34 ) // Checking Rifles
    {
        if(weaponid == Weapons[playerid][Rifles])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }
    if( weaponid >= 35 && weaponid <= 38 ) // Checking Heavy
    {
        if(weaponid == Weapons[playerid][Heavy])
        {
        return 1;
        }
            else
            {
            SendClientMessage(playerid, 0xFF0000FF, "No Hacking!");
            Kick(playerid);
            }
    }
    else { return 1; }
   
return 1;
}


That code is what looks at the weapons on file, and if a weapons not on file that the player is carrying, then it will kick the player.

After that piece of code, we need to add the code to allow a player to be given a scripted weapon.
So below the last piece of code, add this:

pawn Код:
ServerWeapon(playerid, weaponid, ammo)
{
if(weaponid >= 1 && weaponid <= 15)
    {
    Weapons[playerid][Melee] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }

        if( weaponid >= 16 && weaponid <= 18 || weaponid == 39 ) // Checking Thrown
    {
    Weapons[playerid][Thrown] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }
    if( weaponid >= 22 && weaponid <= 24 ) // Checking Pistols
    {
    Weapons[playerid][Pistols] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }

    if( weaponid >= 25 && weaponid <= 27 ) // Checking Shotguns
    {
    Weapons[playerid][Shotguns] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }
    if( weaponid == 28 || weaponid == 29 || weaponid == 32 ) // Checking Sub Machine Guns
    {
    Weapons[playerid][SubMachine] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }

    if( weaponid == 30 || weaponid == 31 ) // Checking Assault
    {
    Weapons[playerid][Assault] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }

    if( weaponid == 33 || weaponid == 34 ) // Checking Rifles
    {
    Weapons[playerid][Rifles] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }
    if( weaponid >= 35 && weaponid <= 38 ) // Checking Heavy
    {
    Weapons[playerid][Heavy] = weaponid;
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
    }
return 1;
}


This basicly orders the weapon that you've been given into the category it belongs in.
And it gives you the weapon.

All you need to do now is the givegun command using the ServerWeapon Macro.
This is for testing purposes.

Place this in the script, anywhere, out of any functions or macros. anywhere below the includes:

pawn Код:
CMD:givegun(playerid, params[])
    {
            new PID; //
            if(sscanf(params, "i", weaponid)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /givegun [Weapon ID] [ammo]");
            ServerWeapon(playerid, weaponid, ammo);
            return 1;
    }


If you do use your own commands, don't forget to add ServerWeapon(playerid, weaponid, ammo);

Thats pretty much the basics, if you need to know how to reset them, just ask below.

Edits:

*Added Ammo
*More Attractive Look :P



References:

SSCANF2 - https://sampforum.blast.hk/showthread.php?tid=120356
ZCMD - https://sampforum.blast.hk/showthread.php?tid=91354

Thank you for reading, if you have any other question just ask below.
Reply
#2

Use dark colors for light background. The format is horrible.
Reply
#3

unqiue,nice
but mark that the Command isn't necessary to run the AWH (Anti-Weapon Hack)
mark that its for testing the AWH.
Reply
#4

go back to the orange, this blue makes me feel sick, other than that I see great optimisation, nice job.
Reply
#5

pawn Код:
new Weapons[playerid][weapons];
shouldn't this be
pawn Код:
new Weapons[MAX_PLAYERS][weapons];
and
pawn Код:
ServerWeapon(playerid, weaponid)
can this be changed to
pawn Код:
ServerWeapon(playerid, weaponid, ammo)
so that we can enter our own ammo, replacing the "9999"
Reply
#6

tested and works perfectly :P rep+
Reply
#7

This is actually really bad way of detecting weapon hackers.

You are checking weapons in OnPlayerUpdate. Man, it's really bad, because OnPlayerUpdate calls many times per second - it will make a big lag with more players.

Players can receive the shoutgun while they are in the Police Ranger, so your anticheat will detect them as hackers.
Reply
#8

Quote:
Originally Posted by Pooh7
Посмотреть сообщение
This is actually really bad way of detecting weapon hackers.

You are checking weapons in OnPlayerUpdate. Man, it's really bad, because OnPlayerUpdate calls many times per second - it will make a big lag with more players.

Players can receive the shoutgun while they are in the Police Ranger, so your anticheat will detect them as hackers.
I tested this on LAN, no shotgun was received from entering ANY police vehicle
Reply
#9

Quote:
Originally Posted by Pooh7
Посмотреть сообщение
This is actually really bad way of detecting weapon hackers.

You are checking weapons in OnPlayerUpdate. Man, it's really bad, because OnPlayerUpdate calls many times per second - it will make a big lag with more players.

Players can receive the shoutgun while they are in the Police Ranger, so your anticheat will detect them as hackers.
I didnt recieve a shotgun in any police vehicle, and if it were, all you need to do is check which vehicle a player is entering and then remove weapons they shouldnt have, and replace with weapons they should have.

Easy as that.
Reply
#10

when i exit a caddy, or exit a plane, i get weapons, does this detect them as cheatweapons?
Reply
#11

Well if its scripted into the server to give the player weapons within the script.
Instead of:
pawn Code:
GivePlayerWeapon(playerid, weaponid, ammo);
Use:
pawn Code:
ServerWeapon(playerid, weaponid, ammo);
Parachutes don't count as cheat weapons, a golfstick is, so maybe OnPlayerExitVehicle use this:

pawn Code:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(vehicleid == 457)
        {
        ResetPlayerWeaponsEx(playerid);
        }

    return 1;
}
Of course this will require another macro to restore all weapons.
So add in at the bottom of the script, this:
pawn Code:
ResetPlayerWeaponsEx(playerid)
{
ResetPlayerWeapons(playerid);
ServerWeapon(playerid, Weapons[playerid][Melee], 9999);
ServerWeapon(playerid, Weapons[playerid][Thrown], 9999);
ServerWeapon(playerid, Weapons[playerid][Pistols], 9999);
ServerWeapon(playerid, Weapons[playerid][Shotguns], 9999);
ServerWeapon(playerid, Weapons[playerid][SubMachine], 9999);
ServerWeapon(playerid, Weapons[playerid][Assault], 9999);
ServerWeapon(playerid, Weapons[playerid][Rifles], 9999);
ServerWeapon(playerid, Weapons[playerid][Heavy], 9999);
ServerWeapon(playerid, Weapons[playerid][Handheld], 9999);
return 1;
}
Reply
#12

Let's see what cessil anticheat master has to say about this.
Reply
#13

Interesting way, I like it. But two aspects you need to know:

1.) When one buy a weapon at the default Ammu Nation one will be banned.
2.) Picking weapon pickups placed with AddStaticPickup will also get one banned.

Both cases are when the weapon differs from the one you have. (For example AK47 gets replaced by M4).

If you do not use any Pickups and disable Interiors it should work fine. But maybe you can think for a fix of these two issues.
Reply
#14

Quote:
Originally Posted by Jeffry
View Post
Interesting way, I like it. But two aspects you need to know:

1.) When one buy a weapon at the default Ammu Nation one will be banned.
2.) Picking weapon pickups placed with AddStaticPickup will also get one banned.

Both cases are when the weapon differs from the one you have. (For example AK47 gets replaced by M4).

If you do not use any Pickups and disable Interiors it should work fine. But maybe you can think for a fix of these two issues.
Jeffry, Most servers don't allow the use of the default Ammu Nation because it is Clientside and not Serverside.
Aka even other AntiWeapon hacks cannot detect it, and if they could, anybody could hack inside of the ammunation.

Secondly, For picking up weapon pickups, you would need to Add a pickup meaning, when you pick it up, you'll need to script in what the pickup does, so instead of GivePlayerWeapon, put in ServerWeapon.

Its scripted in to the script so you won't get banned from weapons you have, if you have a different weapon, you obviously hacked it.
Because you cannot have an ak47 and a M4 at the same time, so if you use ServerWeapon for an AK47 then buy a M4 using same action/command, it WILL NOT ban you.
Reply
#15

Quote:
Originally Posted by Deduction
View Post
Jeffry, Most servers don't allow the use of the default Ammu Nation because it is Clientside and not Serverside.
Aka even other AntiWeapon hacks cannot detect it, and if they could, anybody could hack inside of the ammunation.
You are absolutely correct. But there is a (maybe) way to detect if the player has bought the weapons in the Ammu Nation. You could check when money goes down, position and facing angle (Angle is always set to a default value in every Ammu Nation) and then check which weapon has this cost and whether the user now has this weapon or not. Would take some time to collect all the weapons cost, but could work. Maybe it needs some other stuff to watch for, but whatever. ^^

Nevertheless, you will receive +Rep from me, because I really like the idea how you check for the weapons. Best Anti Weapon hack I've seen so far.
Reply
#16

Can be done way more easy.
Reply
#17

Thanks +rep
Reply
#18

Hello,
I know the thread is old but I have a question.
When I die I'll be banned because of weapons hack. I've done everything like in the tutorial. What can i do now?
Reply
#19

Nice !
Reply
#20

it dont work for me, i havent errors or warnings, but i can get any weapon i want with cheat
can you help me please
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)