GetPlayerHealth and OnPlayerUpdate - 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: GetPlayerHealth and OnPlayerUpdate (
/showthread.php?tid=449882)
GetPlayerHealth and OnPlayerUpdate -
exclide1 - 10.07.2013
Hello. I've got a problem with my anticheat. I have it on a repeative 3 sec timer:
pawn Код:
forward CheckHealth(playerid);
public CheckHealth(playerid)
{
GetPlayerHealth(playerid, Float:gHealth);
if(gHealth != GetPVarFloat(playerid, "faPlayerHealth"))
{
if((lastupdate[playerid]+200) > GetTickCount() && gHealth > GetPVarFloat(playerid, "faPlayerHealth"))
{
HandleCheater(playerid, HealthRes);
}
else
{
//
}
SetPVarFloat(playerid, "faPlayerHealth", gHealth);
}
}
public OnPlayerUpdate(playerid)
{
lastupdate[playerid] = GetTickCount();
return 1;
}
The problem is, when player uses hacks to restore his health and instantly pauses, the hack doesn't get detected. If I understand correctly, this is how it goes:
He has "50" health the "faPlayerHealth" variable is set to 50. Then he restores his health and goes to pause, then the timer kicks in to check, the line "GetTickCount() < (lastupdate[playerid]+200)" checks if he's paused (this is to prevent false-positives), and as he's, it doesn't check for hacks and sets the variable "faPlayerHealth" to 50, because it can't get players current health, when he's paused, so it sets it to the last updated health. So what should happen, when he comes back, the timer kicks again, he has 100 health and the variable is just 50, and as he's now getting updates the "lastupdate[playerid]" +200 should be greater and it should compare his current health (100) to the variable (50), and as it's greater, trigger the detection. But it doesn't. Why?