Issue with anticheat
#1

Hi all, I have a problem when testing my anticheat. Sometimes (few times happens), when I give a weapon to a player ingame (at moment I have only tested locally with me), the anticheat removes that weapon. Currently, my weapon check functions are these.

This one is inside a 1second timer:
pawn Код:
for(new slot = 0; slot < 13; slot++)
    {
        new weapon, bullets;
        GetPlayerWeaponData(playerid, slot, weapon, bullets);
        if(weapon!= 0 && weapon!= 46)
        {
            if(weapon!= PlayerInfo[playerid][pWeapons][slot] || weapon> PlayerInfo[playerid][pBullets][slot])
            {
                format(textArray, sizeof(textArray), "[ANTICHEAT ID:%d]: Player %s has spawned weapons.", playerid, PlayerInfo[playerid][pName]);
                SendClientMessageToAll(COLOR_RED, textArray);
                break;
            }
            else PlayerInfo[playerid][pBullets][slot] = bullets;
        }
    }
And the function to give a weapon to a player, would be this:
pawn Код:
GiveRealWeapon(playerid, weapon, bullets)
{
    new slot = GetWeaponSlot(weapon);
    if(PlayerInfo[playerid][pWeapons][slot] != 0)
    {
        if(3 <= slot <= 5 || weapon == PlayerInfo[playerid][pWeapons][slot]) PlayerInfo[playerid][pBullets][slot] += bullets;
        else PlayerInfo[playerid][pBullets][slot] = bullets;
        PlayerInfo[playerid][pWeapons][slot] = weapon;
    }
    else
    {
        PlayerInfo[playerid][pWeapons][slot] = weapon;
        PlayerInfo[playerid][pBullets][slot] = bullets;
    }
    GivePlayerWeapon(playerid, weapon, bullets);
    return 1;
}
Seeing that it gives false positives with this function, I decided to make a double check of the bullets correctly adding to the "PlayerInfo[playerid][pBullets][slot]" array, so I tried this one:

pawn Код:
GiveRealWeapon(playerid, weapon, bullets)
{
    new slot = GetWeaponSlot(weapon);
    new currentBullets = PlayerInfo[playerid][pBalas][slot];
    if(PlayerInfo[playerid][pWeapons][slot] != 0)
    {
        if(3 <= slot <= 5 || weapon == PlayerInfo[playerid][pWeapons][slot]) PlayerInfo[playerid][pBullets][slot] += bullets;
        else PlayerInfo[playerid][pBullets][slot] = bullets;
        PlayerInfo[playerid][pWeapons][slot] = weapon;
    }
    else
    {
        PlayerInfo[playerid][pWeapons][slot] = weapon;
        PlayerInfo[playerid][pBullets][slot] = bullets;
    }
    if(PlayerInfo[playerid][pBullets][slot] == currentBullets && bullets != 0) GiveRealWeapon(playerid, weapon, bullets);
    else GivePlayerWeapon(playerid, weapon, bullets);
    return 1;
}
But this isn't a right solution, as it keeps giving false positives and removes the weapon from the player. Any idea of what could be happening?

Thanks.
Reply
#2

This should work, if it doesn't, try creating a per player variable and check on anti-cheat if it is safety or not

pawn Код:
GiveRealWeapon(playerid, weapon, bullets)
{
    new slot = GetWeaponSlot(weapon);
    if(PlayerInfo[playerid][pWeapons][slot] != 0)
    {
        if(3 <= slot <= 5 || weapon == PlayerInfo[playerid][pWeapons][slot]) PlayerInfo[playerid][pBullets][slot] += bullets;
        else PlayerInfo[playerid][pBullets][slot] = bullets;
        PlayerInfo[playerid][pWeapons][slot] = weapon;
    }
    else
    {
        PlayerInfo[playerid][pWeapons][slot] = weapon;
        PlayerInfo[playerid][pBullets][slot] = bullets;
    }
    return GivePlayerWeapon(playerid, weapon, bullets);
}
EDIT
If that doesn't work, try this.

pawn Код:
//Per Player Variable/Array
new
    bool:RealWeapon[ MAX_PLAYERS ];

//Function
GiveRealWeapon(playerid, weapon, bullets)
{
    new slot = GetWeaponSlot(weapon);
    if(PlayerInfo[playerid][pWeapons][slot] != 0)
    {
        if(3 <= slot <= 5 || weapon == PlayerInfo[playerid][pWeapons][slot]) PlayerInfo[playerid][pBullets][slot] += bullets;
        else PlayerInfo[playerid][pBullets][slot] = bullets;
        PlayerInfo[playerid][pWeapons][slot] = weapon;
    }
    else
    {
        PlayerInfo[playerid][pWeapons][slot] = weapon;
        PlayerInfo[playerid][pBullets][slot] = bullets;
    }
    GivePlayerWeapon(playerid, weapon, bullets);
    return RealWeapon[playerid] = true;
}

//Anti Cheat
for(new slot = 0; slot < 13; slot++)
{
    new weapon, bullets;
    GetPlayerWeaponData(playerid, slot, weapon, bullets);
    if(weapon != 0 && weapon!= 46 && RealWeapon[playerid] == false)
    {
        if(weapon!= PlayerInfo[playerid][pWeapons][slot] || weapon> PlayerInfo[playerid][pBullets][slot])
        {
            format(textArray, sizeof(textArray), "[ANTICHEAT ID:%d]: Player %s has spawned weapons.", playerid, PlayerInfo[playerid][pName]);
            SendClientMessageToAll(COLOR_RED, textArray);
            break;
        }
        else PlayerInfo[playerid][pBullets][slot] = bullets;
    }
}
Reply
#3

None of those two works the 100% of the times, still having false positives.
Reply
#4

I printed the result to see clearly what happens and it showed this. The first value means "currentBullets" variable (the value of the array before updating it), the second one "bullets" variable, and the last one would be the array "PlayerInfo[playerid][pBullets][slot]":

pawn Код:
[20:26:45] 4050 bullets, 50 given, 4100 current
[20:26:46] 4100 bullets, 50 given, 4150 current
[20:26:46] 4150 bullets, 50 given, 4200 current
[20:26:47] 4200 bullets, 50 given, 4250 current
[20:26:50] 4250 bullets, 50 given, 4300 current
[20:26:51] 4300 bullets, 50 given, 4350 current
[20:26:52] 4350 bullets, 50 given, 4400 current
[20:26:53] 4400 bullets, 50 given, 4450 current
[20:26:54] 4450 bullets, 50 given, 4500 current
[20:26:54] 4500 bullets, 50 given, 4550 current
[20:26:55] 4550 bullets, 50 given, 4600 current
[20:26:55] 4600 bullets, 50 given, 4650 current
[20:26:56] 4650 bullets, 50 given, 4700 current
[20:26:56] 4700 bullets, 50 given, 4750 current
[20:26:57] 4750 bullets, 50 given, 4800 current
[20:26:58] 4800 bullets, 50 given, 4850 current
[20:26:58] 4850 bullets, 50 given, 4900 current
[20:26:59] 4850 bullets, 50 given, 4900 current -> Calls anticheat as it should have 4950 bullets in the weapon (called the function with a non updated array value
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)