SA-MP Forums Archive
Would this be a accurate anti-cheat? (Basic) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Would this be a accurate anti-cheat? (Basic) (/showthread.php?tid=426944)



Would this be a accurate anti-cheat? (Basic) - rangerxxll - 30.03.2013

So I've decided to try something new. I'm attempting to create a very basic anti-cheat.
Note: The armour one works fine, but the health one doesn't. I set my health to 200 in-game and don't get kicked.

Here's the code.
pawn Code:
public OnPlayerUpdate(playerid)
{
    new Float:hp;
    hp = GetPlayerHealth(playerid, hp);
    if(hp > 150 )
    {
        new string[128];
        format(string,sizeof(string), "[Urban Gaming] %s has been kicked for the following Hack. (Healh Hacks)");
        SendClientMessageToAll(COLOR_BRIGHTRED, string);
        Kick(playerid);
    }
    new Float:arm;
    hp = GetPlayerArmour(playerid, arm);
    if(arm > 150 )
    {
        new string[128];
        format(string,sizeof(string), "[Urban Gaming] %s has been kicked for the following Hack. (Armour Hacks)");
        SendClientMessageToAll(COLOR_BRIGHTRED, string);
        Kick(playerid);
    }
    return 1;
}
Would you guys recommend something like this?


Re: Would this be a accurate anti-cheat? (Basic) - Pawnie - 30.03.2013

OnPlayerUpdate calls everything that happens.

Try using something like this

Credits to Coole210
Code:
new AntiCheatTimer;
enum _ACInfo
{
    Float:Health, Float:Armour, Money,
}
new ACInfo[MAX_PLAYERS][_ACInfo];

#define GivePlayerMoney GivePlayerMoneyEx
#define SetPlayerHealth SetPlayerHealthEx
#define SetPlayerArmour SetPlayerArmourEx

public OnGameModeInit()
{
    AntiCheatTimer = SetTimer("AntiCheat",1000,true);
}

public OnGameModeExit()
{
    KillTimer(AntiCheatTimer);
}

forward AntiCheat();
public AntiCheat()
{
    new Float:HP,Float:AP,_Money=GetPlayerMoney(playerid);
    GetPlayerHealth(playerid,HP);
    GetPlayerArmour(playerid,AP);
    if(HP > ACInfo[playerid][Health])
    {
        //Gained health, he used cheats
    }
    else
    {
        ACInfo[playerid][Health] = HP; //If he lost health, set anti-cheat info health to current health
    }
    if(AP > ACInfo[playerid][Armour])
    {
        //Gained armour, he used cheats
    }
    else
    {
        ACInfo[playerid][Health] = HP; //If he lost armour, set anti-cheat info armour to current armour
    }
    if(_Money > ACInfo[playerid][Money])
    {
        //Gained health, he used hacks
    }
    else
    {
        ACInfo[playerid][Money] = _Money; //If he lost money, set anti-cheat info money to current money
    }
    return 1;
}
stock SetPlayerHealthEx(playerid, Float:HP)
{
    SetPlayerHealth(playerid, HP);
    ACInfo[playerid][Health] = HP;
    return 1;
}
stock SetPlayerArmourEx(playerid, Float:AP)
{
    SetPlayerArmour(playerid, AP);
    ACInfo[playerid][Armour] = AP;
    return 1;
}
stock GivePlayerMoneyEx(playerid, money)
{
    GivePlayerMoney(playerid, money);
    ACInfo[playerid][Money] += money;
    return 1;
}
Set a timer to check his HP etc.


Re: Would this be a accurate anti-cheat? (Basic) - Omirrow - 30.03.2013

hp = GetPlayerArmour(playerid);

but

if(arm > 150)


??


Re: Would this be a accurate anti-cheat? (Basic) - Pawnie - 30.03.2013

It still wouldnt help too much if you use it the way you are. Since if you set for example SetPlayerArmour inside the script he will get banned for hacks.


Re: Would this be a accurate anti-cheat? (Basic) - Omirrow - 30.03.2013

pawn Code:
public OnPlayerUpdate(playerid)
{
    new Float:hp;
    hp = GetPlayerHealth(playerid, hp);
    if(hp > 150 )
    {
        new string[128];
        format(string,sizeof(string), "[Urban Gaming] %s has been kicked for the following Hack. (Healh Hacks)");
        SendClientMessageToAll(COLOR_BRIGHTRED, string);
        Kick(playerid);
    }
    new Float:arm;
    arm = GetPlayerArmour(playerid, arm);
    if(arm > 150 )
    {
        new string[128];
        format(string,sizeof(string), "[Urban Gaming] %s has been kicked for the following Hack. (Armour Hacks)");
        SendClientMessageToAll(COLOR_BRIGHTRED, string);
        Kick(playerid);
    }
    return 1;
}
Replace with.


Re: Would this be a accurate anti-cheat? (Basic) - Omirrow - 30.03.2013

That may be innocent in a way prohibited by the error will be too.


Re: Would this be a accurate anti-cheat? (Basic) - rangerxxll - 30.03.2013

Quote:
Originally Posted by Pawnie
View Post
OnPlayerUpdate calls everything that happens.

Try using something like this

Credits to Coole210
Code:
new AntiCheatTimer;
enum _ACInfo
{
    Float:Health, Float:Armour, Money,
}
new ACInfo[MAX_PLAYERS][_ACInfo];

#define GivePlayerMoney GivePlayerMoneyEx
#define SetPlayerHealth SetPlayerHealthEx
#define SetPlayerArmour SetPlayerArmourEx

public OnGameModeInit()
{
    AntiCheatTimer = SetTimer("AntiCheat",1000,true);
}

public OnGameModeExit()
{
    KillTimer(AntiCheatTimer);
}

forward AntiCheat();
public AntiCheat()
{
    new Float:HP,Float:AP,_Money=GetPlayerMoney(playerid);
    GetPlayerHealth(playerid,HP);
    GetPlayerArmour(playerid,AP);
    if(HP > ACInfo[playerid][Health])
    {
        //Gained health, he used cheats
    }
    else
    {
        ACInfo[playerid][Health] = HP; //If he lost health, set anti-cheat info health to current health
    }
    if(AP > ACInfo[playerid][Armour])
    {
        //Gained armour, he used cheats
    }
    else
    {
        ACInfo[playerid][Health] = HP; //If he lost armour, set anti-cheat info armour to current armour
    }
    if(_Money > ACInfo[playerid][Money])
    {
        //Gained health, he used hacks
    }
    else
    {
        ACInfo[playerid][Money] = _Money; //If he lost money, set anti-cheat info money to current money
    }
    return 1;
}
stock SetPlayerHealthEx(playerid, Float:HP)
{
    SetPlayerHealth(playerid, HP);
    ACInfo[playerid][Health] = HP;
    return 1;
}
stock SetPlayerArmourEx(playerid, Float:AP)
{
    SetPlayerArmour(playerid, AP);
    ACInfo[playerid][Armour] = AP;
    return 1;
}
stock GivePlayerMoneyEx(playerid, money)
{
    GivePlayerMoney(playerid, money);
    ACInfo[playerid][Money] += money;
    return 1;
}
Set a timer to check his HP etc.
Having some trouble understanding. I'd need to store ALL of there money in a variable, right? So for example, if I have a /givemoney command, I'd add money to there current existing money.


Re: Would this be a accurate anti-cheat? (Basic) - Omirrow - 30.03.2013

https://sampforum.blast.hk/showthread.php?tid=292898 - subject to a reasonable


Re: Would this be a accurate anti-cheat? (Basic) - Vince - 30.03.2013

GetPlayerHealth in itself only returns 1 if the player is connected and 0 if he isn't.
pawn Code:
hp = GetPlayerHealth(playerid, hp);
That is invalid. The right syntax is simply:
pawn Code:
GetPlayerHealth(playerid, hp);