MAB Posted July 15, 2015 Posted July 15, 2015 why the fuel isn't going down?! am i using the data wrong? *NOTE: this isn't the full script it is just the function that the error is in.. function updateFuel() local veh = getPedOccupiedVehicle( localPlayer ) if isPedInVehicle ( localPlayer ) then if getVehicleEngineState ( veh ) == true then CurrentFuelValue = getElementData(veh,"Fuel") NewFuelValue = CurrentFuelValue - 1 timer = setTimer ( setElementData, 10*1000, 0, veh, "fuel", tonumber(NewFuelValue) ) end if getVehicleEngineState ( veh ) == false then if timer then killTimer ( timer ) end end end if (CurrentFuelValue==0) then setVehicleEngineState(veh,false) end end addEventHandler ("onClientRender", getLocalPlayer(), updateFuel)
Addlibs Posted July 15, 2015 Posted July 15, 2015 *NOTE: this isn't the full script it is just the function that the error is in.. What is the error?
GTX Posted July 15, 2015 Posted July 15, 2015 Timer inside onClientRender event? No, no, no. You know this isn't going to work.
Gr0x Posted July 16, 2015 Posted July 16, 2015 lastTick = 0 function updateFuel() if isPedInVehicle ( localPlayer ) then local veh = getPedOccupiedVehicle( localPlayer ) if getVehicleEngineState ( veh ) == true then CurrentFuelValue = getElementData(veh,"Fuel") if (CurrentFuelValue == 0) then setVehicleEngineState(veh,false) return end if getTickCount() - lastTick <= 10000 then lastTick = getTickCount() setElementData(veh,"Fuel",CurrentFuelValue-1) end end end end addEventHandler ("onClientRender", getLocalPlayer(), updateFuel)
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