Master_11 Posted June 29, 2018 Share Posted June 29, 2018 Hey, I am facing some problem with the Peds health bar, like when the PED is my target the bar is visible, but when I move back or forward the size of the bar changes. Any suggestion regarding this problem? (It's client) local PedA = createPed(285, 1571.49634, -1664.07715, 28.39561, 90) function healthbar() local plr = localPlayer local x, y, z = getElementPosition(PedA) target = getPedTarget(plr) if (not target) then return false end if (not getElementType(target) == "ped" ) then return false end if (not isElementOnScreen(PedA)) then return false end local X, Y = getScreenFromWorldPosition(x, y, z) if (X) then local healthA = dxDrawRectangle(X - 50, Y - 50, 270, 27, tocolor(241, 236, 253, 114), false) local health = getElementHealth(PedA) local lineLength = 256 * (health / 100) local healthB = dxDrawRectangle(X - 44, Y - 44, lineLength, 17, tocolor(9, 172, 213, 254), false) end end addEventHandler("onClientRender", root, healthbar) Link to comment
Dimos7 Posted June 29, 2018 Share Posted June 29, 2018 local sw, sh = guiGetScreenSize() local sx, sy = sw/1920, sh/1080 -- change those number with your resolution local PedA = createPed(285, 1571.49634, -1664.07715, 28.39561, 90) function healthbar() local plr = localPlayer local x, y, z = getElementPosition(PedA) target = getPedTarget(plr) if (not target) then return false end if (not getElementType(target) == "ped" ) then return false end if (not isElementOnScreen(PedA)) then return false end local X, Y = getScreenFromWorldPosition(x, y, z) if (X) then local healthA = dxDrawRectangle(X - 50, Y - 50, sx*270, sy*27, tocolor(241, 236, 253, 114), false) local health = getElementHealth(PedA) local lineLength = 256 * (health / 100) local healthB = dxDrawRectangle(X - 44, Y - 44, lineLength, sy*17, tocolor(9, 172, 213, 254), false) end end addEventHandler("onClientRender", root, healthbar) Link to comment
Master_11 Posted June 29, 2018 Author Share Posted June 29, 2018 Thanks! it works but is it possible to make the rectangle size same as the ped size on movement? Link to comment
Dimos7 Posted June 29, 2018 Share Posted June 29, 2018 41 minutes ago, Master_11 said: Thanks! it works but is it possible to make the rectangle size same as the ped size on movement? What do you mean? Link to comment
Master_11 Posted June 30, 2018 Author Share Posted June 30, 2018 Nothing, it's fine thanks! 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