SA-MP Forums Archive
Problem.. GetVehicleHealth - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem.. GetVehicleHealth (/showthread.php?tid=132513)



Problem.. GetVehicleHealth - Fedee! - 07.03.2010

I have this, it will show your car health in a textdraw:
pawn Код:
forward Update(playerid);
public Update(playerid)
{
  if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
        new Float:CHealth, veh, s[32];
        veh = GetPlayerVehicleID(playerid);
        GetVehicleHealth(veh, CHealth);
    format(s,32,"Vehicle Health: %f", CHealth/10*10);
      TextDrawShowForPlayer(playerid, CHealthtext);
      TextDrawSetString(CHealthtext, s);
  }
  else if(GetPlayerState(playerid == PLAYER_STATE_ONFOOT))
  {
    TextDrawHideForPlayer(playerid, CHealthtext);
  }
}
But what I want, is it to show it on percent(%), I've been trying, but I easily failed
Thanks.


Re: Problem.. GetVehicleHealth - bajskorv123 - 07.03.2010

Dunno but try
Код:
format(s, 32, "Vehicle Health:%f", floatround(CHealth/10, floatround_round));



Re: Problem.. GetVehicleHealth - Fedee! - 07.03.2010

Nope :S

Just gives me '0.000000'


Re: Problem.. GetVehicleHealth - Gyvo - 07.03.2010

If you want the percentage... It is Amount/ Total * 100..

But for vehicles, the total is 1000. So then you do 1000/100 which equals 10 therefore the best and quickest way to do it is "Vehicle Health/10"

This should work great.
Код:
forward Update(playerid);
public Update(playerid)
{
  if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
  new Float:CHealth, veh, s[32];
  veh = GetPlayerVehicleID(playerid);
  GetVehicleHealth(veh, CHealth);
  new vHealth;
  vHealth = floatround((CHealth/10), floatround_floor);
  format(s,32,"Vehicle Health: %i", vHealth)
  TextDrawShowForPlayer(playerid, CHealthtext);
  TextDrawSetString(CHealthtext, s);
  }
  else if(GetPlayerState(playerid == PLAYER_STATE_ONFOOT))
  {
    TextDrawHideForPlayer(playerid, CHealthtext);
  }
}

;



Re: Problem.. GetVehicleHealth - Fedee! - 07.03.2010

Quote:
Originally Posted by Gyvo
If you want the percentage... It is Amount/ Total * 100..

But for vehicles, the total is 1000. So then you do 1000/100 which equals 10 therefore the best and quickest way to do it is "Vehicle Health/10"

This should work great.
Код:
forward Update(playerid);
public Update(playerid)
{
  if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  {
  new Float:CHealth, veh, s[32];
  veh = GetPlayerVehicleID(playerid);
  GetVehicleHealth(veh, CHealth);
  new vHealth;
  vHealth = floatround((CHealth/10), floatround_floor);
  format(s,32,"Vehicle Health: %i", vHealth)
  TextDrawShowForPlayer(playerid, CHealthtext);
  TextDrawSetString(CHealthtext, s);
  }
  else if(GetPlayerState(playerid == PLAYER_STATE_ONFOOT))
  {
    TextDrawHideForPlayer(playerid, CHealthtext);
  }
}

;
Lol, I din't even think abou that
Im too bad at maths

Works fine, many thanks !


Re: Problem.. GetVehicleHealth - Gyvo - 07.03.2010

Quote:
Originally Posted by Fedee!
Lol, I din't even think abou that
Im too bad at maths

Works fine, many thanks !
No problem dude!

Good luck with everything you're doing.