Help with this anticheat of health.
#1

Ok, I made this..

pawn Код:
new Float: pHealth[MAX_PLAYERS];

SetTimer("CheckH", 1000, 1);

stock SetPlayerHealthEx(playerid, Float: health)
{
    pHealth[playerid] = health;
    SetPlayerHeatlh(playerid, health);
    return 1;
}

stock GetPlayerHealthEx(playerid, &Float: health)
{
    GetPlayerHealth(playerid, health);
    return 1;
}

forward CheckH();
public CheckH()
{
    static Float:old_health;
    foreach(Player, i)
    {
        GetPlayerHealth(i, old_health);
        if(old_health != pHealth[i])
        {
            SetPlayerHealthEx(i, pHealth[i]);
        }
    }
    return 1;
}
But.. how can I make if a player get's hurt(punched, fired, fall, etc) the HP goes down?

Thanks
Reply
#2

So make a warning. if maybe he uses hacks it will print out a warn.
Reply
#3

You should read this tutorial I made: Understanding the SA-MP sync.

The most solid way to get a great anti-health hack would be to set all players' money to negative and use something like this (note that I can't test it at the moment):
This is just to illustrate what I'm suggesting, as it's easier than explaining in words!
pawn Код:
new
    Float:g_afPreviousHealth[ MAX_PLAYERS ], // This variable holds the last known health of each player
     bool:g_abIsSpawned[ MAX_PLAYERS char ]  // This variable defines wether a player is spawned or not
;

public OnPlayerConnect( playerid )
{
    g_abIsSpawned[ playerid ] = false; // The player just connected - not spawned
}

public OnPlayerStateChange( playerid, newstate, oldstate )
{
    if ( newstate == PLAYER_STATE_ONFOOT || newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER || newstate == PLAYER_STATE_SPAWNED )
    { // ^ If the new state is one of the states spawned players has ..
        if ( oldstate == PLAYER_STATE_NONE || oldstate == PLAYER_STATE_SPECTATING || oldstate == PLAYER_STATE_WASTED )
        { // ^ If the old state isn't one of the states spawned players has ..
            g_abIsSpawned     [ playerid ] = true;  // The player is now considered spawned
            g_afPreviousHealth[ playerid ] = 100.0; // Health is set to 100 when you spawn
        }
    }
    else
    { // The new state is one that spawned players don't have
        g_abIsSpawned[ playerid ] = false;
    }
}

public OnPlayerUpdate( playerid )
{
    static
        Float:s_fHealth
    ;
   
    GetPlayerHealth( playerid, s_fHealth ); // Get the current health
   
    if ( s_fHealth != g_afPreviousHealth[ playerid ] ) // Compare it to the last known health
    {
        if ( s_fHealth > g_afPreviousHealth[ playerid ] )
        { // The new health is more than the previous!
            static
                s_szMessage[ 64 ]
            ;
           
            format( s_szMessage, sizeof( s_szMessage ), "Health increased for player %d: %0.f -> %0.f", playerid, g_afPreviousHealth[ playerid ], s_fHealth );
           
            SendClientMessageToAll( -1, s_szMessage );
        }
       
        g_afPreviousHealth[ playerid ] = s_fHealth; // Set the previous health to the new one
    }
   
    return 1; // Never forget this in OnPlayerUpdate
}
Reply
#4

checking every players health 40-60times a second isn't the best idea
Reply
#5

Quote:
Originally Posted by cessil
Посмотреть сообщение
checking every players health 40-60times a second isn't the best idea
It takes 600ms to get a player's health 10,000,000 times. I doubt it would be a problem unless you're hosting the server off a calculator.

also, it is the best way to do it. using a timer wouldn't be as accurate.

Read: Understanding SA-MP sync
Reply
#6

Well, thaks g_aSlice, but I solved it my self :P

I had to add this

pawn Код:
else if(old_health < pHealth[i])
{
     pHealth[i] = old_health;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)