Jump to content

Ped Health Bar


Recommended Posts

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

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