eg.
Before I remove a player's personal roboports.
I'd like to collect(put in inventory) the personal construction robots that are flying.
A table of the robots and the stack it is holding/nil.
Thank you
Code: Select all
local function remove_robots(player)
-- position = player.position, area = -- Would be better for performance, but we might miss far away bots ..
local robots = game.surfaces[1].find_entities_filtered{force = player.force, type = "construction-robot"}
local inventories = {defines.inventory.robot_cargo, defines.inventory.robot_repair}
local robotcounter = 0
for _, r in ipairs(robots) do
if r.logistic_network.cells[1].mobile then -- TODO CHECK IF ROBOT IS FROM THIS PLAYER !!!!!!!!!!!!!
for _, inv in pairs(inventories) do -- We could use OR instead of LOOP if we were sure they are never used at the same time..
local itemStack = r.get_inventory(inv)[1]
if itemStack.valid then
player.insert(itemStack)
end
end
player.insert({name = r.name, count = 1})
r.destroy()
robotcounter = robotcounter +1
end
if r.logistic_network.available_construction_robots + robotcounter == r.logistic_network.all_construction_robots then
return
end
end
end
I'm able to find ALL flying construction robots (not ideal in a big map). But I see no way robot is part of a player's personal network.