Page 1 of 1

[Done] Recipe Complete Trigger

Posted: Thu Mar 08, 2018 5:14 pm
by TheSAguy
Hi,
Is there a trigger for on recipe complete?
Where can I go to search for all triggers?

I’d like to create a building that has 3 recipes and does the following:

Recipe 1: Plant trees (in a radius around the building.)
So you’ll have a recipe that uses seeds and each time the recipe completes it will plant the tree.

Recipe 2: Change terrain, using fertilizer (in a radius around the building.)
This recipe will take fertilizer and per completion, look at the terrain, if it’s not grass, change it to grass. (exclude water)

Recipe 3: Do both Recipes 1 & 2 at the same time.
Do both above.



I’m thinking that the easies way to do this would be to use an “On Recipe Complete” trigger if it exists.
The recipe would produce nothing itself, I’ll just use the trigger.
If there is not a on recipe complete trigger, then I’ll use a on_tick or sector scanned and perform the above.


I was thinking that the best way to handle some of the code would be to read all the terrain in a certain radius around the building into a table when you place the building. Then per recipe complete, start at the top of the table and check if it’s valid, if valid, perform action, if not, go to next. Thoughts on this?

Any inputs on how to improve this.
I think I know how to do 90% of this code and will post it once I have it.

Input appreciated.
Thanks,

Re: Recipe Complete Trigger

Posted: Thu Mar 08, 2018 5:38 pm
by eradicator
For perfomance reasons assembling-machines do not raise events for crafting things. You'll have to use on_tick or on_nth_tick. The list of all available events is on the api pages http://lua-api.factorio.com/latest/events.html .

Assembling machines have products_finished which might still be of some use to see if and how many times a recipe completed (i.e. if the machine might not craft when low on power).

I remember there was another mod on the mod portal that grows trees, might be worth a look (i haven't used it so no idea how (good) it works). https://mods.factorio.com/mod/Noxys_Trees

Re: Recipe Complete Trigger

Posted: Thu Mar 08, 2018 5:53 pm
by TheSAguy
Thanks for the feedback Eradicator.

My mod already grows the trees, so got that part covered.

Okay, so I'm leaning towards adding a radar entity and using the "on_Sector_scanned" That will also cover me for the low power that I did not think of on on_tick.

I will just deduct the inventory if it exists.
So since I have 3 recipe's, is there a way to read what recipe is currently selected?

Re: Recipe Complete Trigger

Posted: Fri Mar 09, 2018 2:24 am
by eradicator
ctrl+f "recipe" on this page: http://lua-api.factorio.com/latest/Classes.html
-> LuaEntity.get_recipe()