Page 1 of 1

LuaSurface.refresh_enemy_peaceful_mode()

Posted: Mon Nov 21, 2016 7:55 am
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:

Re: LuaSurface.refresh_enemy_peaceful_mode()

Posted: Wed Jan 04, 2017 3:35 am
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)
}

Re: LuaSurface.refresh_enemy_peaceful_mode()

Posted: Fri May 31, 2019 9:10 am
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.