Locking a container
Posted: Sat Nov 30, 2024 8:26 pm
I'm trying to make a container that can be locked and unlocked. A locked container would not let inserters interact with it (or anything really).
My 'canister' is copied from the car prototype. This gives it other qualities I need, such as mobility, disabled collision and being drawn under other objects. As I need canisters to move, I can't set them to inactive.
Right now my solution is to look for inserters that target a canister and set their target to nil. This is very slow, and doesn't even really work as the inserters will find a target again right away. I tried setting the inserters inactive (and reactivating the next tick), but this gave the same result, and also slow. So I would have to check if the canister was far enough away to turn the inserter back on again - even slower.
I also tried setting the canister to active, teleporting it, and then deactivating it again, but it won't move like that. And letting it be active for any frame will let the inserter in. I know cargo wagons won't let inserters in while they're moving, but that prototype isn't suitable for a number of reasons.
My 'canister' is copied from the car prototype. This gives it other qualities I need, such as mobility, disabled collision and being drawn under other objects. As I need canisters to move, I can't set them to inactive.
Right now my solution is to look for inserters that target a canister and set their target to nil. This is very slow, and doesn't even really work as the inserters will find a target again right away. I tried setting the inserters inactive (and reactivating the next tick), but this gave the same result, and also slow. So I would have to check if the canister was far enough away to turn the inserter back on again - even slower.
Code: Select all
function test_disable_can_inserters(surface, event)
-- find all inserters of all kinds
local all_entities = surface.find_entities()
local inserters = {}
for _, entity in ipairs(all_entities) do
if string.find(entity.name, "nserter") then
table.insert(inserters, entity)
end
end
for _, inserter in pairs(inserters) do
if inserter.drop_target then
if inserter.drop_target.name == "canister" then
inserter.drop_target = nil
end
end
if inserter.pickup_target then
if inserter.pickup_target.name == "canister" then
inserter.pickup_target = nil
end
end
end
end