Jump to content

Fuel System


mehmet

Recommended Posts

Posted

 

Hi guys,
I want to make a fuel system. As I understand it better to do this on the server side. So that they could not change the values. Yes?

And is it possible to do without getElementData?
For example, using the table

Posted (edited)
7 hours ago, DREFTHUN said:

PM me your discord name and I’ll help you in about 3 hrs.

ok

Edited by mehmet
Posted (edited)
--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.

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