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