Wasp Posted May 15, 2022 Share Posted May 15, 2022 Hi, I Got A Script Of Fuel ,Server Side And It's Perfectly Work With My Fuel Hud ,But Vehicle Engine Does Not Stop When The Fuel Is Empty Pls Help. fuelConsumption = 0.004 fuelTable = {} function vehMove() for i,v in ipairs(getElementsByType("vehicle")) do x,y,z = getElementPosition(v) if fuelTable[v] then distance = getDistanceBetweenPoints3D(x,y,z,fuelTable[v][2],fuelTable[v][3],fuelTable[v][4]) enginePlus = 0 if getVehicleEngineState(v) then enginePlus = 0.08 end newFuel = fuelTable[v][1] - (fuelConsumption*(distance+enginePlus)) fuelTable[v] = {newFuel,x,y,z} setElementData(v, "fuel", fuelTable[v][1]) else if getElementData(v, "fuel") then fuelTable[v] = {getElementData(v, "fuel"), x, y, z} else fuelTable[v] = {100, x, y, z} end end end end setTimer(vehMove, 1000, 0) Link to comment
Flashmyname Posted May 15, 2022 Share Posted May 15, 2022 (edited) Hi, you should try somehow like this. setTimer(function() if isPedInVehicle(localPlayer) and getPedOccupiedVehicle(localPlayer) then if getVehicleEngineState (getPedOccupiedVehicle(localPlayer)) then if tonumber(getPedOccupiedVehicle(localPlayer):getData("fuel") or 0) > 0 then else getPedOccupiedVehicle(localPlayer):setData("fuel",0) triggerServerEvent("vehicleStart",localPlayer,localPlayer,getPedOccupiedVehicle(localPlayer),false) end end end end,1000,0) Edited May 15, 2022 by Flashmyname Link to comment
Hydra Posted May 17, 2022 Share Posted May 17, 2022 function CheckFuel() for k, v in ipairs(getElementsByType("vehicle")) do if v == getPedOccupiedVehicle(localPlayer) then if getElementData(v, "fuel") <= 0 then setVehicleEngineState(getPedOccupiedVehicle(localPlayer), false) else getElementData(v, "fuel") >= 1 then setVehicleEngineState(getPedOccupiedVehicle(localPlayer), false) end end end end addEventHandler("onClientRender", root, CheckFuel) Not sure if it will work and not sure if I did it right but you can try it Link to comment
iwalidza Posted May 17, 2022 Share Posted May 17, 2022 fuelConsumption = 0.004 fuelTable = {} function vehMove() for i,v in ipairs(getElementsByType("vehicle")) do x,y,z = getElementPosition(v) if fuelTable[v] then distance = getDistanceBetweenPoints3D(x,y,z,fuelTable[v][2],fuelTable[v][3],fuelTable[v][4]) enginePlus = 0 if getVehicleEngineState(v) then enginePlus = 0.08 end newFuel = fuelTable[v][1] - (fuelConsumption*(distance+enginePlus)) fuelTable[v] = {newFuel,x,y,z} setElementData(v, "fuel", fuelTable[v][1]) else if getElementData(v, "fuel") then fuelTable[v] = {getElementData(v, "fuel"), x, y, z} else fuelTable[v] = {100, x, y, z} end end if getElementData(v, "fuel") <= 0 then setVehicleEngineState(v, false) end end end setTimer(vehMove, 1000, 0) 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