10.09.2010, 10:46
(
Последний раз редактировалось wups; 26.12.2010 в 07:18.
)
Hello, i want to share a gun anti cheat, that i use on my server.
The code works like this: If someone get's a weapon serverside, the server registers the player, that he HAS the weapon. And when he fires it, if the weapon is not registered - he gets banned.
If anyone wan'ts to save 100kb of memory, use the ****** include, and compile it like this.
Remember now allways to use GivePlayerWeaponEx function instead off the GivePlayerWeapon function.
This is not perfect, as you can make ammo etc., but it bans the cheaters who come to server and cheat instantly( what most of them do).
Credits: Wups!
Please don't PM me, ask in this thread if you want.
NOTE: You must dissable amunation shops.
Edit: lowered cells, fixed guns from vehicles, small optimization.
P.S. This won't work if you use ammunation shops or give weapons for player classes!
The code works like this: If someone get's a weapon serverside, the server registers the player, that he HAS the weapon. And when he fires it, if the weapon is not registered - he gets banned.
NO FAKE BANS, ONLY BANS CHEATERS. TESTED 100%.
pawn Код:
#include <a_samp>
new bool:PlayerWeapons[MAX_PLAYERS][47],bool:Spawned[MAX_PLAYERS];
// On top
public OnPlayerConnect(playerid)
{
for(new i=0;i<47;i++) PlayerWeapons[playerid][i]=false; // clears the value
Spawned[playerid]=false;
return 1;
}
public OnPlayerSpawn(playerid)
{
SetTimerEx("RealSpawn",500,false,"i",playerid);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
new model = GetVehicleModel(GetPlayerVehicleID(playerid));
switch(model)
{
case 592,577,511,512,520,593,553,476,519,460,513,548,425,417,487,488,497,563,447,469: PlayerWeapons[playerid][46]=true;
case 457: PlayerWeapons[playerid][2]=true;
case 596,597,598,599: PlayerWeapons[playerid][25]=true;
}
}
}
forward RealSpawn(playerid);
public RealSpawn(playerid)
{
Spawned[playerid]=true;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_FIRE)
{
if(Spawned[playerid])
{
new weapon = GetPlayerWeapon(playerid);
if(weapon != 0 && !PlayerWeapons[playerid][weapon] && weapon != 40) // if weapon is not fists, and weapon is not a remote control.
BanEx(playerid,"GUN HACKS");
}
}
}
stock GivePlayerWeaponEx(playerid,weaponid,ammo)
{
PlayerWeapons[playerid][weaponid]=true; // Player Has the weapon.
GivePlayerWeapon(playerid,weaponid,ammo); // To realy give him the weapon.
}
pawn Код:
#include <a_samp>
#include <YSI\y_bit>
new
BitArray:gPlayerWeapons[46]<MAX_PLAYERS>,
BitArray:gSpawned<MAX_PLAYERS>;
// On top
public OnPlayerConnect(playerid)
{
for(new i=0;i<47;i++) PlayerWeapons[playerid][i]=false; // clears the value
Bit_Set(gSpawned, playerid, false);
return 1;
}
public OnPlayerSpawn(playerid)
{
SetTimerEx("RealSpawn",500,false,"i",playerid);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
new model = GetVehicleModel(GetPlayerVehicleID(playerid));
switch(model)
{
case 592,577,511,512,520,593,553,476,519,460,513,548,425,417,487,488,497,563,447,469: Bit_Set(gPlayerWeapons[46], playerid, true);
case 457: Bit_Set(gPlayerWeapons[2], playerid, true);
case 596,597,598,599: Bit_Set(gPlayerWeapons[25], playerid, true);
}
}
}
forward RealSpawn(playerid);
public RealSpawn(playerid)
{
Bit_Set(gSpawned, playerid, true);
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys & KEY_FIRE)
{
if(Bit_Get(gSpawned, playerid))
{
new weapon = GetPlayerWeapon(playerid);
if(weapon != 0 && !Bit_Get(gPlayerWeapons[weapon], playerid) && weapon != 40) // if weapon is not fists, and weapon is not a remote control.
BanEx(playerid,"GUN HACKS");
}
}
}
stock GivePlayerWeaponEx(playerid,weaponid,ammo)
{
Bit_Set(gPlayerWeapons[weaponid], playerid, true);
GivePlayerWeapon(playerid,weaponid,ammo); // To realy give him the weapon.
}
Remember now allways to use GivePlayerWeaponEx function instead off the GivePlayerWeapon function.
This is not perfect, as you can make ammo etc., but it bans the cheaters who come to server and cheat instantly( what most of them do).
Credits: Wups!
Please don't PM me, ask in this thread if you want.
NOTE: You must dissable amunation shops.
Edit: lowered cells, fixed guns from vehicles, small optimization.
P.S. This won't work if you use ammunation shops or give weapons for player classes!