20.02.2012, 13:09
(
Последний раз редактировалось Deduction; 20.02.2012 в 19:17.
)
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?: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.
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.