Jump to content

Fuel System Help


Recommended Posts

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
Posted (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 by Flashmyname
Link to comment
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
 
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

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