mehmet Posted February 6, 2019 Share Posted February 6, 2019 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 Link to comment
DREFTHUN Posted February 7, 2019 Share Posted February 7, 2019 PM me your discord name and I’ll help you in about 3 hrs. Link to comment
mehmet Posted February 7, 2019 Author Share Posted February 7, 2019 (edited) 7 hours ago, DREFTHUN said: PM me your discord name and I’ll help you in about 3 hrs. ok Edited February 7, 2019 by mehmet Link to comment
DREFTHUN Posted February 7, 2019 Share Posted February 7, 2019 (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 February 7, 2019 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
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