Difference between oldand new carhealth
#1

Hi, i wanted to know the following, is it possible to check the difference between the old carhealth, and the new carhealt, like when you crash? Can someone explain that to me?
Reply
#2

Yes it is possible, run a timer which checks the new health and the old health. It has been made before, but you have to search for that one : >

Anyways, that is the basics
Reply
#3

I can't find anything, on this forum and on ******...
Reply
#4

http://forum.sa-mp.com/index.php?topic=61190.0

This is the basic idea, you just need to edit the timer a little to your needs
Reply
#5

That isn't what i mean. Even not a bit like that.

I want, if my carhealth is now exactly 1000.0, and after a crash it is 700.0, i will save those numbers in a oldcarhealth and newcarhealth. Than i can check the difference, oldcarhealth-newcarhealth = 300.0.

And, i think that isn't a scripting basic, i know the basics.
Reply
#6

I didn't mean 'basics' like scripting basics.. I meant for your timer

pawn Код:
forward CarHealthTimer();
public CarHealthTimer()
{
  for (new i=0; i < MAX_PLAYERS; i++)
  {
    if (IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
    {
       new Float:current[MAX_PLAYERS];
       GetVehicleHealth(GetPlayerVehicleID(i),current[i]);
       if(current[i] < oldhealth[i]) { // action
       }
       // then you overwrite your old health..
      oldhealth[i] = current[i];
     }
  }
}
Like that..
Reply
#7

And where do i define the oldhealth? :P
Reply
#8

Quote:
Originally Posted by Remi-X
And where do i define the oldhealth? :P
Woah, somebody has been a little in-active?
Reply
#9

?
Reply
#10

pawn Код:
new oldhealth[MAX_PLAYERS];

forward CarHealthTimer();
forward OnPlayerVehicleHealthChange(playerid, vehicleid, Float:oldhealth, Float:newhealth);

public OnGameModeInit()
{
  SetTimer("CarHealthTimer", 1000, true);
  return 1;
}

public CarHealthTimer()
{
  for (new i=0; i < MAX_PLAYERS; i++)
  {
    if (IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
    {
       new Float:current;
       new vehicleid = GetPlayerVehicleID(i);
       GetVehicleHealth(vehicleid, current);
       if(current != oldhealth[i])
       {
             OnPlayerVehicleHealthChange(i, vehicleid, oldhealth[i], current);
       }
       oldhealth[i] = current;
     }
  }
  return 1;
}

public OnPlayerVehicleHealthChange(playerid, vehicleid, Float:oldhealth, Float:newhealth)
{
  // Do something
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: