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
MOD - Stop Assembly Machine from working
Re: MOD - Stop Assembly Machine from working
Something like
Not tested. Tested.
See:
events.html#on_player_crafted_item
Concepts.html#SimpleItemStack
LuaRecipe.html#LuaRecipe.enabled
Modding help
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)
See:
events.html#on_player_crafted_item
Concepts.html#SimpleItemStack
LuaRecipe.html#LuaRecipe.enabled
Modding help
Re: MOD - Stop Assembly Machine from working
Hi darkfrei,
thank you for your fast answer.
I've not tested it yet, but I have a question to your code.
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?
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
Re: MOD - Stop Assembly Machine from working
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.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?
Re: MOD - Stop Assembly Machine from working
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.
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk