Jump to content

Problema com Respawn de Veículos


Recommended Posts

Olá boa noite, me deparei com o seguinte erro em meu servidor, ja venho quebrando a cabeça, até pensei que fosse uma propria função no inventário, porém não é.

seguinte, todos os carros do servidor tem espaço para guardar loot dentro dele, porém quando esse carro acaba explodindo, ao respawnar de novo, ele vem sem slots, vem 0/0.

 

meu vehicle_spawns.lua

se alguem puder me ajudar, por favor ..

 

lootItems = {
  helicrashsides = {
	{"Compass",1851,1,0,2},
	{"Scrap Metal",1577,1,0,3},
	{"Stinger",2899,0.3,0,3},
	{"Tire Repair Kit",2015,0.5,0,4},
	{"Hose",1880,0.5,0,6},
	{"Syringe",2000,1,0,6},
	{"Night Vision Goggles",368,1,90,10},
	{"Box of Matches",328,0.4,90,2},
	{"Hunting Knife",335,1,90,4},
	{"Chainsaw",341,1,90,4},
	{"Hatchet",339,1,90,3},
	{"Pizza",1582,1,0,2},
	{"Soda Bottle",2647,1,0,2},
	{"Empty Gas Canister",1650,1,0,2},
	{"Roadflare",324,1,90,2},
	{"Grenade",342,1,0,2},
	{"Parachute",342,1,0,2},
	{"Watch",2710,1,0,4},
	{"Crossbow",357,1,90,6},
	{"Night Vision Goggles",368,1,90,1.5},
	{"Tire",1073,1,0,2},
	{"GPS",2976,0.15,0,3},
	{"Map",1277,0.8,90,7},
	{"Toolbox",2969,0.5,0,1},
	{"Engine",929,0.3,0,2},
	{"Main Rotor Assembly",929,0.3,0,2},
	{"Tent",1279,1,0,3.5},
	{"Infrared Goggles",369,1,90,3},
  },
  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},
	{"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

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)
	setObjectScale(object,1)
	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 >= 5 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)

function spawnDayZVehicles()
	for _, data in ipairs(vehicleSpawns) do
		veh = createVehicle(data[1],data[2],data[3],data[4])
		vehCol = createColSphere(data[2],data[3],data[4],2.5)
		attachElements(vehCol,veh,0,0,0)
		setElementData(vehCol,"parent",veh)
		setElementData(veh,"parent",vehCol)
		setElementData(vehCol,"vehicle",true)
		local tires,engine,parts = getVehicleAddonInfos(getElementModel(veh))
		setElementData(vehCol,"Tire_inVehicle",math.random(0,tires))
		setElementData(vehCol,"Engine_inVehicle",math.random(0,engine))
		setElementData(vehCol,"Parts_inVehicle",math.random(0,parts))
		
		setElementData(vehCol,"Tire_inVehicle_HP",400)
		setElementData(vehCol,"Engine_inVehicle_HP",400)
		setElementData(vehCol,"Parts_inVehicle_HP",400)
		setElementData(vehCol,"armorPointsMax",data[6])
		setElementData(vehCol,"armorPoints",0)
		setElementData(vehCol,"vehicle:station",0)
		setElementData(vehCol,"receiver",0)
		
		setVehicleHeadLightColor(veh,math.random(0,255),math.random(0,255),math.random(0,255))
		
		setElementData(vehCol,"fuel",10)
		setElementData(vehCol,"MAX_Slots",data[5])
		setElementData(vehCol,"spawn",{data[1],data[2],data[3],data[4]})
	end
end

function spawnVehiclePack(ps,cmd)
	if getElementData(ps,"admin") then
		spawnDayZVehicles()
		outputChatBox("SVP Sucess!",ps,8, 193, 207,true)
	end	
end
addCommandHandler("svp",spawnVehiclePack)

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,1800000,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,1800000,0)

function respawnDayZVehicle(id,x,y,z,veh,col,max_slots)
	local armorMax = getElementData(col,"armorPointsMax")
	destroyElement(veh)
	destroyElement(col)
	veh = createVehicle(id,x,y,z+1)
	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",max_slots)
	--Engine + Tires
	local tires,engine,parts = getVehicleAddonInfos (getElementModel(veh))
	setElementData(vehCol,"Tire_inVehicle",math.random(0,tires))
	setElementData(vehCol,"Engine_inVehicle",math.random(0,engine))
	setElementData(vehCol,"Parts_inVehicle",math.random(0,parts))
	
	setElementData(vehCol,"Tire_inVehicle_HP",400)
	setElementData(vehCol,"Engine_inVehicle_HP",400)
	setElementData(vehCol,"Parts_inVehicle_HP",400)
	setElementData(vehCol,"armorPointsMax",armorMax)
	setElementData(vehCol,"armorPoints",0)
	
	setVehicleHeadLightColor(veh,math.random(0,255),math.random(0,255),math.random(0,255))
	
	setElementData(vehCol,"receiver",0)
	setElementData(vehCol,"vehicle:station",0)
	--vehicle_indentifikation
	setElementData(vehCol,"spawn",{id,x,y,z})
	--others
	setElementData(vehCol,"fuel",10)
end

function onPlayerEnterDayzVehicle(veh,seat)
	local col = getElementData(veh,"parent")
	local id = getElementModel(veh)
	local tires,engine,parts = getVehicleAddonInfos (id)
	setElementData(veh,"maxfuel",getVehicleMaxFuel(col))
	setElementData(veh,"needtires",tires)
	setElementData(veh,"needengine",engine)
	setElementData(veh,"needparts",parts)
	if ((getElementData(col,"Tire_inVehicle") or 0) < tonumber(tires)) then
		setVehicleEngineState(veh,false)
		return
	end
	if ((getElementData(col,"Engine_inVehicle") or 0) < tonumber(engine)) then
		setVehicleEngineState(veh,false)
		return
	end
	if ((getElementData(col,"Parts_inVehicle") or 0) < tonumber(parts)) then
		setVehicleEngineState(veh,false)
		return
	end
	if (getElementData(col,"fuel") or 0) <= 1 then
		if not getElementModel(veh) == 510 then
			setVehicleEngineState(veh,false)
			return
		end
	end
end
addEventHandler("onPlayerVehicleEnter",getRootElement(),onPlayerEnterDayzVehicle)

function setEngineState(player,key,keyState)
	local theVehicle = getPedOccupiedVehicle(player)
    if theVehicle and getVehicleController(theVehicle) == player then
		if checkVehicleMovable(theVehicle) then
			setVehicleEngineState(theVehicle, not getVehicleEngineState(theVehicle))
		end	
    end	
end

function checkVehicleMovable(veh)
	if isElement(veh) then
		local parent = getElementData(veh,"parent") 
		if parent then
			if ((getElementData(parent,"Tire_inVehicle") or 0) ~= getElementData(veh,"needtires")) then
				setVehicleEngineState(veh,false)
				return false
			end
			if ((getElementData(parent,"Engine_inVehicle") or 0) ~= getElementData(veh,"needengine")) then
				setVehicleEngineState(veh,false)
				return false
			end
			if ((getElementData(parent,"Parts_inVehicle") or 0) ~= getElementData(veh,"needparts")) then 
				setVehicleEngineState (veh,false) 
				return false
			end
			return true
		end	
	end	
end

function onPlayerExitDayzVehicle(veh,seat)
	if seat == 0 then
		setVehicleEngineState (veh,false)
	end
	unbindKey(source,"k","down",setEngineState)
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

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

function fixVehicleDayZ(veh,player)
	setElementHealth(veh,1000)
	fixVehicle (veh)
	setPedAnimation(player,false)
	setElementFrozen (veh,false)
	setVehicleDamageProof (veh,false)
	repairTimer[veh] = nil
	setElementData(veh,"repairer",nil)
	setElementData(player,"repairingvehicle",nil)
	triggerClientEvent (player, "displayClientInfo", player,"Vehicle","You have completed repairs!",255,0,0)
end

function stopFixxingWhileMoving()
	local veh = getElementData(source,"repairingvehicle")
	setPedAnimation(source)
	setElementFrozen (veh,false)
	setVehicleDamageProof (veh,false)
	setElementData(veh,"repairer",nil)
	setElementData(source,"repairingvehicle",nil)
	setElementData(source,"Repairing",false)
	triggerClientEvent (source, "displayClientInfo", source,"Vehicle","You stopped the repair!",255,0,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
			setVehicleDamageProof (veh,false)
			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)

 

Link to comment
On 29/10/2018 at 00:35, Lukkas2201 said:

Olá boa noite, me deparei com o seguinte erro em meu servidor, ja venho quebrando a cabeça, até pensei que fosse uma propria função no inventário, porém não é.

seguinte, todos os carros do servidor tem espaço para guardar loot dentro dele, porém quando esse carro acaba explodindo, ao respawnar de novo, ele vem sem slots, vem 0/0.

 

meu vehicle_spawns.lua

se alguem puder me ajudar, por favor ..

 


lootItems = {
  helicrashsides = {
	{"Compass",1851,1,0,2},
	{"Scrap Metal",1577,1,0,3},
	{"Stinger",2899,0.3,0,3},
	{"Tire Repair Kit",2015,0.5,0,4},
	{"Hose",1880,0.5,0,6},
	{"Syringe",2000,1,0,6},
	{"Night Vision Goggles",368,1,90,10},
	{"Box of Matches",328,0.4,90,2},
	{"Hunting Knife",335,1,90,4},
	{"Chainsaw",341,1,90,4},
	{"Hatchet",339,1,90,3},
	{"Pizza",1582,1,0,2},
	{"Soda Bottle",2647,1,0,2},
	{"Empty Gas Canister",1650,1,0,2},
	{"Roadflare",324,1,90,2},
	{"Grenade",342,1,0,2},
	{"Parachute",342,1,0,2},
	{"Watch",2710,1,0,4},
	{"Crossbow",357,1,90,6},
	{"Night Vision Goggles",368,1,90,1.5},
	{"Tire",1073,1,0,2},
	{"GPS",2976,0.15,0,3},
	{"Map",1277,0.8,90,7},
	{"Toolbox",2969,0.5,0,1},
	{"Engine",929,0.3,0,2},
	{"Main Rotor Assembly",929,0.3,0,2},
	{"Tent",1279,1,0,3.5},
	{"Infrared Goggles",369,1,90,3},
  },
  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},
	{"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

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)
	setObjectScale(object,1)
	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 >= 5 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)

function spawnDayZVehicles()
	for _, data in ipairs(vehicleSpawns) do
		veh = createVehicle(data[1],data[2],data[3],data[4])
		vehCol = createColSphere(data[2],data[3],data[4],2.5)
		attachElements(vehCol,veh,0,0,0)
		setElementData(vehCol,"parent",veh)
		setElementData(veh,"parent",vehCol)
		setElementData(vehCol,"vehicle",true)
		local tires,engine,parts = getVehicleAddonInfos(getElementModel(veh))
		setElementData(vehCol,"Tire_inVehicle",math.random(0,tires))
		setElementData(vehCol,"Engine_inVehicle",math.random(0,engine))
		setElementData(vehCol,"Parts_inVehicle",math.random(0,parts))
		
		setElementData(vehCol,"Tire_inVehicle_HP",400)
		setElementData(vehCol,"Engine_inVehicle_HP",400)
		setElementData(vehCol,"Parts_inVehicle_HP",400)
		setElementData(vehCol,"armorPointsMax",data[6])
		setElementData(vehCol,"armorPoints",0)
		setElementData(vehCol,"vehicle:station",0)
		setElementData(vehCol,"receiver",0)
		
		setVehicleHeadLightColor(veh,math.random(0,255),math.random(0,255),math.random(0,255))
		
		setElementData(vehCol,"fuel",10)
		setElementData(vehCol,"MAX_Slots",data[5])
		setElementData(vehCol,"spawn",{data[1],data[2],data[3],data[4]})
	end
end

function spawnVehiclePack(ps,cmd)
	if getElementData(ps,"admin") then
		spawnDayZVehicles()
		outputChatBox("SVP Sucess!",ps,8, 193, 207,true)
	end	
end
addCommandHandler("svp",spawnVehiclePack)

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,1800000,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,1800000,0)

function respawnDayZVehicle(id,x,y,z,veh,col,max_slots)
	local armorMax = getElementData(col,"armorPointsMax")
	destroyElement(veh)
	destroyElement(col)
	veh = createVehicle(id,x,y,z+1)
	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",max_slots)
	--Engine + Tires
	local tires,engine,parts = getVehicleAddonInfos (getElementModel(veh))
	setElementData(vehCol,"Tire_inVehicle",math.random(0,tires))
	setElementData(vehCol,"Engine_inVehicle",math.random(0,engine))
	setElementData(vehCol,"Parts_inVehicle",math.random(0,parts))
	
	setElementData(vehCol,"Tire_inVehicle_HP",400)
	setElementData(vehCol,"Engine_inVehicle_HP",400)
	setElementData(vehCol,"Parts_inVehicle_HP",400)
	setElementData(vehCol,"armorPointsMax",armorMax)
	setElementData(vehCol,"armorPoints",0)
	
	setVehicleHeadLightColor(veh,math.random(0,255),math.random(0,255),math.random(0,255))
	
	setElementData(vehCol,"receiver",0)
	setElementData(vehCol,"vehicle:station",0)
	--vehicle_indentifikation
	setElementData(vehCol,"spawn",{id,x,y,z})
	--others
	setElementData(vehCol,"fuel",10)
end

function onPlayerEnterDayzVehicle(veh,seat)
	local col = getElementData(veh,"parent")
	local id = getElementModel(veh)
	local tires,engine,parts = getVehicleAddonInfos (id)
	setElementData(veh,"maxfuel",getVehicleMaxFuel(col))
	setElementData(veh,"needtires",tires)
	setElementData(veh,"needengine",engine)
	setElementData(veh,"needparts",parts)
	if ((getElementData(col,"Tire_inVehicle") or 0) < tonumber(tires)) then
		setVehicleEngineState(veh,false)
		return
	end
	if ((getElementData(col,"Engine_inVehicle") or 0) < tonumber(engine)) then
		setVehicleEngineState(veh,false)
		return
	end
	if ((getElementData(col,"Parts_inVehicle") or 0) < tonumber(parts)) then
		setVehicleEngineState(veh,false)
		return
	end
	if (getElementData(col,"fuel") or 0) <= 1 then
		if not getElementModel(veh) == 510 then
			setVehicleEngineState(veh,false)
			return
		end
	end
end
addEventHandler("onPlayerVehicleEnter",getRootElement(),onPlayerEnterDayzVehicle)

function setEngineState(player,key,keyState)
	local theVehicle = getPedOccupiedVehicle(player)
    if theVehicle and getVehicleController(theVehicle) == player then
		if checkVehicleMovable(theVehicle) then
			setVehicleEngineState(theVehicle, not getVehicleEngineState(theVehicle))
		end	
    end	
end

function checkVehicleMovable(veh)
	if isElement(veh) then
		local parent = getElementData(veh,"parent") 
		if parent then
			if ((getElementData(parent,"Tire_inVehicle") or 0) ~= getElementData(veh,"needtires")) then
				setVehicleEngineState(veh,false)
				return false
			end
			if ((getElementData(parent,"Engine_inVehicle") or 0) ~= getElementData(veh,"needengine")) then
				setVehicleEngineState(veh,false)
				return false
			end
			if ((getElementData(parent,"Parts_inVehicle") or 0) ~= getElementData(veh,"needparts")) then 
				setVehicleEngineState (veh,false) 
				return false
			end
			return true
		end	
	end	
end

function onPlayerExitDayzVehicle(veh,seat)
	if seat == 0 then
		setVehicleEngineState (veh,false)
	end
	unbindKey(source,"k","down",setEngineState)
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

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

function fixVehicleDayZ(veh,player)
	setElementHealth(veh,1000)
	fixVehicle (veh)
	setPedAnimation(player,false)
	setElementFrozen (veh,false)
	setVehicleDamageProof (veh,false)
	repairTimer[veh] = nil
	setElementData(veh,"repairer",nil)
	setElementData(player,"repairingvehicle",nil)
	triggerClientEvent (player, "displayClientInfo", player,"Vehicle","You have completed repairs!",255,0,0)
end

function stopFixxingWhileMoving()
	local veh = getElementData(source,"repairingvehicle")
	setPedAnimation(source)
	setElementFrozen (veh,false)
	setVehicleDamageProof (veh,false)
	setElementData(veh,"repairer",nil)
	setElementData(source,"repairingvehicle",nil)
	setElementData(source,"Repairing",false)
	triggerClientEvent (source, "displayClientInfo", source,"Vehicle","You stopped the repair!",255,0,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
			setVehicleDamageProof (veh,false)
			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)

 

Não achei a parte que spawna os veículos exemplo do que eu quero dizer:

 

	for i,veh in ipairs(patriotSpawns) do
		local x,y,z = veh[1],veh[2],veh[3]
		veh = createVehicle(470,x,y,z)
		vehCol = createColSphere(x,y,z,2.5)
		attachElements ( vehCol, veh, 0, 0, 0 )
		setElementData(vehCol,"parent",veh)
		setElementData(veh,"parent",vehCol)
		setElementData(vehCol,"vehicle",true)
		setElementData(vehCol,"MAX_Slots",38)
		--Engine + Tires
		local tires,engine = getVehicleAddonInfos (getElementModel(veh))
		setElementData(vehCol,"Tire_inVehicle",math.random(0,tires))
		setElementData(vehCol,"Engine_inVehicle",math.random(0,engine))
		--vehicle_indentifikation
		setElementData(vehCol,"spawn",{470,x,y,z})
		--others
		setElementData(vehCol,"fuel",10)
		for i,items in ipairs(lootItems["helicrashsides"]) do
			local randomNumber = math.random(1,10)
			if randomNumber == 5 then
				setElementData(vehCol,items[1],1)
			end
		end
	end

No caso ai, quando o veículo explode, ele da um loop na tabela do helicrashsides e seta no veículo porém o helicrash pode vir vazio também, e eu não sei o valor que você esta utilizando no math.random, eu testei aqui no meu explodi várias vezes o patriot e ele spawna com itens dentro, talvez você modificou algo e esqueceu, tenta fazer algo igual eu passei acima no exemplo.

Edited by OverKILL
Link to comment
4 hours ago, OverKILL said:

Não achei a parte que spawna os veículos exemplo do que eu quero dizer:

 


	for i,veh in ipairs(patriotSpawns) do		local x,y,z = veh[1],veh[2],veh[3]		veh = createVehicle(470,x,y,z)		vehCol = createColSphere(x,y,z,2.5)		attachElements ( vehCol, veh, 0, 0, 0 )		setElementData(vehCol,"parent",veh)		setElementData(veh,"parent",vehCol)		setElementData(vehCol,"vehicle",true)		setElementData(vehCol,"MAX_Slots",38)		--Engine + Tires		local tires,engine = getVehicleAddonInfos (getElementModel(veh))		setElementData(vehCol,"Tire_inVehicle",math.random(0,tires))		setElementData(vehCol,"Engine_inVehicle",math.random(0,engine))		--vehicle_indentifikation		setElementData(vehCol,"spawn",{470,x,y,z})		--others		setElementData(vehCol,"fuel",10)		for i,items in ipairs(lootItems["helicrashsides"]) do			local randomNumber = math.random(1,10)			if randomNumber == 5 then				setElementData(vehCol,items[1],1)			end		end	end

No caso ai, quando o veículo explode, ele da um loop na tabela do helicrashsides e seta no veículo porém o helicrash pode vir vazio também, e eu não sei o valor que você esta utilizando no math.random, eu testei aqui no meu explodi várias vezes o patriot e ele spawna com itens dentro, talvez você modificou algo e esqueceu, tenta fazer algo igual eu passei acima no exemplo.

Obrigado amigo, vi realmente que estava dando loop no helicrash, anulei a função e adicionei outra por cima e deu certo, obrigado !!

Link to comment

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