SoManyTears Posted December 23, 2019 Share Posted December 23, 2019 (edited) 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 December 23, 2019 by SoManyTears Link to comment
Addlibs Posted December 23, 2019 Share Posted December 23, 2019 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. Link to comment
Mahlukat Posted December 30, 2019 Share Posted December 30, 2019 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) 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