Finding entities in a save that have been removed
Posted: Wed Dec 29, 2021 6:09 am
So I'm working on (yet another) infinite resource mod. With it, it duplicates non-infinite resources to create infinite ones, then during the game when the non-infinite ones are depleted (reach 0), it replaces them with the infinite equivalent. The mod also has a startup setting exclusion list.
The issue I'm trying to solve is this: if a player uses this mod, it replaces some resource tiles with the infinite versions, then they save and add that resource to the exclusion list (restart the game), upon loading the save, all of the infinite versions of that resource are gone. I want to convert them back to non-infinite versions, if possible.
My best guess at the moment is to do this via a migration script. (Ok, scratch that... missed the fact that the script is only going to be able to run once per save. But I'm running into the same problems with with control.lua in on_configuration_changed.) But this:
does not return the entities I'm after in my test save. (The log statement is not printing any of the ones I'm looking for.)
How do I get them? Is this possible?
The issue I'm trying to solve is this: if a player uses this mod, it replaces some resource tiles with the infinite versions, then they save and add that resource to the exclusion list (restart the game), upon loading the save, all of the infinite versions of that resource are gone. I want to convert them back to non-infinite versions, if possible.
Code: Select all
require("__core__/lualib/util")
local exclusionlist = {}
for k, v in pairs(util.split(settings.startup["InfiniteResourcesNormalYieldDepletion_exclusions"].value, ",")) do
exclusionlist[v] = true
end
for _, surface in pairs(game.surfaces) do
local resources = surface.find_entities_filtered{area = nil, type = "resource"}
for _, resource in pairs(resources) do
log(resource.name)
if resource.initial_amount and exclusionlist[resource.name:gsub("-infinite", "")] then
resource.surface.create_entity({name = resource.name:gsub("-infinite", ""), amount = resource.amount, position = resource.position, force = game.forces.neutral, raise_built = true})
end
end
end
How do I get them? Is this possible?