Jump to content

Fuel System


mehmet

Recommended Posts

--Server
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)

--Client
sx,sy = guiGetScreenSize()

function testShowFuel()
    if isPedInVehicle(localPlayer) then
        dxDrawRectangle(sx-210,sy-30,200,20,tocolor(0,0,0,120))
        if getElementData(getPedOccupiedVehicle(localPlayer), "fuel") then
            fuel = getElementData(getPedOccupiedVehicle(localPlayer), "fuel")
        else
            fuel = 100
        end
        dxDrawRectangle(sx-210,sy-30,fuel/100*200,20,tocolor(127,198,118,255))
    end
end
addEventHandler("onClientRender", root, testShowFuel)

 

Edited by DREFTHUN
Checks if the engine is on or off, and according to that info it will deplete a little even when the vehicle is still.
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...