[Include] Perfect gun anti-cheat
#1

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.
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.
}
If anyone wan'ts to save 100kb of memory, use the ****** include, and compile it like this.
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!
Reply
#2

You could also expiriment with setting variables containing the player's ammo. Also: Reset their weapon variables when the player dies
Reply
#3

I tried the reseting thingy, but it was buggy. Maybe i need to set it with a timer eh? Bcz when i tried - when you die u automaticly get banned not even spawned.
Reply
#4

This need to be at lolo code..

Your script will ban everyone who will scroll the weapon ..
For example .. he gets Uzi and deagle in server right way, no cheating.
The variable sets to last given weapon ( for example tec ) he scrolls to deagle. and woot.. he gets banned.. .
Reply
#5

Quote:
Originally Posted by GaGlets®
Посмотреть сообщение
This need to be at lolo code..

Your script will ban everyone who will scroll the weapon ..
For example .. he gets Uzi and deagle in server right way, no cheating.
The variable sets to last given weapon ( for example tec ) he scrolls to deagle. and woot.. he gets banned.. .
Nop thats not true. If it was PlayerWeapons[playerid] == UZI , then that would be true. But now it is saved in a value. Study better.
Quote:
Originally Posted by ******
Посмотреть сообщение
This bans people who buy weapons from ammunation!
Yes, you MUST NOT USE AMUNATION SHOPS!
Reply
#6

This bans people, who get out of a helicopter, because when they get out of a heli or plane, they get parachute...
Reply
#7

Quote:
Originally Posted by sushihusi
Посмотреть сообщение
This bans people, who get out of a helicopter, because when they get out of a heli or plane, they get parachute...
Fixed...
Reply
#8

Sorry, i didnt have time to check how many weapons are there, and i left it like that. Now its changed. Also i fixed the parachute bug(i dont think anyone spawns parachutes anyway). Maybe it's not perfect, but show my a better gun anti cheat? Wait. I can change it to title "Best gun anti cheat", if its better for you.
Reply
#9

Quote:
Originally Posted by wups
Посмотреть сообщение
Sorry, i didnt have time to check how many weapons are there, and i left it like that. Now its changed. Also i fixed the parachute bug(i dont think anyone spawns parachutes anyway). Maybe it's not perfect, but show my a better gun anti cheat? Wait. I can change it to title "Best gun anti cheat", if its better for you.
At least make use of ******'s foreach !
Reply
#10

Quote:
Originally Posted by Hal
Посмотреть сообщение
At least make use of ******'s foreach !
Where should i use it?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)