Problem.. GetVehicleHealth
#1

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.
Reply
#2

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

Nope :S

Just gives me '0.000000'
Reply
#4

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);
  }
}

;
Reply
#5

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 !
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)