Help in improving weapon anti cheat
#1

Here is my current Anti Cheat:
pawn Код:
public AntiCheat(playerid)
{
    if(IsPlayerConnected(playerid) && GetPVarInt(playerid, "LoggedIn") == 1)
    {
        new
            string[256];
           
        if(GetPlayerMoney(playerid) != Player[playerid][pMoney])
        {
            ResetPlayerMoney(playerid);
            GivePlayerMoney(playerid, Player[playerid][pMoney]);
        }
       
        if(!IsPlayerInAnyVehicle(playerid))
        {
            switch(GetPlayerWeapon(playerid))
            {
                case 0, 1:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][0])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 2 .. 9:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][1])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 22 .. 24:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][2])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 25 .. 27:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][3])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 28, 29, 32:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][4])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 30, 31:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][5])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 33, 34:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][6])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 35 .. 38:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][7])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 16, 17, 18, 39:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][8])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 41 .. 43:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][9])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 11 .. 15:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][10])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 44 .. 46:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][11])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
                case 40:
                {
                    if(GetPlayerWeapon(playerid) != Player[playerid][pWeapons][12])
                    {
                        SetPVarInt(playerid, "wep_hack_check", GetPVarInt(playerid, "wep_hack_check") + 1);
                       
                        if(GetPVarInt(playerid, "wep_hack_check") == 4)
                        {
                            format(string, sizeof string, "Weapon Hacking (%d)", GetPlayerWeapon(playerid));
                            SendClientMessage(playerid, Colour_White, string);
                            return 1;
                        }
                    }
                }
            }
        }
    }
    return 1;
}
It gets called every time OnPlayerUpdate is called but I feel that is a bad way in doing it as a player might be lagging and therefore get banned for something they didn't do. Could someone tell me what I could do to improve the reliability of my Anti Cheat.
Reply
#2

Use wups anticheat which he has published. It is pretty basic but solid weapon anticheat and only detects when weapon will be in use. To store weapons in savings system use your multi-d-array and getplayerweapon checks together like you have done above.

https://sampforum.blast.hk/showthread.php?tid=175558
Reply
#3

OnPlayerUpdate is a bad call I must agree, because it gets called 30 times in one second. I made a global timer (OnGameModeInIt) of 3 secs, so it checks every 3 seconds all the players. Wasn't lagging for me. If you see any lag you could easily increase it and have a few seconds of delay until the hacker gets called.


To avoid wrong people getting banned you can also make a check, for example, if is true, you set their check to 1 and then send warning to online admins, if checked again (reached 2) then you can ban them. However this might take a bit longer to actually get called.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)