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)