How to change force for entity in editor or script?

Place to get help with not working mods / modding interface.
Post Reply
yagaodirac
Fast Inserter
Fast Inserter
Posts: 151
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

How to change force for entity in editor or script?

Post 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.

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

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

Post 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.

User avatar
Silari
Fast Inserter
Fast Inserter
Posts: 228
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

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

Post 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

yagaodirac
Fast Inserter
Fast Inserter
Posts: 151
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

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

Post by yagaodirac »

PFQNiet wrote:
Sun Jun 27, 2021 2:21 pm
OK thanks.

yagaodirac
Fast Inserter
Fast Inserter
Posts: 151
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

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

Post by yagaodirac »

Silari wrote:
Sun Jun 27, 2021 5:30 pm
Thanks. I'll check it out.

Post Reply

Return to “Modding help”