Page 1 of 1
How can I go about manipulating the craft queue?
Posted: Tue Nov 05, 2019 12:26 pm
by PEBKAC
I want to change things in the crafting queue. When the player crafts, say, 5 inserters, first all gears for the 5 inserters are made, then all 5 circuits, then the 5 inserters. I want to break this up from batched production to piecemeal production, but since this is my first modding attempt, I'm a little stumped on how to do certain things. Other mods (and at least the tutorials I've worked through) don't seem to do what I want to do.
So I've managed to tap into the on_pre_player_crafted_item event. Now, I want to
- see how many of a thing were ordered (doesn't seem to be on the event natively, but I think I can work this out).
- Nullify this event (no idea how to do this), and
- Send out X individual crafting requests (again, no idea).
Any ideas on how to accomplish this? Any references I might check out to help me further here?
Re: How can I go about manipulating the craft queue?
Posted: Thu Nov 07, 2019 12:23 am
by Hermitude
Hello and congrats on your first mod project.
The API has methods for accessing the crafting queue. (TBH I have not used these myself though.)
Take a look at:
LuaControl
Code: Select all
LuaControl.get_craftable_count
LuaControl.begin_crafting
LuaControl.cancel_crafting
LuaControl.crafting_queue_size
LuaControl.crafting_queue
LuaControl.character_crafting_speed_modifier
LuaControl.crafting_speed
LuaControl.crafting_progress
Since LuaPlayer (the player character) inherits from LuaControl, you can use these fields like:
Code: Select all
if (game.player.crafting_queue_size > x) then
-- your code here
end
To solve your problem more generally, you will probably also want to have a look at the recipes:
LuaRecipePrototype
You can get the game's recipe prototypes from:
If you are new to the whole API itself, you should probably bookmark the following:
Factorio API
LuaGameScript
The latter is the class that provides the `game` object that started off my examples above. For much of the "callable" game logic, `game' is the starting point to the entire API.
Enjoy!
Re: How can I go about manipulating the craft queue?
Posted: Thu Nov 07, 2019 6:33 am
by dog80
just a sidenote: then we also need a way to cancel all recipes with 1 action, instead of this mindless hundret times clicking to cancel all these single orders
Re: How can I go about manipulating the craft queue?
Posted: Thu Nov 07, 2019 7:48 pm
by Hermitude
dog80 wrote: ↑Thu Nov 07, 2019 6:33 am
just a sidenote: then we also need a way to cancel all recipes with 1 action, instead of this mindless hundret times clicking to cancel all these single orders
This would also be a very easy mod to make. Please feel free to try it out! If you need any assistance, just ask in this thread.