i have a mod that adds various levels or deepmining, and i want to replace old mining recipes with new researched ones.
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX1" then
data.raw.recipe."deep-mining-5".enabled = false
end
end)
Need help replacing a recipie
Need help replacing a recipie
Last edited by Koub on Mon Nov 23, 2020 10:12 pm, edited 1 time in total.
Reason: Lowered case in subject
Reason: Lowered case in subject
Re: NEED HELP REPLACING A RECIPIE
Won't work. script.on_event is available in control stage only (once you've started a new game or loaded an existing one), but data.raw.recipe will only exist during the data stage (when Factorio is loading).demongo wrote: ↑Mon Nov 23, 2020 9:07 pm i have a mod that adds various levels or deepmining, and i want to replace old mining recipes with new researched ones.
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX1" then
data.raw.recipe."deep-mining-5".enabled = false
end
end)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
-
- Manual Inserter
- Posts: 4
- Joined: Tue Nov 17, 2020 10:11 pm
- Contact:
Re: Need help replacing a recipie
in the control stage, recipes are unlocked for forces. You can disable the old recipes for the force of the research trigger event.
Code: Select all
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX1" then
local force = event.research.force
force.recipes["deep-minig-5"].enabled = false
end
end)
Re: Need help replacing a recipie
omg thank you if i hit another snag i will ask here... working on an inf tech for my deep mines atm
https://mods.factorio.com/user/demongo1154
https://mods.factorio.com/user/demongo1154
Re: Need help replacing a recipie
HMM, it appears it does not like me...
- Attachments
-
- ERROR.png (39.99 KiB) Viewed 2667 times
Re: Need help replacing a recipie
CURRENT WIP: help appreciated...
[/size]
Code: Select all
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX1" then
local force = event.research.force
force.recipes["deep-minig-5"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX2" then
local force = event.research.force
force.recipes["deep-mining-X1"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX3" then
local force = event.research.force
force.recipes["deep-mining-X2"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX4" then
local force = event.research.force
force.recipes["deep-mining-X3"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX5" then
local force = event.research.force
force.recipes["deep-mining-X4"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX6" then
local force = event.research.force
force.recipes["deep-mining-X5"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX7" then
local force = event.research.force
force.recipes["deep-mining-X6"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX8" then
local force = event.research.force
force.recipes["deep-mining-X7"].enabled = false
end
end)
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX9" then
local force = event.research.force
force.recipes["deep-mining-X8"].enabled = false
end
end)
-- allow productivity for "deep-mining-2"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-2")
end
end
-- allow productivity for "deep-mining-3"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-3")
end
end
-- allow productivity for "deep-mining-4"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-4")
end
end
-- allow productivity for "deep-mining-5"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-5")
end
end
-- allow productivity for "deep-mining-X1"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x1")
end
end
-- allow productivity in "deep-mining-X2"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x2")
end
end
-- allow productivity for "deep-mining-X3"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x3")
end
end
-- allow productivity for "deep-mining-X4"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x4")
end
end
-- allow productivity for "deep-mining-X5"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x5")
end
end
-- allow productivity for "deep-mining-X6"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x6")
end
end
-- allow productivity for "deep-mining-X7"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x7")
end
end
-- allow productivity for "deep-mining-X8"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x8")
end
end
-- allow productivity for "deep-mining-X9"
for k,v in pairs(data.raw.module) do
if v.limitation then
table.insert(v.limitation, "deep-mining-x9")
end
end
Re: Need help replacing a recipie
You can't bind multiple times to the same event (defines.events.on_research_finished). Put those all into one block.
Secondly, you are mixing up control and data. The event hooks should go in control.lua and the recipe additions (anything that deals with data.raw) should go in data.lua. That's why you are getting that error - script is not defined in data.lua, only control.lua.
Secondly, you are mixing up control and data. The event hooks should go in control.lua and the recipe additions (anything that deals with data.raw) should go in data.lua. That's why you are getting that error - script is not defined in data.lua, only control.lua.
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Re: Need help replacing a recipie
aw, learning a little more each day im figuring this out... thanks...
Re: Need help replacing a recipie
Apart from what Xorimuth has explained, there also seems to be a small typo in the first block:
Code: Select all
script.on_event(defines.events.on_research_finished, function(event)
if event.research.name == "deep-mine-MKX1" then
local force = event.research.force
force.recipes["deep-minig-5"].enabled = false
end
end)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!