Soapbosnia Posted July 21, 2018 Share Posted July 21, 2018 Hey MTA Community, i was trying to make a rectangle which shows player health and it should decrease/increase slowly when u lose/earn health, but it only increases when the script starts Code: function updateStuff() theHealth = getElementHealth(localPlayer) end addEventHandler("onClientRender",root,updateStuff) local tick = getTickCount()/5 addEventHandler("onClientRender", root, function() local progress = ((getTickCount()/5 - tick)/1000) local cX, cY = interpolateBetween(0, 0, 0, 0, theHealth, 0, progress, "Linear") dxDrawRectangle(450, 0, 100 * 4, 30, tocolor(0,0,0,150)) dxDrawRectangle(450, 0, cY * 4, 30, tocolor(100,0,0,255)) end ) Link to comment
Discord Moderators Pirulax Posted July 22, 2018 Discord Moderators Share Posted July 22, 2018 local tick, healthLastFrame, animateTo = 0, 0 addEventHandler("onClientRender", root, function() local health = getElementHealth(localPlayer) if (healthLastFrame~=health) then tick = getTickCount() animateTo = health else healthLastFrame = health end local progress = (getTickCount()-tick)/1000 dxDrawRectangle(450, 0, 400, 30, tocolor(0, 0, 0, 150)) dxDrawRectangle(450, 0, 400*animateTo*((progress>1 and 1) or progress)/100, 30, tocolor(100, 0, 0, 255)) end ) Should work. 'Should' bc i haven't tried it. Link to comment
TheOtherSide Posted July 22, 2018 Share Posted July 22, 2018 (edited) savedH,startedTick = 0,false addEventHandler("onClientRender", root,function() if ( savedH < getElementHealth(localPlayer) or savedH > getElementHealth(localPlayer) ) then if not( startedTick ) then tick = getTickCount()/5 startedTick = true end else startedTick = false end local progress = ((getTickCount()/5 - tick)/1000) local cX, cY = interpolateBetween(0, savedH, 0, 0, getElementHealth(localPlayer), 0, progress, "Linear") dxDrawRectangle(450, 0, 100 * 4, 30, tocolor(0,0,0,150)) dxDrawRectangle(450, 0, cY * 4, 30, tocolor(100,0,0,255)) savedH = cY end) Edited July 22, 2018 by TheOtherSide Link to comment
xMKHx Posted July 23, 2018 Share Posted July 23, 2018 On 7/22/2018 at 19:03, TheOtherSide said: savedH,startedTick = 0,false addEventHandler("onClientRender", root,function() if ( savedH < getElementHealth(localPlayer) or savedH > getElementHealth(localPlayer) ) then if not( startedTick ) then tick = getTickCount()/5 startedTick = true end else startedTick = false end local progress = ((getTickCount()/5 - tick)/1000) local cX, cY = interpolateBetween(0, savedH, 0, 0, getElementHealth(localPlayer), 0, progress, "Linear") dxDrawRectangle(450, 0, 100 * 4, 30, tocolor(0,0,0,150)) dxDrawRectangle(450, 0, cY * 4, 30, tocolor(100,0,0,255)) savedH = cY end) gg Link to comment
Soapbosnia Posted July 23, 2018 Author Share Posted July 23, 2018 Thank you guys, it works 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