Avoid keying a table by LuaEntity
This commit is contained in:
parent
44b4625518
commit
feaa3e7ba6
|
@ -1,4 +1,9 @@
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
|
Version: 1.0.2
|
||||||
|
Date: 20.09.2024
|
||||||
|
Changes:
|
||||||
|
- Avoid keying a table by LuaEntity, use LuaEntity.unit_number instead
|
||||||
|
---------------------------------------------------------------------------------------------------
|
||||||
Version: 1.0.1
|
Version: 1.0.1
|
||||||
Date: 18.09.2024
|
Date: 18.09.2024
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -13,7 +13,7 @@ script.on_init(function()
|
||||||
global.active = {}
|
global.active = {}
|
||||||
global.active.mining_drills = {} -- [Tick:Entity]
|
global.active.mining_drills = {} -- [Tick:Entity]
|
||||||
global.passive = {}
|
global.passive = {}
|
||||||
global.passive.mining_drills = {} -- [Entity:true]
|
global.passive.mining_drills = {} -- [Entity.unit_number:Entity]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
script.on_load(function()
|
script.on_load(function()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Teardown",
|
"name": "Teardown",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"title": "Teardown",
|
"title": "Teardown",
|
||||||
"description": "Automate the removal of depleted miners",
|
"description": "Automate the removal of depleted miners",
|
||||||
"author": "David Skrundz",
|
"author": "David Skrundz",
|
||||||
|
|
|
@ -11,7 +11,7 @@ function on_active_tick(event)
|
||||||
if status == defines.entity_status.no_minable_resources then
|
if status == defines.entity_status.no_minable_resources then
|
||||||
miner.order_deconstruction(miner.force, nil)
|
miner.order_deconstruction(miner.force, nil)
|
||||||
elseif status ~= defines.entity_status.working then
|
elseif status ~= defines.entity_status.working then
|
||||||
passive_mining_drills[miner] = true
|
passive_mining_drills[miner.unit_number] = miner
|
||||||
script.on_nth_tick(passive_tick, on_passive_tick)
|
script.on_nth_tick(passive_tick, on_passive_tick)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,17 +26,17 @@ end
|
||||||
function on_passive_tick(event)
|
function on_passive_tick(event)
|
||||||
local passive_mining_drills = global.passive.mining_drills
|
local passive_mining_drills = global.passive.mining_drills
|
||||||
|
|
||||||
for miner, _ in pairs(passive_mining_drills) do
|
for id, miner in pairs(passive_mining_drills) do
|
||||||
if miner.valid then
|
if miner.valid then
|
||||||
local status = miner.status
|
local status = miner.status
|
||||||
if status == defines.entity_status.no_minable_resources then
|
if status == defines.entity_status.no_minable_resources then
|
||||||
miner.order_deconstruction(miner.force, nil)
|
miner.order_deconstruction(miner.force, nil)
|
||||||
passive_mining_drills[miner] = nil
|
passive_mining_drills[id] = nil
|
||||||
elseif status == defines.entity_status.working then
|
elseif status == defines.entity_status.working then
|
||||||
passive_mining_drills[miner] = nil
|
passive_mining_drills[id] = nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
passive_mining_drills[miner] = nil
|
passive_mining_drills[id] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue