19.10.2010, 06:14
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!
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
}