Page 1 of 1
MOD - Stop Assembly Machine from working
Posted: Fri May 11, 2018 8:47 am
by NeXuS
Hi,
and another question I hope you can help me with.
How can I stop an assembly-machine entity from crafting, when a certain global number of the product is reached, even though the machine has all available ingredients?
I don't want to use the signal network for this, just implementing a check against a global variable.
Inside the API I've found something like on_pre_player_crafted_item but this is only the starting event for manual crafting. Is there an event for machine crafting as well?
Best wishes
NeXuS
Re: MOD - Stop Assembly Machine from working
Posted: Fri May 11, 2018 10:22 am
by darkfrei
Something like
Code: Select all
script.on_event(defines.events.on_player_crafted_item, function(event)
local item_stack = event.item_stack
if (item_stack.name == 'assembling-machine-1') then
if not global then global = {} end
if not global.crafted then global.crafted = 0 end
global.crafted = global.crafted + 1
if global.crafted > 5 then
event.recipe.enabled = false
end
end
end)
Not tested. Tested.
See:
events.html#on_player_crafted_item
Concepts.html#SimpleItemStack
LuaRecipe.html#LuaRecipe.enabled
Modding help
Re: MOD - Stop Assembly Machine from working
Posted: Sat May 12, 2018 11:34 am
by NeXuS
Hi darkfrei,
thank you for your fast answer.
I've not tested it yet, but I have a question to your code.
Code: Select all
if global.crafted > 5 then
event.recipe.enabled = false
end
If my amount of items drops below five and I re-enable that recipe, do I have to reset the recipe inside the assembling machines or is it just reactivated and works normal without user interaction?
Re: MOD - Stop Assembly Machine from working
Posted: Sat May 12, 2018 1:46 pm
by darkfrei
NeXuS wrote:If my amount of items drops below five and I re-enable that recipe, do I have to reset the recipe inside the assembling machines or is it just reactivated and works normal without user interaction?
The code must be much complex than above. You can also click spamming on the recipe and get 100 assembling machines instead of 5. You can also clicking with RMB and get 5 items, not only one.
Re: MOD - Stop Assembly Machine from working
Posted: Mon Mar 18, 2019 4:50 pm
by robot256
Normally I use the "connect to logistics network" function on the output inserters to tell it when to stop putting them in a provider chest. This doesn't require wires, and makes sure there are at least a certain number available in the network. Sounds like you might have a different need though.