Why does all my cars destroyed when i want to respawn them? I want to respawn them, not to destroy them totally
There are no errors in debugscript script
respawnlock = false
addEventHandler("onResourceStart", resourceRoot, function()
mainTimer = setTimer(respawnVehicles, 900000, 0)
end)
function respawnVehicles()
if not respawnlock then
respawnlock = true
exports.command:sendMessage("Respawning all unoccupied vehicles in 30 seconds!", 0, 255, 0, root)
setTimer ( function(msg, target, r, g, b) exports.command:sendMessage(msg, r, g, b, target) end , 10000, 1, "Respawning all unoccupied vehicles in 20 seconds!", getRootElement(), 0, 255, 0 )
setTimer ( function(msg, target, r, g, b) exports.command:sendMessage(msg, r, g, b, target) end, 20000, 1, "Respawning all unoccupied vehicles in 10 seconds!", getRootElement(), 0, 255, 0 )
setTimer ( function(msg, target, r, g, b) exports.command:sendMessage(msg, r, g, b, target) end, 25000, 1, "Respawning all unoccupied vehicles in 5 seconds!", getRootElement(), 0, 255, 0 )
setTimer ( vehrestask, 30000, 1)
resetTimer(mainTimer)
end
end
function respawnCommand(player)
if not respawnlock then
local accName = getAccountName(getPlayerAccount(player)) -- get his account name
if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- Does he have access to Admin functions?
respawnVehicles()
end
else
exports.command:sendMessage("*vehicles* Wait for the current respawn to end!", 0, 255, 0, player)
end
end
addCommandHandler("vehiclerespawn", respawnCommand)
function vehrestask()
local resVehicles = getElementsByType("vehicle")
for i,v in ipairs(resVehicles) do
local occupants = getVehicleOccupants(v) -- Get all vehicle occupants
local occupied = false
if occupants then
for seat, occupant in pairs(occupants) do
if occupant then
occupied = true
break
end
end
end
if getVehicleController(v) then
occupied = true
end
if not occupied then
if getElementID(getElementParent(getElementParent(v))) ~= "Admin" then
respawn = respawnVehicle(v)
if not respawn then
destroyElement(v)
else
destroyElement(v)
end
--[[elseif getElementData(v, "personalVehicle") then
exports.housing:vehicleRecache(v)]]--
else
if not getElementData(v, "personalVehicleID") then
destroyElement(v)
end
end
end
end
if getResourceState(getResourceFromName("publicvehicles")) == "running" then exports.publicvehicles:spawnPublicCars() end
exports.command:sendMessage("All unoccupied vehicles have been respawned!", 0, 255, 0, root)
respawnlock = false
end