Page 1 of 1

Research Triggers

Posted: Sun Nov 10, 2024 7:27 pm
by ldinc
Hi! Can anyone explain how to make custom technology with research trigger in proper way?
I've tried one, but trigger doesn't work, also rendered in tech tree gui... as correct tech
An another question, how to disable technology with research trigger? If you change it to nil & add unit to technology the whole list of other triggers don't work ....

Re: Research Triggers

Posted: Sun Nov 10, 2024 8:57 pm
by ldinc
Example of new tech i've tried:

Code: Select all

{
  effects = {
    { recipe = "apm_crusher_machine_0", type = "unlock-recipe" },
    { recipe = "apm_coal_crushed_1",    type = "unlock-recipe" },
    { recipe = "apm_stone_crushed_1",   type = "unlock-recipe" },
    { recipe = "apm_wood_pellets_1",    type = "unlock-recipe" }
  },
  essential = true,
  icon = "__apm_resource_pack_ldinc__/graphics/technologies/apm_crusher_machine_0.png",
  icon_size = 128,
  name = "apm_crusher_machine_0",
  order = "a-a-a",
  prerequisites = {},
  research_trigger = { count = 5, item = "copper-plate", type = "craft-item" },
  type = "technology",
}

Re: Research Triggers

Posted: Sun Nov 10, 2024 9:00 pm
by ldinc
The first approoach to disable existing technology was:

Code: Select all

---@param technology_name string
function apm.lib.utils.technology.delete(technology_name)
	if not apm.lib.utils.technology.exist(technology_name) then return end

	local technology = data.raw.technology[technology_name]

	technology.hidden_in_factoriopedia = true
	technology.visible_when_disabled = false
	technology.essential = false
	technology.enabled = false
	technology.hidden = true


	-- let us find who is linked to this technology and remove the prerequisites
	for technology, _ in pairs(data.raw.technology) do
		if technology ~= technology_name then
			if apm.lib.utils.technology.has.prerequisites(technology, technology_name) then
				apm.lib.utils.technology.remove.prerequisites(technology, technology_name)
			end
		end
	end
end
This code successfully hide from the tree technology, but trigger still active and popup with successfully researched tech will appear

Re: Research Triggers

Posted: Sun Nov 10, 2024 9:03 pm
by ldinc
Then i've tried to disable research trigger by setting up with `nil`. After this change any other tech-s with researh triggers become unsearchable via crafting items or interact with ores/oil

Code: Select all

---@param technology_name string
function apm.lib.utils.technology.delete(technology_name)
	if not apm.lib.utils.technology.exist(technology_name) then return end

	local technology = data.raw.technology[technology_name]


	technology.hidden_in_factoriopedia = true
	technology.visible_when_disabled = false
	technology.essential = false
	technology.enabled = false
	technology.hidden = true

	if technology.research_trigger then
		technology.research_trigger = nil
		technology.unit = {
			ingredients = {},
			time = 1,
			count = 1,
		}
	end

	-- let us find who is linked to this technology and remove the prerequisites
	for technology, _ in pairs(data.raw.technology) do
		if technology ~= technology_name then
			if apm.lib.utils.technology.has.prerequisites(technology, technology_name) then
				apm.lib.utils.technology.remove.prerequisites(technology, technology_name)
			end
		end
	end
end