SoManyTears

appear ped health bar with weapon aim

Recommended Posts

 

I tried a few more events but failed.I just want the health bar to appear when I "aim" on ped.Now health bar looks without aim with gun! how can ı really do that ?Please help someone? :/

 

function pedHealthbar()
	for k, peds in pairs(getElementsByType("ped", root, true)) do
	if getElementData(peds, "type") == "Secur.ped" then
	target = getPedTarget(peds)
    if ( target ) then
		local recBar = dxDrawRectangle(sX+420, sY-600,150, 12, tocolor(0, 0, 0, 200))
		local health = getElementHealth(peds)
		local lineLength = 144 * (health / 100)
		local healthBar = dxDrawRectangle(sX+423, sY-597,lineLength, 7, tocolor(46, 139, 87, 210))
	    dxDrawText("Security", sX+460, sY-627, sX+155, sY-19-(32*7), tocolor(0,0,0, 255), 1.6, font, "left", "top")
	     dxDrawText("Security", sX+461.5, sY-625.5, sX+153.5, sY-17.5-(32*7), tocolor(255, 255, 255, 255), 1.6, font, "left", "top")
	end           
end
end
addEventHandler("onClientRender", root, pedHealthbar)

 

Edited by SoManyTears

Share this post


Link to post

You need to use getPedTask or getPedSimplestTask but I'm not sure what task you'd be looking for. Try displaying the tasks of the local player on screen for debugging, find out what tasks are active while aiming, then remove the debug displays since they're no longer needed, and check if these tasks are active before rendering the healthbar. 

Share this post


Link to post
function pedHealthbar()
	local target = getPedTarget(localPlayer) -- get localPlayers's target
	for k, peds in pairs(getElementsByType("ped", root, true)) do
		if getElementData(peds, "type") == "Secur.ped" then
			if ( isElement(target) and target == peds ) then
				local recBar = dxDrawRectangle(sX+420, sY-600,150, 12, tocolor(0, 0, 0, 200))
				local health = getElementHealth(peds)
				local lineLength = 144 * (health / 100)
				local healthBar = dxDrawRectangle(sX+423, sY-597,lineLength, 7, tocolor(46, 139, 87, 210))
				dxDrawText("Security", sX+460, sY-627, sX+155, sY-19-(32*7), tocolor(0,0,0, 255), 1.6, font, "left", "top")
				dxDrawText("Security", sX+461.5, sY-625.5, sX+153.5, sY-17.5-(32*7), tocolor(255, 255, 255, 255), 1.6, font, "left", "top")
			end           
		end
	end
end	
addEventHandler("onClientRender", root, pedHealthbar)

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.