Jump to content

Oxygen Bar


-.Paradox.-

Recommended Posts

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

mta_screen_2013_12_26_11_58_20.jpg

Link to comment
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
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
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
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
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
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
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
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

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 by Guest
Link to comment
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
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

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.
×
×
  • Create New...