Simple Anticheat Check not working
#1

here is my whole code.

pawn Code:
#include <a_samp>
#include <IsPlayerLadmin>

new timer;
new bool: ADMIN[MAX_PLAYERS];
new bool: ADMIN2[MAX_PLAYERS];

public OnFilterScriptInit()
{
  timer = SetTimer("AntiCheat",5000,true);
    print("Cheat Extinguisher by [SU]BP13 loaded");
    return 1;
}

public OnFilterScriptExit()
{
    KillTimer(timer);
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    if(IsPlayerLAdmin(playerid))
    {
    ADMIN[playerid] = true;
    ADMIN2[playerid] = true;
    }
    return 1;
}

public OnPlayerDisconnect(playerid)
{
  ADMIN[playerid] = false;
  ADMIN2[playerid] = false;
  return 1;
}

forward AntiCheat();
public AntiCheat()
{
    new weap, ammo;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
      if(ADMIN[i] == false)
      {
            GetPlayerWeaponData(i, 9, weap, ammo); //Slot 9
            if(ammo > 1 && weap == 42) //Weapon ID 42
            {
                new string [128];
                new pName[MAX_PLAYER_NAME];
                GetPlayerName(i, pName, sizeof(pName));
                format(string, sizeof(string), "BANNED: %s has been auto banned by console.", pName);
                SendClientMessageToAll(0xFF0000FF, string);
                BanEx(i, "AntiCheat");
            }
        }
        else if(ADMIN2[i] == false) //Not banning for brass nuckles (ID 1)
      {
            GetPlayerWeaponData(i, 0, weap, ammo); //Slot 0
            if(ammo > 1 && weap == 1) //Weapon ID 1
            {
                new string [128];
                new pName[MAX_PLAYER_NAME];
                GetPlayerName(i, pName, sizeof(pName));
                format(string, sizeof(string), "BANNED: %s has been auto banned by console.", pName);
                SendClientMessageToAll(0xFF0000FF, string);
                BanEx(i, "AntiCheat");
            }
        }
    }
    return 1;
}
Reply
#2

If its using to check if they have weapons why not just make the code simpler and just use:

pawn Code:
if(GetPlayerWeapon(i) == weaponid)
  {
    if(GetPlayerAmmo(i) > 0)
    {
      // Code here...
    }
  }
Then you would follow the pattern with:

pawn Code:
if(GetPlayerWeapon(i) == weaponid)
  {
    if(GetPlayerAmmo(i) > 0)
    {
      // Code here...
    }
  }
  else if(GetPlayerWeapon(i) == weaponid)
  {
    if(GetPlayerAmmo(i) > 0)
    {
      // Code here...
    }
  }
But if its just to check weapons, I recommend using OnPlayerUpdate, its commonly known to be used for Anti Cheats.
Reply
#3

Could this work? Do I even need the ammo part because I really don't care how much ammo they have in their guns.

pawn Code:
forward AntiCheat();
public AntiCheat()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
      if(ADMIN[i] == false && GetPlayerWeapon(i) == 42)
      {
            new string [128];
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(i, pName, sizeof(pName));
            format(string, sizeof(string), "BANNED: %s has been auto banned by console.", pName);
            SendClientMessageToAll(0xFF0000FF, string);
            BanEx(i, "AntiCheat");
        }
        else if(ADMIN2[i] == false && GetPlayerWeapon(i) == 1)
      {
            new string [128];
            new pName[MAX_PLAYER_NAME];
            GetPlayerName(i, pName, sizeof(pName));
            format(string, sizeof(string), "BANNED: %s has been auto banned by console.", pName);
            SendClientMessageToAll(0xFF0000FF, string);
            BanEx(i, "AntiCheat");
        }
    }
    return 1;
}
Reply
#4

Id rather do it like this:

pawn Code:
public AntiCheat()
{
  for(new i = 0; i < MAX_PLAYERS; i++)
  {
    if(ADMIN[i] == false)
    {
      if(GetPlayerWeapon(i) == 42)
      {
        new string [128];
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, sizeof(pName));
        format(string, sizeof(string), "BANNED: %s has been auto banned by console.", pName);
        SendClientMessageToAll(0xFF0000FF, string);
        BanEx(i, "AntiCheat");
      }
      else if(GetPlayerWeapon(i) == 1)
      {
        new string [128];
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(i, pName, sizeof(pName));
        format(string, sizeof(string), "BANNED: %s has been auto banned by console.", pName);
        SendClientMessageToAll(0xFF0000FF, string);
        BanEx(i, "AntiCheat");
      }
    }
  }
  return 1;
}
Reply
#5

Quote:
Originally Posted by FreshKilla [PR-RP
]
If its using to check if they have weapons why not just make the code simpler and just use:

pawn Code:
if(GetPlayerWeapon(i) == weaponid)
  {
    if(GetPlayerAmmo(i) > 0)
    {
      // Code here...
    }
  }
Then you would follow the pattern with:

pawn Code:
if(GetPlayerWeapon(i) == weaponid)
  {
    if(GetPlayerAmmo(i) > 0)
    {
      // Code here...
    }
  }
  else if(GetPlayerWeapon(i) == weaponid)
  {
    if(GetPlayerAmmo(i) > 0)
    {
      // Code here...
    }
  }
But if its just to check weapons, I recommend using OnPlayerUpdate, its commonly known to be used for Anti Cheats.
I don't really understand whats happening here. I join as a admin and I am free to use the forbidden guns. Then I join as a non admin and then get auto-banned right after I connect?
Reply
#6

Very nice tutorial tnx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)