Page 1 of 1

How to change force for entity in editor or script?

Posted: Sun Jun 27, 2021 1:42 pm
by yagaodirac
I tried to make a scenario. I messed up the force. Now I need to find all the worm turrets and set then to enemy. Any idea?
I searched in the docs but found nothing. Entity doesn't contain a field to set force, neither force is without any function to receive entity.
Editor doesn't do this neither.

Re: How to change force for entity in editor or script?

Posted: Sun Jun 27, 2021 2:21 pm
by PFQNiet

Code: Select all

/c for _,turret in pairs(game.player.surface.find_entities_filtered{type="turret"}) do if turret.name:find("worm") then turret.force = "enemy" end end
Should search the current surface for all turrets, then narrow the search to turrets with "worm" in their name and set them to the "enemy" force.

Re: How to change force for entity in editor or script?

Posted: Sun Jun 27, 2021 5:30 pm
by Silari
In vanilla the extra filtering should be unnecessary - the only 'turret' prototypes in the game are the four worms. Player turrets have their own types - ammo-turret, fluid-turret, and electric-turret.
yagaodirac wrote:
Sun Jun 27, 2021 1:42 pm
Entity doesn't contain a field to set force, neither force is without any function to receive entity.
LuaEntity inherits from LuaControl, which has a Force parameter that can be set like in the code posted above - https://lua-api.factorio.com/latest/Lua ... trol.force

Re: How to change force for entity in editor or script?

Posted: Mon Jun 28, 2021 1:33 am
by yagaodirac
PFQNiet wrote:
Sun Jun 27, 2021 2:21 pm
OK thanks.

Re: How to change force for entity in editor or script?

Posted: Mon Jun 28, 2021 1:34 am
by yagaodirac
Silari wrote:
Sun Jun 27, 2021 5:30 pm
Thanks. I'll check it out.