[Help] Health Anticheat Problem
#1

I am trying to script a type of health anti-cheat but it just won't work properly...

Код:
//The function below is called every 250ms
public HealthCheck()
{
	for(new i=0; i<MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i) && GetPlayerState(i) != PLAYER_STATE_SPECTATING && GetPlayerState(i) != PLAYER_STATE_WASTED)
		{
            new Float:health;
  			GetPlayerHealth(i, health);
  			if(health >= 100.0)
  			{
  			   SetPlayerHealth(i, 75.0);
  			   GetPlayerHealth(i, health);
  			   if(health > 75.0)
  			   {
  			   	SendClientMessage(i, COLOR_RED, "-> Cheater");
  			   }
  			   else
  			   {
  				SendClientMessage(i, COLOR_RED, "-> Clean");
   				SetPlayerHealth(i, 100.0);
  			   }
  		}
    }
}
As soon as i enter the server i keep getting "-> Cheater" message.
Normaly i shouldn't get it since i don't hack but i keep getting it.
The code looks like it should work but it just doesn't.

Anyone can figure out the problem?
Reply
#2

Put it under OnPlayerSpawn instead. Since there's no point in hacking health when you're not spawned.
Reply
#3

You didn't get my point... It works exactly as it shouldn't.

EXAMPLE:

Retrieve Health: 100.0
Health Set: 75.0
Retrieve Health: 100.0 // Here is my problem. Second time it retrieves 100.0 health even if i have 75.0 health
Retrieved Health != Health Set -> Cheater
Reply
#4

Quote:
Originally Posted by viKKmaN
You didn't get my point... It works exactly as it shouldn't.

EXAMPLE:

Retrieve Health: 100.0
Health Set: 75.0
Retrieve Health: 100.0 // Here is my problem. Second time it retrieves 100.0 health even if i have 75.0 health
Retrieved Health != Health Set -> Cheater
No1?
Reply
#5

When the player join, his health is above 100. I have noticed this myself.
Reply
#6

I noticed you were missing a bracket.

pawn Код:
//The function below is called every 250ms
public HealthCheck()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && GetPlayerState(i) != PLAYER_STATE_SPECTATING && GetPlayerState(i) != PLAYER_STATE_WASTED)
        {
            new Float:health;
            GetPlayerHealth(i, health);
            if(health >= 100.0)
            {
                SetPlayerHealth(i, 75.0);
                GetPlayerHealth(i, health);
                if(health > 75.0)
                {
                    SendClientMessage(i, COLOR_RED, "-> Cheater");
                }
                else
                {
                    SendClientMessage(i, COLOR_RED, "-> Clean");
                    SetPlayerHealth(i, 100.0);
                }
            }
        }
    }
}
See if that helps?
Reply
#7

SetPlayerHealth takes a couple of seconds to work, I came across this problem with my Anti Cheat too.
Reply
#8

Quote:
Originally Posted by cessil
SetPlayerHealth takes a couple of seconds to work, I came across this problem with my Anti Cheat too.
He's right, lag is an important issue, so first set the health to 75, then wait a X amount of seconds before checking health again...

X = whatever number best suits to work for you & your players (I suggest starting with 3 though)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)