A way to change Stats for Units in game?

Place to get help with not working mods / modding interface.
Dobudakter
Manual Inserter
Manual Inserter
Posts: 4
Joined: Tue Jan 17, 2017 1:18 am
Contact:

A way to change Stats for Units in game?

Post by Dobudakter »

How to change the max_health of a turret with many kills, for example?
Rseding91
Factorio Staff
Factorio Staff
Posts: 15998
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: A way to change Stats for Units in game?

Post by Rseding91 »

There's no way to change the max health of an entity runtime.

If the max health could be changed runtime that means we would need to save the max health in the save file for every entity that has health and that would increase the save size for something that would virtually never be used but is on a *lot* of entities. All trees + all player buildings + all biters/nests.
If you want to get ahold of me I'm almost always on Discord.
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: A way to change Stats for Units in game?

Post by posila »

I assume you want to make some promotion system for turrets. You could create different entity prototype for each rank and then promote the turret by fast replacing it with entity with higher rank.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: A way to change Stats for Units in game?

Post by aubergine18 »

Is there a programatical way to do a fast replace? (The only way I know of currently is to make a copy of entity settings in a table, delete entity, place new entity, apply the stored settings).
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15998
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: A way to change Stats for Units in game?

Post by Rseding91 »

aubergine18 wrote:Is there a programatical way to do a fast replace? (The only way I know of currently is to make a copy of entity settings in a table, delete entity, place new entity, apply the stored settings).
Yes, http://lua-api.factorio.com/latest/LuaS ... ate_entity use the fast_replace=true option.
If you want to get ahold of me I'm almost always on Discord.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: A way to change Stats for Units in game?

Post by aubergine18 »

Perfect! That will make my code much nicer :D
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding help”