Dzsozi (h03) Posted April 1, 2014 Share Posted April 1, 2014 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'. Link to comment
MIKI785 Posted April 1, 2014 Share Posted April 1, 2014 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. Link to comment
Dzsozi (h03) Posted April 1, 2014 Author Share Posted April 1, 2014 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? Link to comment
Castillo Posted April 1, 2014 Share Posted April 1, 2014 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 ) Link to comment
Dzsozi (h03) Posted April 1, 2014 Author Share Posted April 1, 2014 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 Link to comment
arezu Posted April 1, 2014 Share Posted April 1, 2014 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). Link to comment
Castillo Posted April 1, 2014 Share Posted April 1, 2014 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. 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