Print resistances of all enemy types
Print resistances of all enemy types
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
This can be done in two way: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?
- Data stage: Create your own mod (containing info.json and data-final-fixes.lua) and run this in data-final-fixes.lua:
Potential drawback: Mods that modify resistances in data-final-fixes.lua after your mod is done could falsify your results.
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
- 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
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Print resistances of all enemy types
Instrument mode allows an instrument-after-data.lua that is guaranteed to run last.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.
There's also --dump-data (see Command line parameters).
Re: Print resistances of all enemy types
Right, that would work. I've never used this mode before, though, so I didn't think of it.SoShootMe wrote: Thu Feb 08, 2024 3:45 pm Instrument mode allows an instrument-after-data.lua that is guaranteed to run last.

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.There's also --dump-data (see Command line parameters).
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Print resistances of all enemy types
I agree it is overkill, but the output will most likely also contain the answers to questions that follow "What are the resistances?"Pi-C wrote: Thu Feb 08, 2024 4:06 pmDefinitely 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
Thank you, that helps!Pi-C wrote: Thu Feb 08, 2024 1:47 pmThis can be done in two way: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?
- Data stage: Create your own mod (containing info.json and data-final-fixes.lua) and run this in data-final-fixes.lua:
Potential drawback: Mods that modify resistances in data-final-fixes.lua after your mod is done could falsify your results.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
- 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