[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


Messages In This Thread
Deduction - Anti-Weapon Hack - by Deduction - 20.02.2012, 13:09
Re: Deduction - Anti-Weapon Hack - by Not Applicable - 20.02.2012, 13:13
Re: Deduction - Anti-Weapon Hack - by Kaperstone - 20.02.2012, 15:17
Re: Deduction - Anti-Weapon Hack - by Hoborific - 20.02.2012, 15:17
Re: Deduction - Anti-Weapon Hack - by emokidx - 20.02.2012, 17:04
Re: Deduction - Anti-Weapon Hack - by rati555 - 20.02.2012, 17:28
Re: Deduction - Anti-Weapon Hack - by Pooh7 - 20.02.2012, 20:34
Re: Deduction - Anti-Weapon Hack - by Hoborific - 21.02.2012, 04:30
Re: Deduction - Anti-Weapon Hack - by Deduction - 21.02.2012, 05:28
Re: Deduction - Anti-Weapon Hack - by Meisternuke - 21.02.2012, 06:30
Re: Deduction - Anti-Weapon Hack - by Deduction - 21.02.2012, 10:09
Re: Deduction - Anti-Weapon Hack - by KyleSmith - 21.02.2012, 10:11
Re: Deduction - Anti-Weapon Hack - by Jeffry - 21.02.2012, 16:05
Re: Deduction - Anti-Weapon Hack - by Deduction - 21.02.2012, 19:33
Re: Deduction - Anti-Weapon Hack - by Jeffry - 22.02.2012, 10:05
Re: Deduction - Anti-Weapon Hack - by BaubaS - 22.02.2012, 12:03
Re: Deduction - Anti-Weapon Hack - by niyaz - 28.02.2012, 08:10
Re: Deduction - Anti-Weapon Hack - by gcw - 28.06.2012, 10:36
Re: Deduction - Anti-Weapon Hack - by ErzaNatsu - 30.06.2012, 00:59
Re: Deduction - Anti-Weapon Hack - by ilijas - 02.07.2012, 20:51
Re: Deduction - Anti-Weapon Hack - by ilijas - 03.07.2012, 11:30
Re: Deduction - Anti-Weapon Hack - by czop1223 - 23.04.2013, 14:52
Re: Deduction - Anti-Weapon Hack - by dEcooR - 14.06.2013, 16:00
Re: Deduction - Anti-Weapon Hack - by cyber_punk - 15.06.2013, 03:58
Re: Deduction - Anti-Weapon Hack - by Chrillzen - 18.10.2013, 20:23
Respuesta: Deduction - Anti-Weapon Hack - by Nitrome - 22.10.2013, 15:14
Re: Deduction - Anti-Weapon Hack - by cessil - 03.12.2013, 22:52
Re: Deduction - Anti-Weapon Hack - by Gastro - 04.12.2013, 01:18

Forum Jump:


Users browsing this thread: 2 Guest(s)