lolman Posted August 10, 2015 Share Posted August 10, 2015 Hello, I've been working on the fuel system but the problem is that I don't know what to do... I mean, the fuel system works perfect but because I did getLocalPlayer() the player which one's fuel is 0% and gets in an another vehicle it also says 0%... I tried looping but that doesn't work also.. If someone could explain me a bit... Here's the code: local x, y = guiGetScreenSize() function drawFuel() local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) local getFuel = getElementData(getLocalPlayer(), "Fuel") if isPedInVehicle (localPlayer) == false then return end sx, sy, sz = getElementVelocity (theVehicle) kmhs = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180) dxDrawText ( ""..math.round(getFuel, 2).." %", 44, y - 41, x, y, tocolor ( 0, 0, 0, 255 ), 1.02, "bankgothic" ) if getKeyState("W") or getKeyState("S") then setElementData(getLocalPlayer(), "Fuel", (getFuel-1.000)) end end function HandleTheRendering ( ) addEventHandler ( "onClientRender", root, drawFuel ) end addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering ) function outOfFuel() local getFuel = getElementData(getLocalPlayer(), "Fuel") local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) if isPedInVehicle(localPlayer) == false then return end if (getFuel < 0) then dxDrawText ( "0 %", 44, y - 41, x, y, tocolor ( 0, 0, 0, 255 ), 1.02, "bankgothic" ) setVehicleEngineState(theVehicle, false) removeEventHandler("onClientRender", root, drawFuel) end end function setFuel() setElementData(getLocalPlayer(), "Fuel", 100) end addEventHandler("onClientResourceStart", root, setFuel) function HandleTheRendering2 ( ) addEventHandler ( "onClientRender", root, outOfFuel ) end addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering2 ) Link to comment
GTX Posted August 11, 2015 Share Posted August 11, 2015 (edited) setElementData(getPedOccupiedVehicle(getLocalPlayer()), "Fuel", (getFuel-1.000)) Edited August 12, 2015 by Guest Link to comment
lolman Posted August 12, 2015 Author Share Posted August 12, 2015 doesnt work... if i get in a vehicle and the fuel is empty and then get in an another one there comes a lot of bug in the debugmessages... Link to comment
FlyingSpoon Posted August 12, 2015 Share Posted August 12, 2015 What messages are outputted. Link to comment
lolman Posted August 12, 2015 Author Share Posted August 12, 2015 Hmm, I had changed that line where it says : setElementData(getLocalPlayer(), "Fuel", (getFuel-1.000)) to setElementData(getPedOccupiedVehicle(getLocalPlayer()), "Fuel", (getFuel-1.000)) but the text (fuel) doesnt even gets lower... sorry for what I've said above but I don't see any errors and it doesn't work... Link to comment
GTX Posted August 12, 2015 Share Posted August 12, 2015 You also have to change local getFuel = getElementData(getPedOccupiedVehicle(getLocalPlayer()), "Fuel") 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