Page 1 of 1

Need help replacing a recipie

Posted: Mon Nov 23, 2020 9:07 pm
by demongo
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)

Re: NEED HELP REPLACING A RECIPIE

Posted: Mon Nov 23, 2020 9:35 pm
by Pi-C
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)
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).

Re: Need help replacing a recipie

Posted: Tue Nov 24, 2020 7:38 pm
by JonnyOnSeSocks
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

Posted: Tue Dec 01, 2020 1:34 am
by demongo
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

Re: Need help replacing a recipie

Posted: Tue Dec 01, 2020 3:18 am
by demongo
HMM, it appears it does not like me...

Re: Need help replacing a recipie

Posted: Tue Dec 01, 2020 3:25 am
by demongo
CURRENT WIP: help appreciated...

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
[/size]

Re: Need help replacing a recipie

Posted: Tue Dec 01, 2020 5:05 am
by Xorimuth
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.

Re: Need help replacing a recipie

Posted: Tue Dec 01, 2020 5:27 am
by demongo
aw, learning a little more each day im figuring this out... thanks...

Re: Need help replacing a recipie

Posted: Tue Dec 01, 2020 8:10 am
by Pi-C
demongo wrote: Tue Dec 01, 2020 5:27 am aw, learning a little more each day im figuring this out... thanks...
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)
If there is no recipe "deep-minig-5" ("minig" --> "mining"!), this won't ever work as expected. Also, you should definitely read up on the data life cycle, and having a look at eradicator's tutorial mod may also be helpful. :-)