Update recipes with new technologies:
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Update recipes with new technologies:
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
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.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Update recipes with new technologies:
You are need the control.luaDiegoPro77 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
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)
https://wiki.factorio.com/Prototype/Technology
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Update recipes with new technologies:
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.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Update recipes with new technologies:
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.
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.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Update recipes with new technologies:
You are need two recipes for it. Note that the new recipe must have unique name.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.
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:
Sorry.
Some recipes have .normal and some of them have .expensive recipe difficult.
Just find how it was defined:
to
Some recipes have .normal and some of them have .expensive recipe difficult.
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}
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})
- DiegoPro77
- Fast Inserter
- Posts: 172
- Joined: Tue Feb 20, 2018 1:40 pm
- Contact:
Re: Update recipes with new technologies:
Thank you darkfrei; one more thing...
If I wanted to remove / add a technology prerequisite, how can I do it?
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.
"One day you'll live this word behind, so live a life you will remember."
Expanding your game experience since 2018.
Re: Update recipes with new technologies:
Prerequisites are just a list of technologies.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?
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
Code: Select all
data.raw.technology["automation-2"].prerequisites = {"electronics", "steel-processing", "logistic-science-pack"}
Code: Select all
remove_value_from_list ("steel-processing", data.raw.technology["automation-2"].prerequisites)
Code: Select all
data.raw.technology["automation-2"].prerequisites = {"electronics", nil ,"logistic-science-pack"}
----------------------
Adding it back:
Code: Select all
table.insert (data.raw.technology["automation-2"].prerequisites, "steel-processing")
Code: Select all
data.raw.technology["automation-2"].prerequisites = {"electronics", nil ,"logistic-science-pack", "steel-processing"}