Page 1 of 1
Print resistances of all enemy types
Posted: Thu Feb 08, 2024 3:15 am
by vernir
Hello. Never wrote for Factorio. Could you kick me in a right direction to help me write a script that prints all resistances of all enemy prototypes to the file? Or just how to iterate through all available Prototype/Units?
Re: Print resistances of all enemy types
Posted: Thu Feb 08, 2024 1:47 pm
by Pi-C
vernir wrote: Thu Feb 08, 2024 3:15 am
Could you kick me in a right direction to help me write a script that prints all resistances of all enemy prototypes to the file? Or just how to iterate through all available Prototype/Units?
This can be done in two way:
- Data stage: Create your own mod (containing info.json and data-final-fixes.lua) and run this in data-final-fixes.lua:
Code: Select all
local objects = {
"unit", -- Biters/spitters
"unit-spawner", -- Spawners
"turret", -- Worms
}
for p, protos in pairs(objects) do
log("Type: "..protos)
for p, proto in pairs(data.raw[protos] do
log(string.format("Ty %s:\tResistances: %s", p, serpent.block(proto.resistances))
end
end
Potential drawback: Mods that modify resistances in data-final-fixes.lua after your mod is done could falsify your results.
- Directly in the game (all prototypes are final), you can run the following from the command line/chat console:
Code: Select all
/c protos = game.get_filtered_entity_prototypes{{filter = "type", type = { "unit", "unit-spawner", "turret"}}}
for p, proto in pairs(protos) do
log(string.format("Name: %s (%s)\tResistances: %s", p, proto.type, serpent.block(proto.resistances)))
end
Re: Print resistances of all enemy types
Posted: Thu Feb 08, 2024 3:45 pm
by SoShootMe
Pi-C wrote: Thu Feb 08, 2024 1:47 pm
Potential drawback: Mods that modify resistances in data-final-fixes.lua after your mod is done could falsify your results.
Instrument mode allows an instrument-after-data.lua that is guaranteed to run last.
There's also --dump-data (see
Command line parameters).
Re: Print resistances of all enemy types
Posted: Thu Feb 08, 2024 4:06 pm
by Pi-C
SoShootMe wrote: Thu Feb 08, 2024 3:45 pm
Instrument mode allows an instrument-after-data.lua that is guaranteed to run last.
Right, that would work. I've never used this mode before, though, so I didn't think of it.
Definitely useful in general, but dumping all of data.raw seems a bit excessive in this particular case where the OP is interested only in one particular property of a subset of the game's prototypes.
Re: Print resistances of all enemy types
Posted: Thu Feb 08, 2024 4:41 pm
by SoShootMe
Pi-C wrote: Thu Feb 08, 2024 4:06 pm
Definitely useful in general, but dumping all of data.raw seems a bit excessive in this particular case where the OP is interested only in one particular property of a subset of the game's prototypes.
I agree it is overkill, but the output will most likely also contain the answers to questions that follow "What are the resistances?"

. (Also, it's much faster than loading the game and can easily be generated as part of an automated process.)
Re: Print resistances of all enemy types
Posted: Thu Feb 08, 2024 6:13 pm
by vernir
Pi-C wrote: Thu Feb 08, 2024 1:47 pm
vernir wrote: Thu Feb 08, 2024 3:15 am
Could you kick me in a right direction to help me write a script that prints all resistances of all enemy prototypes to the file? Or just how to iterate through all available Prototype/Units?
This can be done in two way:
- Data stage: Create your own mod (containing info.json and data-final-fixes.lua) and run this in data-final-fixes.lua:
Code: Select all
local objects = {
"unit", -- Biters/spitters
"unit-spawner", -- Spawners
"turret", -- Worms
}
for p, protos in pairs(objects) do
log("Type: "..protos)
for p, proto in pairs(data.raw[protos] do
log(string.format("Ty %s:\tResistances: %s", p, serpent.block(proto.resistances))
end
end
Potential drawback: Mods that modify resistances in data-final-fixes.lua after your mod is done could falsify your results.
- Directly in the game (all prototypes are final), you can run the following from the command line/chat console:
Code: Select all
/c protos = game.get_filtered_entity_prototypes{{filter = "type", type = { "unit", "unit-spawner", "turret"}}}
for p, proto in pairs(protos) do
log(string.format("Name: %s (%s)\tResistances: %s", p, proto.type, serpent.block(proto.resistances)))
end
Thank you, that helps!