LuaSurface.refresh_enemy_peaceful_mode()

Things that already exist in the current mod API
Post Reply
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

LuaSurface.refresh_enemy_peaceful_mode()

Post by Mooncat »

Request:

An API to refresh the status of peaceful-mode in enemy units on a particular surface. Such API can be called after changing LuaSurface.peaceful_mode.

Alternatively, add LuaSurface.set_peaceful_mode(true/false) to change LuaSurface.peaceful_mode and automatically refresh unit status.

Reason:

For most of the modders and command users, we know that changing LuaSurface.peaceful_mode will not change the current status of the existing enemy units. The change is only applied on the new ones. So we need to call LuaForce.kill_all_units for the enemy in order to force respawn. Users may see the units suddenly disappear and may feel odd. Ideally, the refresh is done internally so users will not see that. :mrgreen:

BenSeidel
Filter Inserter
Filter Inserter
Posts: 584
Joined: Tue Jun 28, 2016 1:44 am
Contact:

Re: LuaSurface.refresh_enemy_peaceful_mode()

Post by BenSeidel »

Have thought about this in the past, but never got round to try implementing it.
Basically just iterate over all the enemy units, copy the units settings (position, orientation, hp), kill it, and create a new one.

something like this.
for each unit in enimy_force
{
recreate = copy(unit)
unit.kill()
create(recreate)
}

Bilka
Factorio Staff
Factorio Staff
Posts: 3138
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: LuaSurface.refresh_enemy_peaceful_mode()

Post by Bilka »

Hello, this was actually not a problem with the units, but with the spawners going to sleep and not getting woken up by disabling peaceful mode. This was fixed a few minor versions ago, so now disabling peaceful mode should work as expected.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Already exists”