-.Paradox.- Posted December 26, 2013 Share Posted December 26, 2013 Hello guys, i made an oxygen level bar but not working, here is my code addEventHandler("onClientRender", root, function() local oxygen = math.floor(getPedOxygenLevel ( getLocalPlayer() )) if oxygen < 1000 then oxygen = oxygen / 2 end dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen/10), 18, tocolor(8, 154, 246, 255), true) end ) As you can see the oxygen is the sky-blue color bar and thats the bug Link to comment
WASSIm. Posted December 26, 2013 Share Posted December 26, 2013 addEventHandler("onClientRender", root, function() local oxygen = getPedOxygenLevel(localPlayer) if (isElementInWater(localPlayer)) then dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen/1000), 18, tocolor(8, 154, 246, 255), true) end end) Link to comment
-.Paradox.- Posted December 26, 2013 Author Share Posted December 26, 2013 Still the same problem Link to comment
Arsilex Posted December 26, 2013 Share Posted December 26, 2013 x,y = guiGetScreenSize() local r = x/1000 addEventHandler("onClientRender", root, function() local oxygen = math.floor(getPedOxygenLevel ( getLocalPlayer() )) if oxygen < 1000 then oxygen = oxygen / 2 end dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, oxygen*r*(1.3/264), 18, tocolor(8, 154, 246, 255), true) end ) Link to comment
Spajk Posted December 26, 2013 Share Posted December 26, 2013 x,y = guiGetScreenSize() local r = x/1000 addEventHandler("onClientRender", root, function() local oxygen = math.floor(getPedOxygenLevel ( getLocalPlayer() )) if oxygen < 1000 then oxygen = oxygen / 2 end dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, oxygen*r*(1.3/264), 18, tocolor(8, 154, 246, 255), true) end ) and what should "r" be? addEventHandler("onClientRender", root, function() if (isElementInWater(localPlayer)) then local oxygen = getPedOxygenLevel(localPlayer) dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen/getPedStat (localPlayer, 225)), 18, tocolor(8, 154, 246, 255), true) end end) Try this one. Link to comment
-.Paradox.- Posted December 27, 2013 Author Share Posted December 27, 2013 Not working but now just showing a black rectangle Link to comment
Snow-Man Posted December 27, 2013 Share Posted December 27, 2013 addEventHandler("onClientRender", root, function() local oxygen = math.floor (getPedOxygenLevel ( localPlayer )) if oxygen < 1000 or isElementInWater(getLocalPlayer()) then dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen/100), 18, tocolor(8, 154, 246, 255), true) end) Link to comment
DNL291 Posted December 27, 2013 Share Posted December 27, 2013 addEventHandler("onClientRender", root, function() local oxygen = math.floor (getPedOxygenLevel ( localPlayer )) if oxygen < 1000 or isElementInWater(getLocalPlayer()) then dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen/100), 18, tocolor(8, 154, 246, 255), true) end) Is missing 'end' to close the if statement. Link to comment
Snow-Man Posted December 27, 2013 Share Posted December 27, 2013 addEventHandler("onClientRender", root, function() local oxygen = math.floor (getPedOxygenLevel ( localPlayer )) if oxygen < 1000 or isElementInWater(getLocalPlayer()) then dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen/100), 18, tocolor(8, 154, 246, 255), true) end end) sorry i forget it Link to comment
Renkon Posted December 27, 2013 Share Posted December 27, 2013 local ratio = 1000 -- Not sure, but please write here the maximum oxygen, whether its 10 100 or 1000. local oxygen = math.floor(getPedOxygenLevel(getLocalPlayer())/ratio) dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen), 18, tocolor(8, 154, 246, 255), true) Link to comment
-.Paradox.- Posted December 29, 2013 Author Share Posted December 29, 2013 Still the same anyway my max oxygen level is 250 I guess it would help Link to comment
Plean Posted December 29, 2013 Share Posted December 29, 2013 addEventHandler('onClientRender', root, function () local oxygenLevel = math.ceil(getPedOxygenLevel(getLocalPlayer())) local maxOxygenLevel = 1000 + 1.5 * getPedStat(getLocalPlayer(), 225) if oxygenLevel < maxOxygenLevel or isElementInWater(getLocalPlayer()) then dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, math.floor(264 / maxOxygenLevel * oxygenLevel), 18, tocolor(8, 154, 246, 255), true) end end ) Link to comment
K4stic Posted December 29, 2013 Share Posted December 29, 2013 (edited) it's simple and easy :3 addEventHandler("onClientRender", root, function() local oxygen = string.format( "%.0f", (getPedOxygenLevel ( localPlayer ) ) ) -- i remake it to it give correct value of oxygen without decimals i mean like 1.0000147 dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, (oxygen/2.5)*26.5, 18, tocolor(8, 154, 246, 255), true) end ) Edited December 29, 2013 by Guest Link to comment
-.Paradox.- Posted December 29, 2013 Author Share Posted December 29, 2013 Still the same i tried both codes Link to comment
K4stic Posted December 29, 2013 Share Posted December 29, 2013 (edited) Copy my code again Edited December 29, 2013 by Guest Link to comment
-.Paradox.- Posted December 29, 2013 Author Share Posted December 29, 2013 Idk,By the way i used /crun getPedOxygenLevel(localPlayer) and it output that my max oxygen is 250 Link to comment
K4stic Posted December 29, 2013 Share Posted December 29, 2013 Idk,By the way i used /crun getPedOxygenLevel(localPlayer) and it output that my max oxygen is 250 in MTA wiki says oxygen: the amount of oxygen you want to set on the ped. Native values are from 0 to 1000 (At the maximum value of UNDERWATER_STAMINA full oxygen level is 2500. Higher values do not appear in the HUD). but if it's 250 them copy my code again and test But Correct setPlayerOxygen to 1000 them replace in my code the 2.5 to 10 Link to comment
-.Paradox.- Posted December 29, 2013 Author Share Posted December 29, 2013 Still not working Link to comment
Plean Posted December 31, 2013 Share Posted December 31, 2013 Try mine again, but first remove your old one. Maybe your bugged oxygen bar was covering other's bars. Link to comment
denny199 Posted December 31, 2013 Share Posted December 31, 2013 addEventHandler("onClientRender", root,function() local oxygen = math.floor(getPedOxygenLevel ( localPlayer )) --dxDrawText (tostring(oxygen), 100, 500 ) dxDrawRectangle(900, 94, 266, 20, tocolor(0, 0, 0, 255), true) dxDrawRectangle(901, 95, 264*(oxygen/1000), 18, tocolor(8, 154, 246, 255), true) end ) It works properly for me? P.S; your code isn't working for every screen resolution. Link to comment
-.Paradox.- Posted January 1, 2014 Author Share Posted January 1, 2014 I fixed it thanks a lot guys Link to comment
denny199 Posted January 2, 2014 Share Posted January 2, 2014 How did you fixed it, or what was the problem? Link to comment
-.Paradox.- Posted January 5, 2014 Author Share Posted January 5, 2014 I just set all the players stamina stats to 0 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