Sign in to follow this  
Master_11

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)

 

Share this post


Link to post
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)

 

Share this post


Link to post

Thanks! it works but is it possible to make the rectangle size same as the ped size on movement?

Share this post


Link to post
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? 

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.