Jump to content

Problem with healthbar (dxdrawrectangle)


MitnickP56

Recommended Posts

Hi. I have problem with healthbar (my edit) original: https://community.multitheftauto.com/in ... ls&id=9135

All can see on the picture. In random healthbar 0% and in this script 22%

http://iv.pl/images/65963762101610373676.png

Code:

  
local screenW,screenH = guiGetScreenSize() 
local resW,resH = 1280,720 
local sW,sH =  (screenW/resW), (screenH/resH) 
  
function drawVehicleHUD() 
    local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) 
        if ( vehicle ) then 
            --local speedX, speedY, speedZ = getElementVelocity ( vehicle  ) 
           --local actualSpeed = (speedX^2 + speedY^2 + speedZ^2)^(0.5)  
            --local KMH = math.floor(actualSpeed*180)    
                if ( getElementHealth( vehicle ) >= 1000 ) then 
                    vehiclehealth = 100 
                else 
                    vehiclehealth = math.floor(getElementHealth ( vehicle )/10) 
                end 
                    dxDrawRectangle(1079*sW, 578*sH, 191*sW, 17*sH, tocolor(0, 0, 0, 180), true) 
                    dxDrawRectangle(1084*sW, 583*sH, 181*sW, 17*sH, tocolor(0, 0, 0, 80), true) 
                   dxDrawRectangle(1084*sW, 583*sH, 181*sW/100*vehiclehealth, 10*sH, tocolor(8, 252, 104, 255), true) 
                    --dxDrawText("HEALTH", 1084*sW, 683*sH, 1265*sW, 700*sH, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false) 
                    --dxDrawRectangle(1079*sW, 646*sH, 191*sW, 27*sH, tocolor(0, 0, 0, 180), true) 
                    --dxDrawText(KMH.." KM/H", 1084*sW, 651*sH, 1265*sW, 668*sH, tocolor(255, 255, 255, 255), 1.15, "default-bold", "center", "center", false, false, true, false, false) 
                    dxDrawText(vehiclehealth.."%", 1203*sW, 1020*sH, 1260*sW, 270*sH, tocolor(0, 255, 0, 255), 1.00, "default-bold", "center", "center", false, false, true, true, false)        
        end 
    end 
addEventHandler("onClientRender", root, drawVehicleHUD) 

Please help.

Link to comment

Here:

local screenW,screenH = guiGetScreenSize() 
local resW,resH = 1280,720 
local sW,sH =  (screenW/resW), (screenH/resH) 
  
function drawVehicleHUD() 
   local vehicle = getPedOccupiedVehicle( getLocalPlayer() ) 
      if ( vehicle ) then 
         --local speedX, speedY, speedZ = getElementVelocity ( vehicle  ) 
         --local actualSpeed = (speedX^2 + speedY^2 + speedZ^2)^(0.5) 
         --local KMH = math.floor(actualSpeed*180) 
            health = getElementHealth(vehicle) 
         health = (math.max(0,health-250)/750)*100 
     
         dxDrawRectangle(1079*sW, 578*sH, 191*sW, 17*sH, tocolor(0, 0, 0, 180), true) 
         dxDrawRectangle(1084*sW, 583*sH, 181*sW, 17*sH, tocolor(0, 0, 0, 80), true) 
         dxDrawRectangle(1084*sW, 583*sH, 181*sW/100*math.floor(health), 10*sH, tocolor(8, 252, 104, 255), true) 
         --dxDrawText("HEALTH", 1084*sW, 683*sH, 1265*sW, 700*sH, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false) 
         --dxDrawRectangle(1079*sW, 646*sH, 191*sW, 27*sH, tocolor(0, 0, 0, 180), true) 
         --dxDrawText(KMH.." KM/H", 1084*sW, 651*sH, 1265*sW, 668*sH, tocolor(255, 255, 255, 255), 1.15, "default-bold", "center", "center", false, false, true, false, false) 
         dxDrawText(math.floor(health).."%", 1203*sW, 1020*sH, 1260*sW, 270*sH, tocolor(0, 255, 0, 255), 1.00, "default-bold", "center", "center", false, false, true, true, false)       
      end 
   end 
addEventHandler("onClientRender", root, drawVehicleHUD) 

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