Code: Select all
function ammo.stowage_on_tick(event)
if event.tick % filling_time == 0 then
for _, surface in pairs(game.surfaces) do
local entitys = surface.find_entities_filtered{name = "v2-ammo-stowage"}
if next(entitys) == nil then return end
for _, entity in pairs(entitys) do
local chest_inventory = entity.get_inventory(defines.inventory.chest)
if chest_inventory.is_empty() then return end
if entity and entity.valid then
local position = entity.position
local radiu = entity_quality_radiu(entity)
for _,name in pairs(turrets) do
local turret_s = surface.find_entities_filtered{name = name, position = position, radius = radiu}
if next(turret_s) ~= nil then
for _, turret in pairs(turret_s) do
if turret and turret.valid
then ammo_loading(entity,turret)
end
end
end
end
end
end
end
end
end