Files
factorio-clusterio/sharedPlugins/researchSync/enableResearch.lua
T
Hornwitser 62f3a99feb Set progress when completing infinite researches
Set the progress for the next level of an infinite research when
unlocking it via a script.  This is necessary when the research is
actively being researched  as Factorio will carry over the progress for
the current level into the next one when set via a script.

It's possible for the new progress to be non-zero if the next level was
on the research queue.
2019-10-12 17:07:08 +02:00

34 lines
1.0 KiB
Lua

local function updateTech()
script.raise_event(defines.events.on_research_finished, {research=game.forces['player'].technologies['{tech_name}'], by_script=true})
if {notify} then
if 1 == {tech_infinite} then
game.print("Infinite technology {tech_name} level {tech_level} unlocked")
else
game.print("Technology {tech_name} researched")
end
game.play_sound({path="utility/research_completed"})
end
end
local force = game.forces['player']
local tech = force.technologies['{tech_name}']
if tech then
if 1 == {tech_infinite} then
if (tech.level ~= level) then
tech.level = {tech_level}
if tech == force.current_research then
force.research_progress = {tech_progress}
else
force.set_saved_technology_progress(tech.name, {tech_progress});
end
updateTech()
end
else
if not tech.researched then
tech.researched = true
updateTech()
end
end
end