[Tutorial] How to make a simple anti-weapon-hack (no silly timers)
#1

Hello,this is not my first tutorial.

In this,i'll explain how to setup and code a small (but efficient) anti weapon hack in simple steps!

Please note that ALL the lines wrote here,are commented so you can except the maximum understand of the FULL code.

This small anticheat doesn't use ANY timers or OnPlayerUpdate.

So,let's start.

First step is to add a custom stock in our gamemode:

pawn Код:
stock ForbiddenWeap(playerid) // ForbiddenWeap will be called for our small anticheat.
{
    new weap = GetPlayerWeapon(playerid); // GetPlayerWeapon is to get the currently weapon of the player.
    if( weap == 36 || weap == 37 || weap == 38 || weap == 38 || weap == 41 || weap == 42 || weap == 43 || weap == 44 || weap == 45 || weap == 46) // This are the FORBIDDEN weapon (s) ID (s)
    {
     return true; // return true = A player has ONE or MORE of this weapons in hand.
    }
    return false; // else he's clean.
}
Simply uh?First step is done,let's move to the second and last step.

Move to OnPlayerKeyStateChange and paste this code. This callback is called when a player press FIRE or RELEASE button.

pawn Код:
if(newkeys & KEY_FIRE && ForbiddenWeap(playerid)) // We define KEY_FIRE (used to shoot) to check if player has forbidden weap - ForbiddenWeap(playerid) is releated to the stock created earlier.
        {
            new weap, ammo; // Define currently holding weapon and ammo state.
            GetPlayerWeaponData(playerid, 7, weap, ammo); // Here we not define,the GetPlayerWeaponData will retrieve the info of the weapon (ammo and id).
            new pname[MAX_PLAYER_NAME]; // Create a new to store the player name.
            new string[170]; // Create a new string.
            GetPlayerName(playerid, pname, sizeof(pname)); // Here we get the player name with the "new pname" used above.
            format(string, sizeof(string), "AC: %s has been banned - Forbidden weapon (%s) with %d ammo.", pname,weap,ammo); // We format the string,we send the anticheat message with some values: Name of the player,weapon name and ammo.Ex: Test has been banned.Forbidden Weap: RPG with 90 ammo.
            SendClientMessageToAll(0xffffffff,string); // We send the string created at all online players.
            BanEx(playerid,string); // We ban the player.I used BanEx to insert the string in the ban file.
            return 1; // Return 1,player has been banned.
        }
And we're done

Please remember this is a simple anticheat,with Pawn you can do things much complex than this.
Reply
#2

Really nice but you could do a more explaining, 8/10.
Well if you use timers, it will detect if you have the weapon in your hand. With your code it looks like if you shoot it will ban the player. Well you can also use OnPlayerUpdate like i did on my tutorial for anti weapon hack. If you use OnPlayerUpdate, it will still ban the player if they have it holding.
Reply
#3

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
Really nice but you could do a more explaining, 8/10.
Well if you use timers, it will detect if you have the weapon in your hand. With your code it looks like if you shoot it will ban the player. Well you can also use OnPlayerUpdate like i did on my tutorial for anti weapon hack. If you use OnPlayerUpdate, it will still ban the player if they have it holding.
Thanks.

I don't like timers for anticheat so i made with KeyStateChange,it works differently but it works (:

Checking if player has forbidden weapon in hand with timers,or using KeyStateChange when shoot with the forbidden wep,it's the same thing.
Reply
#4

seems nice. but he can be with a minigun walking around like "haters gonna hate"
Reply
#5

Nice work.

I actually prefer the timer method.
Reply
#6

Quote:
Originally Posted by Nicholas.
Посмотреть сообщение
Nice work.

I actually prefer the timer method.
Thanks.

Quote:
Originally Posted by AlExAlExAlEx
Посмотреть сообщение
Yeah, he can't fire it but he can keep it in hand.
I'm sure he will fire,lol.

Quote:
Originally Posted by emokidx111
Посмотреть сообщение
seems nice. but he can be with a minigun walking around like "haters gonna hate"
LOL,every cheater in 99% of cases,when they spawn a weapon,they shoot.
Reply
#7

Quote:
Originally Posted by emokidx111
Посмотреть сообщение
seems nice. but he can be with a minigun walking around like "haters gonna hate"
Actually ^^. The person will start acting like a boss with a minigun . Also if he shoots with minigun, it could be possible that a little bit ammo will be shot before he gets banned so if the person attempts to shoot someone, he will shoot very less amount of ammo then get banned.
Reply
#8

Sorry to bump a really old topic but i have a command that pops a dialog asking what gun i want if one of the guns i want are them ID's and i spawn it will i get banned if so how can i stop this ?
Reply
#9

I should be in credits, this is why

https://sampforum.blast.hk/showthread.php?tid=322484

Stolen
Reply
#10

Quote:
Originally Posted by Unknownich
Посмотреть сообщение
I should be in credits, this is why

https://sampforum.blast.hk/showthread.php?tid=322484
just wanted to say that

everything is same
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)