How to check the difference?
#1

Hey everybody

I'm back with another question...

How to check if the difference between those is more then 40?

Code:
fHealth
Code:
faPlayerHealth[playerid]
EDIT: Example:

(Taken from SAMP Wiki)
pawn Code:
new Float:faPlayerHealth[MAX_PLAYERS];  // float-array storing all players health.

public OnPlayerUpdate(playerid)
{
    new Float:fHealth;

    GetPlayerHealth(playerid, fHealth);

    if(fHealth != faPlayerHealth[playerid])
    {
      // Player health has changed since last update from player -> server, so obviously thats the thing updated.
      // Lets do further checks see if he've lost or gain health, anti health cheat? ;-)

      if(fHealth > faPlayerHealth[playerid])
      {
        /* He've gained health! Cheating? Write your own scripts here to figure how a player
            gained health! */

      }
      else if(   Difference between "fHealth" and "faPlayerHealth[playerid]" is more then 40     )
      {
        /* He've lost health! */
      }

      faPlayerHealth[playerid] = fHealth;
    }
}
Reply
#2

pawn Code:
else if( ( fHealth - faPlayerHealth[playerid] ) > 40 )
Reply
#3

Quote:
Originally Posted by Marcel
pawn Code:
else if( ( fHealth - faPlayerHealth[playerid] ) > 40 )
What is fHealth is less than faPlayerHealth[playerid] ?

You will get a negative value, that is most certainly less than 40!
Reply
#4

pawn Code:
new Float:faPlayerHealth[MAX_PLAYERS];  // float-array storing all players health.

public OnPlayerUpdate(playerid)
{
    new Float:fHealth;

    GetPlayerHealth(playerid, fHealth);

    if(fHealth != faPlayerHealth[playerid])
    {
      // Player health has changed since last update from player -> server, so obviously thats the thing updated.
      // Lets do further checks see if he've lost or gain health, anti health cheat? ;-)

      if(fHealth > faPlayerHealth[playerid])
      {
        /* He've gained health! Cheating? Write your own scripts here to figure how a player
            gained health! */

      }
    else if((fHealth - faPlayerHealth[playerid]) > 40)
      {
        SetPlayerHealth(playerid,0);
      }

      faPlayerHealth[playerid] = fHealth;
    }
}
That didn't work...

It's supposed to kill the player if he looses more then 40 hp on the update...
Reply
#5

Quote:
Originally Posted by IntrozeN
That didn't work...

It's supposed to kill the player if he looses more then 40 hp on the update...
Well it wouldn't. If the new health is less than the old health:

20-70 = -50
-50 is not > 40
Reply
#6

Quote:
Originally Posted by Weirdosport
Quote:
Originally Posted by IntrozeN
That didn't work...

It's supposed to kill the player if he looses more then 40 hp on the update...
Well it wouldn't. If the new health is less than the old health:

20-70 = -50
-50 is not > 40
what you mean?

EDIT:
pawn Code:
new Float:faPlayerHealth[MAX_PLAYERS];  // float-array storing all players health.

public OnPlayerUpdate(playerid)
{
    new Float:fHealth;

    GetPlayerHealth(playerid, fHealth);

    if(fHealth != faPlayerHealth[playerid])
    {
      // Player health has changed since last update from player -> server, so obviously thats the thing updated.
      // Lets do further checks see if he've lost or gain health, anti health cheat? ;-)

      if(fHealth > faPlayerHealth[playerid])
      {
        /* He've gained health! Cheating? Write your own scripts here to figure how a player
            gained health! */

      }
    else if((fHealth - faPlayerHealth[playerid]) > 40)
      {
        SetPlayerHealth(playerid,0);
      }

      faPlayerHealth[playerid] = fHealth;
    }
}
PLEASE... Change so it will work? (A)
Reply
#7

pawn Code:
else if( ( fHealth - faPlayerHealth[playerid] ) > 40 || ( fHealth - faPlayerHealth[playerid] ) < -40 )
There.
Reply
#8

Quote:
Originally Posted by IntrozeN
what you mean?
Ok i'll go through it a bit more clearly.

Let's say the player had 80 health to start with. The script runs and this ends up being saved to faPlayerHealth. For some reason or other, the player loses 50 hp at once! His health is not 30. The script runs.

It reaches this line:
pawn Code:
((fHealth - faPlayerHealth[playerid]) > 40)
fHealth = 30
faPlayerHealth = 80

30 minus 80 = negative 50.
The script then checks to see if negative 50 is greater than 40. Which it isn't. So the script within that box is never going to be triggered!

The guy aboves solution should work, but he got there before I had chance to post >.>

EDIT: With that script though anybody whose HP increases or decreases by 40 hp at once will end up being killed.
Reply
#9

Quote:
Originally Posted by ▒▓█ [S•A•F•E
Vince █▓▒ ]
pawn Code:
else if( ( fHealth - faPlayerHealth[playerid] ) > 40 || ( fHealth - faPlayerHealth[playerid] ) < -40 )
There.
Thank you VERY MUCH

Problem Solved
Reply
#10

No problem, glad I could help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)