Adjust an items recipe in an existing game

Place to get help with not working mods / modding interface.
girthworm
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Mar 02, 2019 2:02 am
Contact:

Adjust an items recipe in an existing game

Post by girthworm »

I'm curious if there's a way I can base a mod's recipe values on a sort of "global" variable that changes throughout gameplay?

From what I saw in posts ~4 years ago this was not possible through means of changing the game difficulty, and therefore not possible at all. Mostly just looking for a push in the right direction, though I'll take as much help as I can get!
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Adjust an items recipe in an existing game

Post by DaveMcW »

It's still not possible to change a recipe during the game.

You could define multiple recipes with every possible value, and enable/disable the correct one during the game. Note that this involves search/replacing every assembling machine recipe.
girthworm
Manual Inserter
Manual Inserter
Posts: 3
Joined: Sat Mar 02, 2019 2:02 am
Contact:

Re: Adjust an items recipe in an existing game

Post by girthworm »

Okay so yeah that probably wont work. So far I have a 10gb json file with 4/96 of the recipes and their values I want to use.

Yikes.

Thinking my dreams might have to die today
Hiladdar
Fast Inserter
Fast Inserter
Posts: 214
Joined: Mon May 14, 2018 6:47 pm
Contact:

Re: Adjust an items recipe in an existing game

Post by Hiladdar »

I am playing around with that right now. I am currently working on a new mod which does something very similar with accumulators, solar panels and big electric poles.

Although it is probably not possible to change the recipe once the game is fully loaded, but it is possible to write a mod in such a way that the recipe will be dynamically adjusted based on the powerful the solar panels are between tiers. That can be changed based on during the time the mod is loaded into memory. I just finished the solar panels and recipe will be dependent on how effective the solar panel will be. I expect this to be finished within about 1-2 days with maybe another 1-2 days of some testing. The name of the mod will be Hiladdar Electronics. Once it is up, feel free to download it, and take a look at how this is accomplished.

What you are attempting to do is a bit beyond what I am about to finish. One challenge you will have is how to store that value between gaming sessions. A second change storing that within the game during the gaming session. Finally a third challenge is updating the recipe during the game.

Of the top of my head, with what little I know about programming and Factorio, one way to store create the global parameters within the .json files which can be used to calculate the recipe. The recalculation should be a triggered event, such as number of biters dead, or number of trees burned down, or number of gears crafted. It is best to use something that is already tracked by Factorio. Then you will need identify the right event trigger to use to trigger your update. Finally to do the update you would need to have a function which issues the correct data.raw commend as a console command. My recommendation is to identify the formula or algorithm that redefines the recipe, then write a function that creates the string programmatically, such as:
'{ {type="fluid", name="crude-oil", amount=10}, {type="fluid", name="water", amount=5} }'. Finally you will need to post this change to the data.raw data structure. ../doc-html/LuaRecipe.html distributed within factorio and ../doc-html/events.html documents the recipe data structure and events available to us as developers. If recipes can be updated via the console, then it just might be possible.

One mod I would seriously take a look at is "console-extended-0.17.2" released a short time ago, since it adds a number of console command, and changing a recipe mid-session would be something like that. Any mod that keeps track of data is another great candidate to study. Off the top of my head in that category, I also recommend taking a look at what "MxlChievments_1.1.3" does.

Hiladdar
Post Reply

Return to “Modding help”