How to make a simple anti-weapon-hack. |
Hello,this is my 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:
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.
And we're done
Please remember this is a simple anticheat,with Pawn you can do things much complex than this.
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:
Code:
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.
Code:
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.
Post a Comment