Page 1 of 1
Update recipes with new technologies:
Posted: Thu Sep 17, 2020 3:13 pm
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
Re: Update recipes with new technologies:
Posted: Thu Sep 17, 2020 9:11 pm
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
Re: Update recipes with new technologies:
Posted: Mon Sep 21, 2020 4:13 pm
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
Re: Update recipes with new technologies:
Posted: Sat Oct 03, 2020 9:41 pm
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.
Re: Update recipes with new technologies:
Posted: Sat Oct 03, 2020 10:07 pm
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"
},
})
Re: Update recipes with new technologies:
Posted: Sat Oct 03, 2020 10:13 pm
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](./download/file.php?id=63437)
- 2020-10-04T00_11_11-D__Factorio_1.0_factorio-current.log - Notepad++.png (16.64 KiB) Viewed 2441 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})
Re: Update recipes with new technologies:
Posted: Sun Oct 04, 2020 11:55 am
by DiegoPro77
Thank you darkfrei; one more thing...
If I wanted to remove / add a technology prerequisite, how can I do it?
Re: Update recipes with new technologies:
Posted: Sun Oct 04, 2020 12:37 pm
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](./download/file.php?id=63442)
- 2020-10-04T14_31_34-D__Factorio_1.0_factorio-current.log - Notepad++.png (37.8 KiB) Viewed 2388 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"}