Sign in to follow this  
India

MTA - Fuel System

Recommended Posts

fuel is not getting low, please help me guys

SurvivorSystem_client.lua


local sx,sy = guiGetScreenSize()
local x,y,z = getElementPosition(getLocalPlayer())
for i,veh in ipairs(getElementsByType("vehicle")) do
	local px,py,pz = getElementPosition (veh)
	local vehID = getElementModel(veh)
	local vehicle = getPedOccupiedVehicle(getLocalPlayer())
	if veh ~= vehicle then
		if vehID ~= 548 then
			local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz )
			if pdistance <= 6 then
				--Get screenposition
				local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 )
				if sx and sy then
					--Draw Vehicle
					local w = dxGetTextWidth(getVehicleName(veh),1.02,"default-bold")
					dxDrawText ( getVehicleName(veh), sx-(w/2), sy, sx-(w/2), sy, tocolor ( 100, 255, 100, 200 ), 1.02, "default-bold" )
				end
			end
		end
	end
end
--Vehicle Infos
local veh = getPedOccupiedVehicle (getLocalPlayer())
if veh then
	local alan = getElementData(veh,"parent")
	if alan then
		local maxfuel = getElementData(alan,"maxfuel") or 0
		local fuel = getElementData(alan,"fuel") or 0
		local needengine = (getElementData(alan,"needengines") or 1)
		local needtires = (getElementData(alan,"needtires") or 4)
		local needparts = (getElementData(alan,"needparts") or 1)
		local engine = getElementData(alan,"Engine_inVehicle") or 0
		local tires = getElementData(alan,"Tire_inVehicle") or 0
		local parts = getElementData(alan,"Parts_inVehicle") or 0

		local enginerenk =(engine == needengine and tocolor(0,255,0,220) or	tocolor(255,0,0,220))
		local tiresrenk = (tires == needtires and tocolor(0,255,0,220) or	tocolor(255,0,0,220))
		local partsrenk = (parts == needparts and tocolor(0,255,0,220) or	tocolor(255,0,0,220))

		dxDrawText (engine.."/"..needengine.." Engine" ,0,0,sx,sy,enginerenk,1,"default-bold", "center", "top"	)
		dxDrawText (tires.."/"..needtires.." Tires",0,13,sx,sy,tiresrenk,1,"default-bold", "center", "top"	)
		dxDrawText (parts.."/"..needparts.." Tank Parts",0,24,sx,sy,partsrenk,1,"default-bold", "center", "top"	)

		if fuel == maxfuel then
			r,g,b = 0,255,0
		elseif fuel < maxfuel/10 then
			r,g,b = 255,0,0
		elseif fuel < maxfuel/4 then
			r,g,b = 255,50,0
		elseif fuel < maxfuel/3 then
			r,g,b = 200,100,0
		elseif fuel < maxfuel/2 then
			r,g,b = 125,200,0
		elseif fuel < maxfuel/1.5 then
			r,g,b = 50,200,0
		end
		dxDrawText ("Fuel:"..math.floor(fuel).."/"..maxfuel,0,36,sx,sy,tocolor( r,g,b, 220),1,"default-bold", "center", "top"	)
	end
end
if not playerTarget then return end
local x,y,z = getElementPosition(playerTarget)
local x,y,distance = getScreenFromWorldPosition (x,y,z+0.5)
distance = 20
if getElementData(playerTarget,"bandit") then
	text = string.gsub(getPlayerName(playerTarget), '#%x%x%x%x%x%x', '' ).." (Bandit)"
else
	text = string.gsub(getPlayerName(playerTarget), '#%x%x%x%x%x%x', '' )
end
local w = dxGetTextWidth(text,distance*0.033,"default-bold")
dxDrawText (text,x-(w/2),y,x-(w/2), y, tocolor ( 100, 255, 100, 200 ), distance*0.033, "default-bold" )

 

Edited by CodyJ(L)
Fixed lua shiz

Share this post


Link to post

VehiclesTable.lua and vehicle_spawns.lua 

 

vehiclesTable = {
--{Name,ID,Eng,Tire,Parts,Rot,Glass,Slots,Fuel,FuelPerMinute}
    {"Bullet",541,1,4,1,0,4,100,100,0.1},
    {"Bobcat",422,1,4,1,0,4,20,80,0.25},
    {"Patriot",470,1,4,1,0,4,40,100,0.1},
    {"Camper",483,1,4,1,0,4,20,80,0.25},
    {"Clover",542,1,4,1,0,4,35,45,0.3},
    {"Quadbike",471,1,4,1,0,0,15,30,0.1},
    {"Sanchez",468,1,2,1,0,0,10,30,0.1},
    {"FCR900",521,1,2,1,0,0,10,40,0.1},
    {"Regina",479,1,4,1,0,4,40,60,0.035},
    {"Barracks",433,1,6,1,0,4,70,140,0.5},
    {"Coach",437,1,6,1,0,4,70,140,0.5},
    {"BMX",481,0,0,0,0,0,00,000,0},
    {"Dodo",593,1,3,1,1,4,20,60,0.25},
    {"Maverick",487,1,0,1,1,4,30,60,0.25},
    {"P Maverick",497,1,0,1,1,4,35,60,0.25},
    {"Cargobob",548,1,3,1,1,4,60,160,0.5},
    {"Tractor",531,1,4,1,0,0,25,80,0.25},
    {"Mesa",500,1,4,1,0,4,20,40,0.1},
    {"Sandking",495,1,4,1,0,4,60,80,0.7},
    {"Police Car",596,1,4,1,0,4,25,60,0.7},
    {"Infernus",411,1,4,1,0,4,25,60,0.8},
    {"Reefer",453,1,0,1,0,4,30,60,0.1},
}

--engine,tires,parts,rotor,glass,slots,fuel,fuelpm = getVehicleAddonInfos(getElementModel(veh))
function getVehicleAddonInfos(ID)
  for _,veh in pairs(vehiclesTable)do
    if ID == veh[2] then
      return veh[3],veh[4],veh[5],veh[6],veh[7],veh[8],veh[9],veh[10]
    end
  end
end


vehSpawns = {}
vehSpawns["Bullet"] = {
{-1829.5804443359,1288.6861572266,59.734375}}

vehSpawns["Sandking"] = {}


vehSpawns["Infernus"] = {
{408.83032226563,2495.2810058594,20.329418182373}}


vehSpawns["Bobcat"] = {
{-2479.6240234375,2223.6669921875,4.84375},
{-92.9951171875,2823.0908203125,76.721649169922},
{-2448.99609375,-1335.8662109375,310.97662353516},
{-173.2470703125,-2635.5341796875,26.608192443848},
{2108.447265625,-1600.916015625,13.552597045898},
{2452.7392578125,1607.9833984375,10.8203125},
{-1800.8984375,-1950.9736328125,93.561332702637},
{402.92279052734,2496.9677734375,16.484375}}

vehSpawns["Patriot"] = {
{-1473.5791015625,320.2294921875,7.1875},
{-1373.998046875,460.62109375,7.1875},
{419.150390625,2186.087890625,39.499450683594},
{2821.1796875,793.4658203125,10.8984375}}

vehSpawns["Camper"] = {
{303.8581,2040.5405,17.6406,184.6847},
{-235.5664,-207.0945,1.4297,27.6536},
{-1740.5837,-67.5864,3.5547,13.4941},
{2094.1072,-1581.1379,13.2511,27.7677}}

vehSpawns["Clover"] = {}

vehSpawns["Quadbike"] = {
{-738.1989,-125.3214,67.1632,203.8758},
{-1016.8008,-688.9416,32.0078,22.4471},
{-1545.8480,628.1342,7.1875,180.2506}}

vehSpawns["Sanchez"] = {
{-812.470703125,-2629.912109375,90.105056762695},
{-1729.8525390625,-1940.3154296875,99.840209960938},
{-2130.90234375,178.4375,35.257678985596},
{-2656.7333984375,1352.4873046875,7.0596733093262},
{-1598.302734375,2694.947265625,55.07092666626},
{-809.96484375,2430.037109375,156.97012329102},
{2920.38671875,2486.0087890625,10.8203125},
{505.732421875,-291.8681640625,20.00952911377},
{-428.8828125,-694.8310546875,19.14847946167},
{1190.41015625,-2109.0341796875,64.738548278809},
{1658.9716796875,-1069.0224609375,23.906229019165}}

vehSpawns["Regina"] = {
{280.61630249023,2020.4465332031,17.640625},
{138.6126,1784.9572,17.6406,98.7775}}

vehSpawns["Barracks"] = {
{86.486328125,1950.9013671875,17.846803665161},
{440.185546875,1464.173828125,6.3338670730591}}

vehSpawns["Coach"] = {
{-1971.4619140625,97.4658203125,27.6875},
{1735.8720703125,1429.0693359375,10.797702789307},
{2797.1318359375,-1868.8359375,9.8603811264038},
{1941.900390625,1975.1904296875,7.59375}}

vehSpawns["BMX"] = {
{194.685546875,-120.2333984375,1.5497757196426},
{173.0146484375,-95.0634765625,1.5516006946564},
{2369.9599609375,29.712890625,28.0416431427},
{710.87109375,-566.7548828125,16.3359375},
{1109.6025390625,-1667.6689453125,13.615442276001},
{2014.6689453125,-1113.4013671875,26.203125},
{2447.41015625,-1967.1845703125,13.546875},
{2633.7236328125,1835.291015625,11.0234375},
{1489.3974609375,2681.54296875,10.8203125},
{-2428.5654296875,2280.875,4.984375},
{-2501.0869140625,2224.880859375,4.9861993789673},
{-2142.8515625,-2457.84765625,30.625},
{-2456.078125,-141.115234375,26.112222671509},
{-1881.4453125,954.3837890625,35.171875}}

vehSpawns["Dodo"] = {
{279.32537841797,2020.9741210938,17.640625},
{-1227.2910,-127.5485,14.1484,152.2099},
{1282.6152,1323.6509,10.8203,91.4783}}

vehSpawns["Maverick"] = {
{-1495.888671875,-2691.40234375,57.325229644775},
{-2688.42578125,1471.634765625,7.1875},
{-1534.28125,2842.9482421875,97.463409423828},
{2221.8583984375,-1344.396484375,23.984273910522}}

vehSpawns["P Maverick"] = {
{-1354.9009,-580.84528,14.148438},
{-1467.4047,1488.0812,8.2500687},
{-1680.4514160156,707.12536621094,30.6015625}}

vehSpawns["Cargobob"] = {}

vehSpawns["FCR900"] = {}

vehSpawns["Tractor"] = {}

vehSpawns["Mesa"] = {}

vehSpawns["Police Car"] = {
{2314.9506835938,2460.3657226563,3.2734375},
{1601.1104736328,-1629.669921875,13.477452278137}}

vehSpawns["Reefer"] = {}
 

 

 

vehicle_spawns.lua

 

function spawnDayZVehicles()
  for i,vehs in pairs(vehiclesTable)do
    spawnedVehs = {}
    count = math.random(0,#vehSpawns[vehs[1]])
    for i=1,count do
      num = math.random(1,#vehSpawns[vehs[1]])
      if not isVehSpawned(num) then
        table.insert(spawnedVehs,num)
        x,y,z = vehSpawns[vehs[1]][num][1],vehSpawns[vehs[1]][num][2],vehSpawns[vehs[1]][num][3]
        veh = createVehicle(vehs[2],x,y,z)
        vehCol = createColSphere(x,y,z,4)
        attachElements(vehCol,veh,0,0,0)
        setElementData(vehCol,"parent",veh)
        setElementData(veh,"parent",vehCol)
        setElementData(vehCol,"vehicle",true)
        setElementData(vehCol,"MAX_Slots",vehs[8])
        engRand = math.random(0,vehs[3])
        tireRand = math.random(0,vehs[4])
        partRand = math.random(0,vehs[5])
        rotorRand = math.random(0,vehs[6])
        glaRand = math.random(0,vehs[7])
        setElementData(vehCol,"Engine_inVehicle",engRand)
        setElementData(vehCol,"Tire_inVehicle",tireRand)
        setElementData(vehCol,"Parts_inVehicle",partRand)
        setElementData(vehCol,"Rotor_inVehicle",rotorRand)
        setElementData(vehCol,"Glass_inVehicle",glaRand)
        setElementData(vehCol,"spawn",{vehs[2],x,y,z})
        setElementData(vehCol,"fuel",10)
        setElementData(vehCol,"ProtectionPercent",0)
        setElementData(vehCol,"maxfuel",vehs[9])
        setElementData(vehCol,"needengines",vehs[3])
        setElementData(vehCol,"needtires",vehs[4])
        setElementData(vehCol,"needparts",vehs[5])
        setElementData(vehCol,"needrotor",vehs[6])
        setElementData(vehCol,"needglass",vehs[7])
        if tireRand >= 1 then
          setElementData(vehCol,"TireState",math.random(0,100))
        else
          setElementData(vehCol,"TireState",100)
        end
        if engRand >= 1 then
          setElementData(vehCol,"EngineState",math.random(0,100))
        else
          setElementData(vehCol,"EngineState",100)
        end
        if rotorRand >= 1 then
          setElementData(vehCol,"RotorState",math.random(0,100))
        else
          setElementData(vehCol,"RotorState",100)
        end
        if partRand >= 1 then
          setElementData(vehCol,"PartsState",math.random(0,100))
        else
          setElementData(vehCol,"PartsState",100)
        end
      end
    end
  end
end

function notifyAboutExplosion()
  occupants = getVehicleOccupants(source) or {}
  for _,peds in pairs(occupants)do
    removePedFromVehicle(peds)
  end
  local col = getElementData(source,"parent")
  if col and getElementData(col,"helicrash") then return end
  id,x,y,z = getElementData(col,"spawn")[1],getElementData(col,"spawn")[2],getElementData(col,"spawn")[3],getElementData(col,"spawn")[4]
  setTimer(respawnDayZVehicle,600000,1,id,x,y,z,source,col)
  setElementData(col,"deadVehicle",true)
  setElementData(source,"isExploded",true)
  x1,y1,z1 = getElementPosition(source)
  createExplosion(x1+1,y1+1,z1,4)
  createExplosion(x1-1,y1-1,z1,4)
  createExplosion(x1+1,y1-1,z1,4)
  createExplosion(x1-1,y1+1,z1,4)
end
addEventHandler("onVehicleExplode",getRootElement(),notifyAboutExplosion)

function respawnVehiclesInWater(vehiclesInWater)
  for i,veh in ipairs(getElementsByType("vehicle"))do
    if isElementInWater(veh) and getVehicleType(veh) ~= "Boat" then
      local col = getElementData(veh,"parent")
      id,x,y,z = getElementData(col,"spawn")[1],getElementData(col,"spawn")[2],getElementData(col,"spawn")[3],getElementData(col,"spawn")[4]
      respawnDayZVehicle(id,x,y,z,veh,col)
    end
  end
end
setTimer(respawnVehiclesInWater,600000,0)

function respawnDayZVehicle(id,x,y,z,veh,col)
  destroyElement(veh)
  destroyElement(col)
  local engine,tires,parts,rotor,glass,slots,fuel,fuelpm = getVehicleAddonInfos(id)
  veh = createVehicle(id,x,y,z)
  vehCol = createColSphere(x,y,z,4)
  attachElements(vehCol,veh,0,0,0)
  setElementData(vehCol,"parent",veh)
  setElementData(veh,"parent",vehCol)
  setElementData(vehCol,"vehicle",true)
  setElementData(vehCol,"MAX_Slots",slots)
  engRand = math.random(0,engine)
  tireRand = math.random(0,tires)
  partRand = math.random(0,parts)
  rotorRand = math.random(0,rotor)
  glaRand = math.random(0,glass)
  setElementData(vehCol,"Engine_inVehicle",engRand)
  setElementData(vehCol,"Tire_inVehicle",tireRand)
  setElementData(vehCol,"Parts_inVehicle",partRand)
  setElementData(vehCol,"Rotor_inVehicle",rotorRand)
  setElementData(vehCol,"Glass_inVehicle",glaRand)
  setElementData(vehCol,"spawn",{id,x,y,z})
  setElementData(vehCol,"fuel",10)
  setElementData(vehCol,"ProtectionPercent",0)
  setElementData(vehCol,"maxfuel",fuel)
  setElementData(vehCol,"needengines",engine)
  setElementData(vehCol,"needtires",tires)
  setElementData(vehCol,"needparts",parts)
  setElementData(vehCol,"needrotor",rotor)
  setElementData(vehCol,"needglass",glass)
  if tireRand >= 1 then
    setElementData(vehCol,"TireState",math.random(0,100))
  else
    setElementData(vehCol,"TireState",100)
  end
  if engRand >= 1 then
    setElementData(vehCol,"EngineState",math.random(0,100))
  else
    setElementData(vehCol,"EngineState",100)
  end
  if rotorRand >= 1 then
    setElementData(vehCol,"RotorState",math.random(0,100))
  else
    setElementData(vehCol,"RotorState",100)
  end
  if partRand >= 1 then
    setElementData(vehCol,"PartsState",math.random(0,100))
  else
    setElementData(vehCol,"PartsState",100)
    local randomNumber = math.random(1,10)
    if randomNumber == 5 then
      setElementData(vehCol,items[1],1)
    end
  end
end

function spawnVehiclePack(ps,cmd)
  if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(ps)),aclGetGroup("Console")) then
    spawnDayZVehicles()
    outputChatBox("Vehicles has been spawned!",ps,255,0,0,true)
  end
end
addCommandHandler("svp",spawnVehiclePack)

function onPlayerEnterDayzVehicle(veh,seat)
  if seat == 0 then
    setVehicleEngineState(veh,false)
    outputChatBox("Press 'K' to turn the engine on/off!",source,255,255,255)
  end
end
addEventHandler("onPlayerVehicleEnter",getRootElement(),onPlayerEnterDayzVehicle)

function onPlayerExitDayzVehicle(veh,seat)
  if seat == 0 then
    setVehicleEngineState(veh,false)
  end
end
addEventHandler("onPlayerVehicleExit",getRootElement(),onPlayerExitDayzVehicle)

function setVehiclesFuelPerMinute ()
    for i,veh in ipairs(getElementsByType("vehicle")) do
        if getVehicleEngineState(veh) == true then
            if getElementData(getElementData(veh,"parent"),"fuel") >= 0 then
                setElementData(getElementData(veh,"parent"),"fuel",getElementData(getElementData(veh,"parent"),"fuel")-getVehicleFuelRemove(getElementModel(veh),getElementData(veh,"parent")))
            else
                setVehicleEngineState ( veh, false )
            end
        end
    end
end
setTimer(setVehiclesFuelPerMinute,20000,0)

function isVehicleReadyToStart2 (veh)
    if getElementData(getElementData(veh,"parent"),"fuel") >= 1 then
        local tires,engine,parts,metal = getVehicleAddonInfos (getElementModel(veh))
        if (getElementData(getElementData(veh,"parent"),"Tire_inVehicle") or 0) > tonumber(tires) and (getElementData(getElementData(veh,"parent"),"Engine_inVehicle") or 0) > tonumber(engine) and (getElementData(getElementData(veh,"parent"),"Parts_inVehicle") or 0) > tonumber(parts) then
            setVehicleEngineState ( veh, true )
        end
    end
    setTimer(isVehicleReadyToStart2,1000,1,veh)
end

function setVehiclesFuelPerMinute()
    for i,veh in ipairs(getElementsByType("vehicle")) do
        if getVehicleEngineState(veh) == true then
            if getElementData(getElementData(veh,"parent"),"fuel") >= 0 then
                setElementData(getElementData(veh,"parent"),"fuel",getElementData(getElementData(veh,"parent"),"fuel")-getVehicleFuelRemove(getElementModel(veh),getElementData(veh,"parent")))
            else
                local driver = getVehicleOccupant ( veh )
                unbindKey(driver,"k","down",setEngineStateByPlayer)
                setVehicleEngineState(veh,false)
            end
        end
    end
end
setTimer(setVehiclesFuelPerMinute,2000,0)

function isVehicleReadyToStart2 (veh)
    if getElementData(getElementData(veh,"parent"),"fuel") >= 1 then
        local tires,engine,parts = getVehicleAddonInfos (getElementModel(veh))
        if (getElementData(getElementData(veh,"parent"),"Tire_inVehicle") or 0) > tonumber(tires) and (getElementData(getElementData(veh,"parent"),"Engine_inVehicle") or 0) > tonumber(engine) and (getElementData(getElementData(veh,"parent"),"Parts_inVehicle") or 0) > tonumber(parts) then
            setVehicleEngineState ( veh, true )
        end
    end
    setTimer(isVehicleReadyToStart2,1000,1,veh)
end

repairTimer = {}
function repairVehicle(veh)
  if repairTimer[veh] then
    triggerClientEvent(source,"displayClientInfo",source,"Vehicle",getVehicleName(veh).." is currently being repaired!",255,22,0)
    return
  end
  local health = math.floor(getElementHealth(veh))
  repairTimer[veh] = setTimer(fixVehicleDayZ,(1000 - health)*120,1,veh,source)
  setElementFrozen(veh,true)
  setElementData(veh,"repairer",source)
  setElementData(source,"repairingvehicle",veh)
  setPedAnimation(source,"SCRATCHING","sclng_r",-1,true,false)
  triggerClientEvent(source,"displayClientInfo",source,"Vehicle","You started to repair "..getVehicleName(veh),22,255,0)
end
addEvent("repairVehicle",true)
addEventHandler("repairVehicle",getRootElement(),repairVehicle)

function fixVehicleDayZ(veh,player)
  local FL,RL,FR,RR = getVehicleWheelStates(veh)
  setElementHealth(veh,1000)
  fixVehicle(veh)
  setVehicleWheelStates(veh,FL,RL,FR,RR)
  setPedAnimation(player,false)
  setElementFrozen(veh,false)
  repairTimer[veh] = nil
  setElementData(veh,"repairer",nil)
  setElementData(player,"repairingvehicle",nil)
  triggerClientEvent(player,"displayClientInfo",player,"Vehicle","You finished repairing "..getVehicleName(veh),22,255,0)
end

function stopFixxingWhileMoving()
  local veh = getElementData(source,"repairingvehicle")
  setPedAnimation(source)
  setElementFrozen(veh,false)
  setElementData(veh,"repairer",nil)
  setElementData(source,"repairingvehicle",nil)
  triggerClientEvent(source,"displayClientInfo",source,"Vehicle","You stopped repairing "..getVehicleName(veh),255,22,0)
  killTimer(repairTimer[veh])
  repairTimer[veh] = nil
end
addEvent("onClientMovesWhileAnimation",true)
addEventHandler("onClientMovesWhileAnimation",getRootElement(),stopFixxingWhileMoving)

function debugFixxing()
  for i,veh in ipairs(getElementsByType("vehicle"))do
    if getElementData(veh,"repairer")== source then
      outputDebugString("Vehicle repairer disconnected - destroyed tables")
      killTimer(repairTimer[veh])
      setElementFrozen(veh,false)
      repairTimer[veh] = nil
      setElementData(veh,"repairer",nil)
    end
  end
end
addEventHandler("onPlayerQuit",getRootElement(),debugFixxing)

Edited by India

Share this post


Link to post

You are posting client side scripts, if it's a fuel system, the server-side scripts do the math to 'lower' fuel, so go check server side scripts for any errors (you can use /debugscript 3)

Share this post


Link to post
5 hours ago, Feche1320 said:

You are posting client side scripts, if it's a fuel system, the server-side scripts do the math to 'lower' fuel, so go check server side scripts for any errors (you can use /debugscript 3)

No error about fuel

which lua files u need?

Share this post


Link to post
7 hours ago, WASSIm. said:

Post server-side

Its DayZ mode, which server-side? i didnt understand

My files;

addons

animals

animals_client

BackpacksTable

coma_c

coma_s

CraftRecipes

dataTables

editor_server

inventory

login

menu_client

pickups

spawn

SurvivorSystem

survivorSystem_client

textlib

vehicle_spawns

VehiclesTable

VestsMasksTable

WeaponsTable

 

 

Share this post


Link to post

It looks like 1 of the old days gamemodes which gets bugged easily by spawning vehicles outside of the gamemode. rip 😬

Share this post


Link to post

It is DayZ mode

I have that files about fuel;

survivorSystem_client.lua

vehicle_spawns

VehiclesTable

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.