Jump to content

[HELP] Maths headache


.:HyPeX:.

Recommended Posts

Well i'm totally confused and i'm not sure how to continue this.. I'll try to explain my best what is the issue:

Vehicles have max 1000HP.

Under 250HP they get into fire.

I'm making a Health bar. Under 250HP it should be actually 0.

Whats my issue? My maths to draw the bar.

My fast-fix was to get down those 250HP.

Health = health-250

max = 750

local progress = Health/max

The problem is, if you had 500HP. Aka 50%, on the new calculation you would have 250/750, wich doesnt shows 50%, and i'm not sure how to do this...

  
    local health = math.ceil( ( getElementHealth(veh) )) 
    local max = 1000 
    local min = 0 
    local percentage = health/max 
    if health >= 250 then 
    health = health-250 
    max = 750 
    progress = health / max 
    else 
    progress = health / max 
    end 
    if health <= 0 then 
    health = 0 
    end 

Greetz

EDIT: I'm an idiot, didnt realize that actually 0.33 is right if you have 250HP of 750.. :roll:

Link to comment
  • MTA Team

You should try the math functions.

  
local nHealth = getElementHealth(veh) or 0 
local nProgress = math.max(0, (nHealth - 250) / 750) 
  

OR

  
local nHealth = math.max(0, (getElementHealth(veh) or 0) - 250) 
local nProgress = nHealth / 750 
  

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...