Jump to content

[HELP] Health Bar


LabiVila

Recommended Posts

local x,y = guiGetScreenSize () 
  
addEventHandler ("onClientRender", root, 
    function (source) 
        local pVehicle = getPedOccupiedVehicle (localPlayer) 
        if pVehicle then 
            local vHealth = (getElementHealth (pVehicle)-250)/10 
             
            dxDrawLine (x/1.05, y/2.1, x/1.05, y/4, tocolor (255, 255, 255)) -- HOR 
            dxDrawLine (x/1.125, y/2.1, x/1.125, y/4, tocolor (255, 255, 255)) -- HOR 
             
            dxDrawLine (x/1.05, y/2.1, x/1.125, y/2.1, tocolor (255, 255, 255)) -- VER 
            dxDrawLine (x/1.05, y/3.5, x/1.125, y/3.5, tocolor (255, 255, 255)) -- VER 
             
            dxDrawRectangle (x/1.124, y/2.1,x/15.795, y/-3.97*vHealth/100, tocolor (0, 255, 0, 200)) -- GREEN ARENA 
        end 
    end 
) 
  
  

Here is my full script, it actually works cool but after it reaches 0, which means the Green Arena dissapears, if the car still gets damage, the green arena starts going down and down. I want to make like a border, here are some screens for better explanation:

cool = http://www.upload.ee/image/4200435/gta_ ... -34-19.png

not cool = http://www.upload.ee/image/4200436/gta_ ... -48-21.png

Link to comment

try this:

local x,y = guiGetScreenSize () 
  
addEventHandler ("onClientRender", root, 
function (source) 
    local pVehicle = getPedOccupiedVehicle (localPlayer) 
    if pVehicle then 
    local vHealth = (getElementHealth (pVehicle)-250)/10 
    if vHealth >= 0 then 
    dxDrawLine (x/1.05, y/2.1, x/1.05, y/4, tocolor (255, 255, 255)) -- HOR 
    dxDrawLine (x/1.125, y/2.1, x/1.125, y/4, tocolor (255, 255, 255)) -- HOR 
    dxDrawLine (x/1.05, y/2.1, x/1.125, y/2.1, tocolor (255, 255, 255)) -- VER 
    dxDrawLine (x/1.05, y/3.5, x/1.125, y/3.5, tocolor (255, 255, 255)) -- VER 
    dxDrawRectangle (x/1.124, y/2.1,x/15.795, y/-3.97*vHealth/100, tocolor (0, 255, 0, 200)) -- GREEN ARENA 
    end 
    end 
end 
) 

Link to comment

That will stop the drawing. Try this:

local x,y = guiGetScreenSize () 
  
addEventHandler ("onClientRender", root, 
function (source) 
    local pVehicle = getPedOccupiedVehicle (localPlayer) 
    if pVehicle then 
    local vHealth = (getElementHealth (pVehicle)-250)/10 
    if vHealth < 0 then 
        vHealth = 0 
    end 
    dxDrawLine (x/1.05, y/2.1, x/1.05, y/4, tocolor (255, 255, 255)) -- HOR 
    dxDrawLine (x/1.125, y/2.1, x/1.125, y/4, tocolor (255, 255, 255)) -- HOR 
    dxDrawLine (x/1.05, y/2.1, x/1.125, y/2.1, tocolor (255, 255, 255)) -- VER 
    dxDrawLine (x/1.05, y/3.5, x/1.125, y/3.5, tocolor (255, 255, 255)) -- VER 
    dxDrawRectangle (x/1.124, y/2.1,x/15.795, y/-3.97*vHealth/100, tocolor (0, 255, 0, 200)) -- GREEN ARENA 
    end 
end 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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