Jump to content

Displaying nitro level with dx functions


Recommended Posts

Posted

Hey guys! So today i tried to make a nitro-o-meter thing. So when you enter a vehicle and if it has nitro in it you should see a rectangle which is displays the nitro level. But it's not working for some reason, and I don't know why. Can somebody help me please?

Here's my code:

function drawNitro() 
    dxDrawRectangle(1330, 950, fNitroLevel, 45, tocolor(0, 255, 0, 255), false) 
end 
  
function displayNitroLevel(pPlayer) 
    if pPlayer == localPlayer then 
        if getVehicleUpgradeOnSlot( source, 8 ) then -- Check if the vehicle has nitro installed 
            local fNitroLevel = getVehicleNitroLevel(source) 
            addEventHandler("onClientRender", root, drawNitro) 
            --outputChatBox("The nitro level of this " .. getVehicleName(source) .. " is " .. fNitroLevel .. ".", 255, 180, 20, false) 
        end 
    end 
end 
addEventHandler("onClientVehicleEnter", root, displayNitroLevel) 

P.S.: I used wiki's example of 'getVehicleNitroLevel'.

Your signature image is too large.

Removed

Posted

That wouldnt work, there are several issues. First fNitroLevel is a local so it would be nil in drawNitro... secondly you save the value into variable just when the player enters vehicle, it wouldn't get refreshed... and thirdly wiki says: "Returns a float determining the nitro level (ranges from 0.0001 to 1.0) of the vehicle" so you woudln't be able to see it anyway.

Lua Scripter

?ucet=miki_cz

Owner of mshost.cz MTA portal.

Posted
That wouldnt work, there are several issues. First fNitroLevel is a local so it would be nil in drawNitro... secondly you save the value into variable just when the player enters vehicle, it wouldn't get refreshed... and thirdly wiki says: "Returns a float determining the nitro level (ranges from 0.0001 to 1.0) of the vehicle" so you woudln't be able to see it anyway.

So how can I make the nitro level visible with dx functions to players when they enter a vehicle?

Your signature image is too large.

Removed

Posted
function drawNitro ( ) 
    local vehicle = getPedOccupiedVehicle ( localPlayer ) 
    if ( vehicle ) then 
        local fNitroLevel = getVehicleNitroLevel ( vehicle ) 
        dxDrawRectangle(1330, 950, fNitroLevel, 45, tocolor(0, 255, 0, 255), false) 
    end 
end 
  
function displayNitroLevel ( pPlayer ) 
    if ( pPlayer == localPlayer ) then 
        if getVehicleUpgradeOnSlot ( source, 8 ) then -- Check if the vehicle has nitro installed 
            addEventHandler ( "onClientRender", root, drawNitro ) 
            --outputChatBox("The nitro level of this " .. getVehicleName(source) .. " is " .. fNitroLevel .. ".", 255, 180, 20, false) 
        end 
    end 
end 
addEventHandler ( "onClientVehicleEnter", root, displayNitroLevel ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
function drawNitro ( ) 
    local vehicle = getPedOccupiedVehicle ( localPlayer ) 
    if ( vehicle ) then 
        local fNitroLevel = getVehicleNitroLevel ( vehicle ) 
        dxDrawRectangle(1330, 950, fNitroLevel, 45, tocolor(0, 255, 0, 255), false) 
    end 
end 
  
function displayNitroLevel ( pPlayer ) 
    if ( pPlayer == localPlayer ) then 
        if getVehicleUpgradeOnSlot ( source, 8 ) then -- Check if the vehicle has nitro installed 
            addEventHandler ( "onClientRender", root, drawNitro ) 
            --outputChatBox("The nitro level of this " .. getVehicleName(source) .. " is " .. fNitroLevel .. ".", 255, 180, 20, false) 
        end 
    end 
end 
addEventHandler ( "onClientVehicleEnter", root, displayNitroLevel ) 

It draws a little line, but it not changes when nitro is activated :|

Your signature image is too large.

Removed

Posted

Why dont you guys read MIKI785's comment?

Returns a float determining the nitro level (ranges from 0.0001 to 1.0)

You have to multiply the nitro level with a high value if you want to display it graphically (try to multiply by 100 or something).

Posted
function drawNitro ( ) 
    local vehicle = getPedOccupiedVehicle ( localPlayer ) 
    if ( vehicle ) then 
        local fNitroLevel = getVehicleNitroLevel ( vehicle ) 
        dxDrawRectangle(1330, 950, fNitroLevel, 45, tocolor(0, 255, 0, 255), false) 
    end 
end 
  
function displayNitroLevel ( pPlayer ) 
    if ( pPlayer == localPlayer ) then 
        if getVehicleUpgradeOnSlot ( source, 8 ) then -- Check if the vehicle has nitro installed 
            addEventHandler ( "onClientRender", root, drawNitro ) 
            --outputChatBox("The nitro level of this " .. getVehicleName(source) .. " is " .. fNitroLevel .. ".", 255, 180, 20, false) 
        end 
    end 
end 
addEventHandler ( "onClientVehicleEnter", root, displayNitroLevel ) 

It draws a little line, but it not changes when nitro is activated :|

That part is up to you, I won't do all the job.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...