Update recipes with new technologies:

Place to get help with not working mods / modding interface.
User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 172
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Update recipes with new technologies:

Post by DiegoPro77 »

Hi guys: the title says it all.
Example: you can create an iron gear wheel by using 2 iron plates.

If I wanted to create a technology that implemented a recipe that would use an iron plate for making a gear wheel, not as a new recipe, but as an overwrite to the pre-existing one (as to have a more clear inventory and apply instantly the changes in the game once the research is completed).

_Playmaker
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Update recipes with new technologies:

Post by darkfrei »

DiegoPro77 wrote: Thu Sep 17, 2020 3:13 pm Hi guys: the title says it all.
Example: you can create an iron gear wheel by using 2 iron plates.

If I wanted to create a technology that implemented a recipe that would use an iron plate for making a gear wheel, not as a new recipe, but as an overwrite to the pre-existing one (as to have a more clear inventory and apply instantly the changes in the game once the research is completed).

_Playmaker
You are need the control.lua
https://lua-api.factorio.com/latest/eve ... h_finished

It this technology was completed, then disable this recipe. Another recipe will be activated by the technology without control.lua.

Set the technology in the data stage like:

Code: Select all

data.raw["update-technology-1"].effects = {{type = "unlock-recipe", recipe = "assembling-machine-2"}}

Code: Select all

data.raw["update-technology-2"].effects = {{type = "unlock-recipe", recipe = "assembling-machine-3"}}

control.lua

Code: Select all

script.on_event(defines.events.on_research_finished, function(event)
  local tech= event.research
  if tech.name == "update-technology-1" then
      tech.force.recipes["assembling-machine-1"].enabled=false
  elseif tech.name == "update-technology-2" then
      tech.force.recipes["assembling-machine-2"].enabled=false
  end
end)
Also you can replace all am1 with am2 and am2 to am3.

https://wiki.factorio.com/Prototype/Technology
User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 172
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Update recipes with new technologies:

Post by DiegoPro77 »

Thank you man I'll see what I can do with this awelsome piece of code and sorry for the questions but lua is not properly my language. xD
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 172
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Update recipes with new technologies:

Post by DiegoPro77 »

And if I had a recipe and wanted to change an item required?

Iron gear wheel:
Iron plate, x1 -> Iron gear wheel

New recipe:
Iron rod, x1 -> Iron gear wheel

I've tried to understand and replicate Bob's method (as his way to code is very clear and powerful) but the game didn't "applied" the changes that I made.
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Update recipes with new technologies:

Post by darkfrei »

DiegoPro77 wrote: Sat Oct 03, 2020 9:41 pm And if I had a recipe and wanted to change an item required?

Iron gear wheel:
Iron plate, x1 -> Iron gear wheel

New recipe:
Iron rod, x1 -> Iron gear wheel

I've tried to understand and replicate Bob's method (as his way to code is very clear and powerful) but the game didn't "applied" the changes that I made.
You are need two recipes for it. Note that the new recipe must have unique name.

Code: Select all

  
data.extend({
  {
    type = "recipe",
    name = "iron-plate-to-iron-gear-wheel",
    ingredients = {{"iron-plate", 1}},
    result = "iron-gear-wheel"
  },
  {
    type = "recipe",
    name = "iron-rod-to-iron-gear-wheel",
    ingredients = {{"iron-rod", 1}},
    result = "iron-gear-wheel"
  },
})
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Update recipes with new technologies:

Post by darkfrei »

Sorry.

Some recipes have .normal and some of them have .expensive recipe difficult.
2020-10-04T00_11_11-D__Factorio_1.0_factorio-current.log - Notepad++.png
2020-10-04T00_11_11-D__Factorio_1.0_factorio-current.log - Notepad++.png (16.64 KiB) Viewed 2253 times
Just find how it was defined:

Code: Select all

data.raw.recipe["iron-gear-wheel"].normal.ingredients[1] = {"iron-plate", 2}
data.raw.recipe["iron-gear-wheel"].expensive.ingredients[1] = {"iron-plate", 4}
to

Code: Select all

data.raw.recipe["iron-gear-wheel"].normal.ingredients[1] = {"iron-rod", 2}
data.raw.recipe["iron-gear-wheel"].expensive.ingredients[1] = {"iron-rod", 4}

Code: Select all

data.raw.recipe["iron-gear-wheel"].normal.ingredients[1] = {"iron-rod", 2}
-- add another ingredients:
table.insert (data.raw.recipe["iron-gear-wheel"].normal.ingredients, {"tin-plate", 1})
table.insert (data.raw.recipe["iron-gear-wheel"].normal.ingredients, {"copper-screw", 4})

data.raw.recipe["iron-gear-wheel"].expensive.ingredients[1] = {"iron-rod", 4}
-- add another ingredients:
table.insert (data.raw.recipe["iron-gear-wheel"].expensive.ingredients, {"tin-plate", 2})
table.insert (data.raw.recipe["iron-gear-wheel"].expensive.ingredients, {"copper-screw", 8})
User avatar
DiegoPro77
Fast Inserter
Fast Inserter
Posts: 172
Joined: Tue Feb 20, 2018 1:40 pm
Contact:

Re: Update recipes with new technologies:

Post by DiegoPro77 »

Thank you darkfrei; one more thing...
If I wanted to remove / add a technology prerequisite, how can I do it?
Aka Playmaker. My mods: https://mods.factorio.com/user/77playmaker -|- My Discord Server: https://discord.gg/6NGYQdX
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Update recipes with new technologies:

Post by darkfrei »

DiegoPro77 wrote: Sun Oct 04, 2020 11:55 am Thank you darkfrei; one more thing...
If I wanted to remove / add a technology prerequisite, how can I do it?
Prerequisites are just a list of technologies.
2020-10-04T14_31_34-D__Factorio_1.0_factorio-current.log - Notepad++.png
2020-10-04T14_31_34-D__Factorio_1.0_factorio-current.log - Notepad++.png (37.8 KiB) Viewed 2200 times
You are need to remove the value from this list, for example as function:

Code: Select all

function remove_value_from_list (value, list)
	for i, v in pairs (list) do
		if v == value then 
			log ('removed: ' .. value) -- this writes the log into Factorio/factorio-current.log
			list[i] = nil 
		end
	end
end
So if you have the prerequisites as

Code: Select all

data.raw.technology["automation-2"].prerequisites = {"electronics", "steel-processing", "logistic-science-pack"}
then you can call this function as

Code: Select all

remove_value_from_list ("steel-processing", data.raw.technology["automation-2"].prerequisites)
and you get the list of prerequisites as:

Code: Select all

data.raw.technology["automation-2"].prerequisites = {"electronics", nil ,"logistic-science-pack"}
Here nil is nothing, removed value from list.

----------------------
Adding it back:

Code: Select all

table.insert (data.raw.technology["automation-2"].prerequisites, "steel-processing")
The result:

Code: Select all

data.raw.technology["automation-2"].prerequisites = {"electronics", nil ,"logistic-science-pack", "steel-processing"}
Post Reply

Return to “Modding help”