Furious^ONE!

Erreur au niveau d'un script

Recommended Posts

Bonsoir, 

Je rencontre actuellement un soucis au niveau d'un script, j'ai pris une base d'un gamemode dayz que j'ai modifié, mais actuellement le problème est lié au script de mon vehicle_spawn.Lua, je n'ai quasi rien touché dans ce fichier mise à part avoir ajouter quelques position pour tel spawn box ou autre, j'ai beau essayer de trouver mais j'ai du mal;

Voici le code:

 

hospitalPacks = {
{-2670.87890625,636.8984375,14.453125},
{-2637.0556640625,635.03125,14.453125},
{-1515.669921875,2519.166015625,56.0703125},
{-1513.888671875,2519.5908203125,56.064819335938},
{-1528.8955078125,2516.724609375,55.986171722412},
{2022.1650390625,-1402.6806640625,17.18045425415},
{2042.7001953125,-1409.4775390625,17.1640625},
{-316.5478515625,1051.6494140625,20.340259552002},
{-337.9541015625,1049.490234375,19.739168167114},
{-331.5849609375,1046.037109375,26.012474060059},
{-307.0419921875,1045.27734375,26.012474060059},
{1171.490234375,-1310.560546875,13.986573219299},
{1171.609375,-1306.556640625,13.996350288391},
{1158.5048828125,-1326.333984375,31.503561019897},
{1159.80078125,-1323.9013671875,31.498970031738},
{1238.7119140625,328.2431640625,19.7555103302},
{1229.365234375,311.1435546875,24.7578125},
{-2204.07421875,-2309.58203125,31.375},
{1615.939453125,1818.0537109375,10.8203125},
{1601.9443359375,1816.736328125,10.8203125},
{1590.0166015625,1792.0234375,30.46875},
{1607.3232421875,1776.7412109375,37.3125},
{2107.7626953125,926.16015625,10.8203125},
{2116.12890625,925.7705078125,10.9609375},
{2122.1865234375,925.3193359375,10.8203125},
{1260.6501464844,-1799.30078125,13.478693008423}, -- Military Camp Verdant Bluff
{1280.0263671875,-1810.7297363281,13.463276863098}, -- Military Camp Verdant Bluff
{1352.2316894531,404.55191040039,19.5546875}, --- MONTGOMERY MILITARY CAMP
{-2752.1530761719,403.74862670898,4.4635558128357}, --- MAIRIE SF
{-2770.8791503906,415.75357055664,4.4786520004272}, --- MAIRIE SF
---HOSPITAL SF---
{-2671.3078613281,625.27618408203,14.859218597412}, -- AMBULANCE MEDIC BOX
{-2641.1657714844,622.57006835938,14.859218597412}, -- AMBULANCE MEDIC BOX
--- HOSPITAL ROOF ---
{-2691.83203125,527.86340332031,48.063758850098},
{-2710.32421875,539.60845947266,48.07857131958},
{-2628.9931640625,490.79647827148,47.9765625},
{-2641.9028320313,490.28616333008,47.9765625},
---AU DESSUS DES DAMSO---
{-1913.7913818359,-489.23870849609,38.234375},
{-1913.5050048828,-501.54971313477,38.234375},
{-1233.2175292969,-22.528776168823,14.1484375}, -- SF AP
{-1227.8767089844,-35.254020690918,14.1484375}, -- SF AP
--- SF ECOLE DRIVING---
{-2017.0971679688,-212.9753112793,35.370311737061},
{-2015.7872314453,-193.4952545166,35.379531860352},
{-2090.9128417969,-276.59533691406,35.370311737061},
{657.61706542969,-1370.1496582031,21.80965423584}, --- Chass Camp
}

patrolPoints = {
{-1603.2197265625,-2712.736328125,48.9453125},
{2465.748046875,-2215.55859375,13.546875},
{2473.439453125,-2215.56640625,13.546875},
{2480.0732421875,-2216.140625,13.546875},
{2487.24609375,-2215.5966796875,13.546875},
{2494.1005859375,-2215.5859375,13.546875},
{-1686.6728515625,408.9970703125,7.3984375},
{-1682.34375,412.9384765625,7.3984375},
{-1680.0263671875,402.3642578125,7.3984375},
{-1675.84375,406.4677734375,7.3984375},
{-1670.5615234375,411.8359375,7.3984375},
{-1666.2392578125,416.2509765625,7.3984375},
{-1672.7939453125,422.81640625,7.3984375},
{-1677.20703125,418.46484375,7.3984375},
{-2410.7021484375,969.9091796875,45.4609375},
{-2410.744140625,975.220703125,45.4609375},
{-2410.837890625,980.5302734375,45.4609375},
{-1329.3046875,2668.5126953125,50.46875},
{-1328.7314453125,2673.90625,50.0625},
{-1327.0185546875,2679.3876953125,50.46875},
{-1327.3798828125,2684.62890625,50.0625},
{1940.7099609375,-1778.5244140625,13.390598297119},
{1940.6552734375,-1774.908203125,13.390598297119},
{1940.630859375,-1771.728515625,13.390598297119},
{1940.7080078125,-1767.3837890625,13.390598297119},
{-1477.921875,1868.138671875,32.639846801758},
{-1466.1552734375,1869.0048828125,32.6328125},
{-1464.5224609375,1861.3828125,32.639846801758},
{-1477.4599609375,1860.5205078125,32.6328125},
{-735.9208984375,2744.0087890625,47.2265625},
{-739.0439453125,2744.2421875,47.165451049805},
{377.6953125,2601.1083984375,16.484375},
{624.5263671875,1676.25390625,6.9921875},
{620.2958984375,1681.2431640625,6.9921875},
{616.248046875,1686.4169921875,7.1875},
{612.783203125,1691.1650390625,7.1875},
{609.2060546875,1696.201171875,7.1875},
{605.8505859375,1700.978515625,7.1875},
{602.27734375,1706.3603515625,7.1875},
{2141.037109375,2742.734375,10.960174560547},
{2142.3115234375,2752.6982421875,10.96019744873},
{2147.9521484375,2752.3203125,10.8203125},
{2152.60546875,2751.953125,10.8203125},
{2152.984375,2743.85546875,10.8203125},
{2147.75,2743.7392578125,10.8203125},
{-97.6298828125,-1175.0283203125,2.4990689754486},
{-90.74609375,-1177.853515625,2.2021217346191},
{-84.75390625,-1163.853515625,2.3359375},
{-91.5771484375,-1160.5732421875,2.4453125},
{-1606.525390625,-2717.2138671875,48.9453125},
{-1609.7109375,-2721.544921875,48.9453125},
{-1599.83203125,-2708.302734375,48.9453125},
{-2246.314453125,-2558.8212890625,32.0703125},
{-2241.3125,-2561.3662109375,32.0703125},
{-1132.2880859375,-135.0986328125,14.14396572113},
{-1153.529296875,-156.373046875,14.1484375},
{-1142.826171875,-145.67578125,14.14396572113},
{655.611328125,-557.9912109375,16.501491546631},
{655.6572265625,-572.1728515625,16.501491546631},
{1601.791015625,2203.90625,11.060997009277},
{1596.806640625,2203.4345703125,10.8203125},
{1590.197265625,2203.4853515625,10.8203125},
{1589.4775390625,2195.43359375,10.8203125},
{1596.125,2194.294921875,10.8203125},
{1601.6591796875,2194.3369140625,10.8203125},
{2206.8466796875,2470.47265625,10.8203125},
{2206.94140625,2474.75,10.8203125},
{2206.9267578125,2478.86328125,10.8203125},
{2198.06640625,2480.6953125,10.8203125},
{2197.541015625,2475.791015625,10.995170593262},
{2197.609375,2471.9169921875,10.995170593262},
{2120.8251953125,915.4833984375,10.8203125},
{2115.1181640625,915.44140625,10.8203125},
{2109.076171875,915.4228515625,10.8203125},
{2109.22265625,924.8779296875,10.9609375},
{2114.9404296875,924.8857421875,10.9609375},
{2119.5126953125,925.2861328125,10.9609375},
{2645.7197265625,1112.7802734375,10.8203125},
{2639.984375,1112.56640625,10.8203125},
{2634.828125,1112.3466796875,10.9609375},
{2634.1826171875,1101.9482421875,10.8203125},
{2636.7509765625,1101.6748046875,10.8203125},
{2643.5126953125,1101.81640625,10.8203125},
{2209.576171875,2469.8251953125,10.8203125},
{2208.8310546875,2475.09375,10.8203125},
{1005.078125,-901.7490234375,42.216625213623},
{993.025390625,-902.474609375,42.222496032715},
}

lootItems = {
  helicrashsides = {
	{"M4A1",356,1,90,3},
	{"M4A1 CCO",356,1,90,3},
	{"M4A1 CCO SD",356,1,90,3},
	{"FN SCAR",356,1,90,2},
	{"FN SCAR SD",356,1,90,2},
	----------------------------
	{"M107",358,1,90,0.5},
	{"AS50",358,1,90,0.8},
	{"KSVK",358,1,90,0.7},
	{"Cheytac M200",358,1,90,1},
	----------------------------
	{"M249 SAW",355,1,90,1.5},
	{"M240",355,1,90,1.5},
	{"Mk 48 Mod 0",355,1,90,1.5},
	{"PKP",355,1,90,1.5},
	{"PKM",355,1,90,1.5},
    ----------------------------
	{"Balanced Vest",1800,1,0,1},
	{"Press Vest",1481,1,0,2},
	{"Police Vest",1744,1,0,1},
	{"Light Tactical Vest",1759,1,0,2.5},
	----------------------------
	{"Ghillie Helmet",1759,1,0,2.5},
	{"Helmet",1759,1,0,2.5},
	{"Helmet ONU",1759,1,0,2.5},
	
  },
  bmpcrashsides = {
	{"M4A1",356,1,90,3},
	{"AK-74 GP-25",356,1,90,3},
	{"Steyr Aug",356,1,90,3},
	{"M4A1 CCO",356,1,90,3},
	{"AKS Gold",356,1,90,3},
	{"AKS-74 Kobra",356,1,90,3},
	{"M4A1 CCO SD",356,1,90,3},
	{"FN SCAR",356,1,90,2},
	{"Balanced Vest",1800,1,0,1},
	{"FN SCAR SD",356,1,90,2},
	{"Helmet",1759,1,0,2.5},
	{"Helmet ONU",1759,1,0,2.5},
	{"Light Tactical Vest",1759,1,0,2.5},
	
  },    
  hospital = {
	{"Syringe",2000,1,0},
	{"Antibiotics",1919,2.1,0},
	{"Medic Kit",2891,0.7,0},
	{"Heat Pack",1576,1,0},
	{"Bandage",1578,0.5,0},
	{"Blood Bag",1580,1,0},
	{"Morphine",1579,1,0},
	{"Morphine Auto-Injector",14673,1,0},
	{"Blood Bag",1580,1,0},
	{"Medic Kit",2891,0.7,0},
	{"Blood Bag",1580,1,0},
	{"Painkiller",1580,1,0}
  }
}

for i,bpData in pairs(BackpacksTable)do
  table.insert(lootItems.helicrashsides,{bpData[1],bpData[3],1,0,bpData[4][5]})
end

for i,bpData in pairs(BackpacksTable)do
  table.insert(lootItems.bmpcrashsides,{bpData[1],bpData[3],1,0,bpData[4][5]})
end

--*************** NEW Helicrash *******************--
function createHeliCrashSite()
  if cargoCol then
	destroyElement(getElementData(cargoCol,"parent"))
	destroyElement(getElementData(cargoCol,"smoke"))
	destroyElement(cargoCol)
  end
  local item_id = math.random(#vehSpawns["heliCrash"])
  local x,y,z = vehSpawns["heliCrash"][item_id][1],vehSpawns["heliCrash"][item_id][2],vehSpawns["heliCrash"][item_id][3]
  smoke = createObject ( 1946, x, y, z - 1, 0, 0, 90 )  
  cargobob = createObject ( 1945, x, y, z - 1, 0, 0, 90 )
  blowVehicle(cargobob)
  outputChatBox("Spawn Helicrash",getRootElement(),255,255,255,true)
  setElementFrozen(cargobob,true)
  cargoCol = createColSphere(x,y,z,3)
  setElementData(cargoCol,"smoke",smoke)
  setElementData(cargoCol,"parent",cargobob)
  setElementData(cargoCol,"helicrash",true)
  setElementData(cargoCol,"MAX_Slots",0)
  for i,item in ipairs(lootItems.helicrashsides)do
	local value = math.percentChance(item[5] * 3.5,math.random(1,2))
	setElementData(cargoCol,item[1],value)
	local ammoData,weapID = getWeaponAmmoType(item[1])
	if ammoData ~= item[1] then
	  if ammoData and value > 0 then
		minBullets,maxBullets = math.floor(getAmmoPlus(ammoData)/3),getAmmoPlus(ammoData)*2
		ammoQuantity = math.random(minBullets,maxBullets)
		setElementData(cargoCol,ammoData,ammoQuantity)
	  end
	end
  end
  setTimer(createHeliCrashSite,3600000,1)
end
createHeliCrashSite()
--*************** NEW BMPCrash *******************--
function createBMPCrashSite()
  if cargoCol then
	destroyElement(getElementData(cargoCol,"parent"))
	destroyElement(getElementData(cargoCol,"smoke"))
	destroyElement(cargoCol)
  end
  local item_id = math.random(#vehSpawns["BMPCrash"])
  local x,y,z = vehSpawns["BMPCrash"][item_id][1],vehSpawns["BMPCrash"][item_id][2],vehSpawns["BMPCrash"][item_id][3]
  smoke = createObject ( 1946, x, y, z - 1, 0, 0, 90 )  
  cargobob = createObject ( 1944, x, y, z - 1, 0, 0, 90 )
  blowVehicle(cargobob)
  outputChatBox("Spawn BMPCrash",getRootElement(),255,255,255,true)
  setElementFrozen(cargobob,true)
  cargoCol = createColSphere(x,y,z,3)
  setElementData(cargoCol,"smoke",smoke)
  setElementData(cargoCol,"parent",cargobob)
  setElementData(cargoCol,"BMPCrash",true)
  setElementData(cargoCol,"MAX_Slots",0)
  for i,item in ipairs(lootItems.bmpcrashsides)do
	local value = math.percentChance(item[5] * 3.5,math.random(1,2))
	setElementData(cargoCol,item[1],value)
	local ammoData,weapID = getWeaponAmmoType(item[1])
	if ammoData ~= item[1] then
	  if ammoData and value > 0 then
		minBullets,maxBullets = math.floor(getAmmoPlus(ammoData)/3),getAmmoPlus(ammoData)*2
		ammoQuantity = math.random(minBullets,maxBullets)
		setElementData(cargoCol,ammoData,ammoQuantity)
	  end
	end
  end
  setTimer(createBMPCrashSite,1800000,1)
end
createBMPCrashSite()
---------------------------------------------
function updateHospitals()
  for i,box in pairs(hospitalCol)do
	for _,items in ipairs(lootItems.hospital)do
	  setElementData(hospitalCol[i],items[1],math.random(1,5))
	end
  end
  setTimer(updateHospitals,3600000,1)
end
hospitalCol = {}
function createHospitalPacks()
  number1 = 0
  for i,box in ipairs(hospitalPacks)do
	number1 = number1 + 1
	local x,y,z = box[1],box[2],box[3]
	object = createObject(1558,x,y,z,nil,nil,nil)
	hospitalCol[i] = createColSphere(x,y,z,2)
	setElementData(hospitalCol[i],"parent",object)
	setElementData(hospitalCol[i],"hospitalbox",true)
	setElementData(hospitalCol[i],"MAX_Slots",20)
	for _,items in ipairs(lootItems.hospital)do
	  local randomNumber = math.random(1,10)
	  if randomNumber >= 2 then
		setElementData(hospitalCol[i],items[1],math.random(1,5))
	  end
	end
  end
  setTimer(updateHospitals,3600000,1)
end
createHospitalPacks()

patrolCol = {}
for num,patrol in ipairs(patrolPoints) do
  local x,y,z = patrol[1],patrol[2],patrol[3]
  patrolCol[num] = createColSphere(x,y,z,3)
  setElementData(patrolCol[num],"patrolstation",true)
  local rand = math.random(1,15)
  if rand == 1 then
	lts = 100
  elseif rand == 2 or rand == 3 then
	lts = 80
  elseif rand >= 4 or rand <= 6 then
	lts = 60
  elseif rand >= 7 or rand <= 10 then
	lts = 40
  else
	lts = 20
  end
  setElementData(patrolCol[num],"patrollts",lts)
end

function updatepatrol()
  for i,box in pairs(patrolCol) do
	local rand = math.random(1,15)
	if rand == 1 then
	  lts = 100
	elseif rand == 2 or rand == 3 then
	  lts = 80
	elseif rand >= 4 or rand <= 6 then
	  lts = 60
	elseif rand >= 7 or rand <= 10 then
	  lts = 40
	else
	  lts = 20
	end
	setElementData(patrolCol[i],"patrollts",lts)
  end
end
setTimer(updatepatrol,10800000,0)

spawnedVehs = {}
function isVehSpawned(num)
  for _, numm in pairs(spawnedVehs)do
	if numm == num then
	  return true
	end
  end
  return false
end

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,120000,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,120000,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 getVehicleFuelRemove(veh,col)
  engine,tires,parts,rotor,glass,slots,fuel,fuelpm = getVehicleAddonInfos(getElementModel(veh))
  partstate = getElementData(col,"PartsState")
  if partstate < 10 then
	damaged = 2.3
  elseif partstate < 20 then
	damaged = 2
  elseif partstate < 40 then
	damaged = 1.7
  elseif partstate < 60 then
	damaged = 1.4
  elseif partstate < 80 then
	damaged = 1.1
  else
	damaged = 1
  end
  if getElementData(col,"Parts_inVehicle") == 0 then
	return fuelpm * 2.5
  else
	return fuelpm * damaged
  end
end

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

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)

l'erreur vient d'ici :

[19-07-18 18:58:03] ERROR: [DayZ-MTA]/DayZ/vehicle_spawns.Lua:362: attempt to get length of field '?' (a nil value)
[19-07-18 18:58:07] ERROR: [DayZ-MTA]/DayZ/vehicle_spawns.Lua:362: attempt to get length of field '?' (a nil value)
[19-07-18 18:58:13] ERROR: [DayZ-MTA]/DayZ/vehicle_spawns.Lua:362: attempt to get length of field '?' (a nil value) [DUP x2]

Share this post


Link to post

Bonsoir,

Où est le tableau "vehiclesTable" et "vehSpawns" ?

Actuellement, ton erreur veut simplement dire qu'il n'arrive pas à aller à la case de ton tableau.

Essaye de vérifier le contenu de tes tableaux et de vérifier si la case 1 est remplie, comme tu essayes d'y accéder.

  • Like 1

Share this post


Link to post

Ahh, exact! Après vérification de mes fichiers, j'avais fais une petite boulette 😛 merci de ton aide !

Share this post


Link to post

Aucun soucis, ça fait plaisir !

Bonne continuation et bon courage ;)

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

  • Recently Browsing   0 members

    No registered users viewing this page.