NadhmiNK Posted March 25, 2016 Share Posted March 25, 2016 Hi So, what i'm trying to accomplish is pretty simple but i can't seem to do it . I want to show a healthbar over other players' vehicles. Anywat, I've made this simple script: addEventHandler( "onClientRender", root, function( thePlayer ) local vehicle = getPedOccupiedVehicle(thePlayer) local x, y, z = getElementPosition( vehicle ) local sX, sY = getScreenFromWorldPosition( x, y, z ) local health = math.floor( getElementHealth( vehicle )/10) local Rhealth = 50 local lineLength = 56 * ( health / 100 ) if health < 25 then health = 0 else math.floor( getElementHealth( vehicle )/10) end if isElementOnScreen( vehicle ) then if sX then dxDrawText( health, sX, sY ) dxDrawRectangle( sX-32, sY-82, 60, 14, tocolor( 0, 100, 0, 120 ) ) dxDrawRectangle( sX-30, sY-80, 56, 10, tocolor( 0, 220, 0, 120 ) ) dxDrawRectangle( sX-30, sY-80, lineLength, 10, tocolor( 0, 220, 0 ) ) end end end ) But it doesn't act as any other floating health bar (that one witch is on top of every player's car). I can see my own car's bar but i can't see other's ones (same thing with other players) So, can anyone can help me out fixing this script, or give me another fully working one Thnx; Link to comment
..:D&G:.. Posted March 25, 2016 Share Posted March 25, 2016 Try this: addEventHandler( "onClientRender", root, function() for i, vehicle in ipairs(getElementsByType("vehicle")) do local x, y, z = getElementPosition( vehicle ) local sX, sY = getScreenFromWorldPosition( x, y, z ) local health = math.floor( getElementHealth( vehicle )/10) local Rhealth = 50 local lineLength = 56 * ( health / 100 ) if health < 25 then health = 0 else math.floor( getElementHealth( vehicle )/10) end if isElementOnScreen( vehicle ) then if sX then dxDrawText( health, sX, sY ) dxDrawRectangle( sX-32, sY-82, 60, 14, tocolor( 0, 100, 0, 120 ) ) dxDrawRectangle( sX-30, sY-80, 56, 10, tocolor( 0, 220, 0, 120 ) ) dxDrawRectangle( sX-30, sY-80, lineLength, 10, tocolor( 0, 220, 0 ) ) end end end end ) Those changes should render the HP bar for all the vehicles. Link to comment
NadhmiNK Posted March 25, 2016 Author Share Posted March 25, 2016 Works, thanks. BUT, it shows the health bar for every vehicle in the map whereas i only want it for the players' vehicles (ped's occupied vehicle). Can you help me with that? Link to comment
ozulus Posted March 25, 2016 Share Posted March 25, 2016 This should work. addEventHandler( "onClientRender", root, function() for i, vehicle in ipairs(getElementsByType("vehicle")) do local x, y, z = getElementPosition( vehicle ) local sX, sY = getScreenFromWorldPosition( x, y, z ) local health = math.floor( getElementHealth( vehicle )/10) local Rhealth = 50 local lineLength = 56 * ( health / 100 ) if health < 25 then health = 0 else math.floor( getElementHealth( vehicle )/10) end local vehicleDriver = getVehicleOccupant ( vehicle ) -- get driver of car if isElement(vehicleDriver) then -- is there driver in car?, if yes draw the healthbar if isElementOnScreen( vehicle ) then if sX then dxDrawText( health, sX, sY ) dxDrawRectangle( sX-32, sY-82, 60, 14, tocolor( 0, 100, 0, 120 ) ) dxDrawRectangle( sX-30, sY-80, 56, 10, tocolor( 0, 220, 0, 120 ) ) dxDrawRectangle( sX-30, sY-80, lineLength, 10, tocolor( 0, 220, 0 ) ) end end end end end ) Link to comment
NadhmiNK Posted March 25, 2016 Author Share Posted March 25, 2016 Thank you, works perfectly. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now