De-aggro'ing hostile units for safe teleport
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
De-aggro'ing hostile units for safe teleport
If a player character is teleported a great distance while being attacked by biters, massive lag spikes ensue as a crowd of biters tries to path to their target which may be a million tiles away now.
What is the best way of telling nearby biters to "lose" their target and carry on with any other normal business?
What is the best way of telling nearby biters to "lose" their target and carry on with any other normal business?
Last edited by Deadlock989 on Thu Oct 29, 2020 7:09 pm, edited 1 time in total.
Re: De-aggro unit commands?
If the biters think the target is going to die, they will stop attacking it
So you could spawn a projectile, which does 999999 damage, and target the player.
This will internally set the 'damage to be taken', so the biters will see that the character is going to die, and stop attacking it.
Then after a few ticks, or whenever you teleport the character again, just delete the projectile, and the damage to be taken will be cleared.
So you could spawn a projectile, which does 999999 damage, and target the player.
This will internally set the 'damage to be taken', so the biters will see that the character is going to die, and stop attacking it.
Then after a few ticks, or whenever you teleport the character again, just delete the projectile, and the damage to be taken will be cleared.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: De-aggro unit commands?
Should the projectile be riding in an invisible car?
I had some success with this:
It mainly works because the player is made indestructible just before teleport so the biters don't try to re-target them. It doesn't catch everything though. The player could be running from a biter nest patch a long way off that was aggro'ed and the biters are still pathing their way to them but beyond 50 tiles. I don't know what range biters are guaranteed to lose interest in a player but it's a bigger and bigger search radius and more dead UPS. But if you don't catch them all, just one biter trying to path a million tiles through uncharted territory can produce some nasty lag. One of my tests on a large nest's worth all at once destabilised my PC so badly I had to manually power it off.
To be honest though I don't know what I'm doing with unit commands. I see there are compound commands that might include an attack sub-command. I also vaguely understand that commands can work on unit groups rather than units. I don't want to destabilise some biter group and have them behave erratically forever.
I had some success with this:
Code: Select all
local biters = player.surface.find_entities_filtered{position = teleporter.position, radius = 50, type = "unit"}
for _,biter in pairs(biters) do
biter.set_command {
type = defines.command.wander,
ticks_to_wait = 30,
distraction = defines.distraction.by_enemy
}
end
To be honest though I don't know what I'm doing with unit commands. I see there are compound commands that might include an attack sub-command. I also vaguely understand that commands can work on unit groups rather than units. I don't want to destabilise some biter group and have them behave erratically forever.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: De-aggro unit commands?
Am i correct in assuming that neither the distance not the speed of the projectile matter for that? If yes that has other interesting applications...
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: De-aggro unit commands?
I tried it, couldn't get it work. I didn't try very hard tbf.eradicator wrote: ↑Wed Oct 28, 2020 11:35 pmAm i correct in assuming that neither the distance not the speed of the projectile matter for that? If yes that has other interesting applications...
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: De-aggro unit commands?
No luck either. Tried all sorts of projectiles including homing ones like "laser" and "blue-laser" but the biters don't care. Also most projectiles ignore "speed" given with create_entity it seems.Deadlock989 wrote: ↑Wed Oct 28, 2020 11:36 pmI tried it, couldn't get it work. I didn't try very hard tbf.eradicator wrote: ↑Wed Oct 28, 2020 11:35 pmAm i correct in assuming that neither the distance not the speed of the projectile matter for that? If yes that has other interesting applications...
What does utterly confuse them is if i have 0 health:
Code: Select all
/c x = game.player.character script.on_event(defines.events.on_tick,function()x.health=0 end)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: De-aggro unit commands?
Thanks, that works (given that the character is set to non-destructible). My only small annoyance with it (seems there is always a price for these hacks) is that because the character is detached, you get three small grey health indicator bars drawn beneath them during the cutscene (like they are a badly damaged wall or something). Trying to find a way to hide it. The character needs to be in that state for at least a second or so before the teleport so that all the units have time to select new targets.
I'm on the verge of reporting this as a bug, it doesn't seem right that I can hard crash Factorio and even destabilise Windows with runaway memory usage by teleporting a character under attack.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: De-aggro unit commands?
True that. I never used my teleporters while under fire i guess - at least i never noticed any such thing.Deadlock989 wrote: ↑Thu Oct 29, 2020 10:51 amI'm on the verge of reporting this as a bug, it doesn't seem right that I can hard crash Factorio and even destabilise Windows with runaway memory usage by teleporting a character under attack.
Personally i'd prefer if there was a non-hacky way to just force the character LuaEntity out of the biters target list manually - for other usecases too. @Klonan said there's already a mechanism to make them ignore entities "that are going to die", so i wonder if requesting something like LuaEntity.permanently_ignored_by_biters(bool) or LuaEntity.remove_from_current_biter_targets() would be realistic.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: De-aggro unit commands?
I guess that would just be one more thing for every attacking biter to check every single tick. Since vanilla never, ever teleports, there's no worries about pathfinding horror when the worst that can happen is a player with 8 exoskeletons steps half a tile out of range in a tick. Part of my horrible issue is the need to do this, so the distance involved is about as large as it can possibly be, which explains the memory death spiral (20 biters trying to pathfind 1000km through uncharted territory). So a simple visible = false flag for rendering would tick a ton of my boxes and probably kill off this worst case. But in fact in a megabase it's not unreasonable to expect a player to set up two teleporter bases a few km apart, so even if I could just hide the character, biters still might have to path-find much further than they normally would. And because it's a random convergence of events, none of the path-caching optimisations will ever apply.eradicator wrote: ↑Thu Oct 29, 2020 3:27 pmTrue that. I never used my teleporters while under fire i guess - at least i never noticed any such thing.
Personally i'd prefer if there was a non-hacky way to just force the character LuaEntity out of the biters target list manually - for other usecases too. @Klonan said there's already a mechanism to make them ignore entities "that are going to die", so i wonder if requesting something like LuaEntity.permanently_ignored_by_biters(bool) or LuaEntity.remove_from_current_biter_targets() would be realistic.
The code snippet above works as well without having to tinker with health - additionally refinement is to check for units that are actually on the enemy force and maybe setting distraction to "anything" - but it seems to render the affected biters oblivious to the player if they then walk back to that spot. They will continue to attack anything else.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: De-aggro unit commands?
What i meant there was something that just works once (and doesn't have the range problem that your snippet has). Thus reducing the problem to preventing the re-targeting of the entity, which should be much easier.Deadlock989 wrote: ↑Thu Oct 29, 2020 3:51 pmI guess that would just be one more thing for every attacking biter to check every single tick.
Does teleporting to another surface de-aggro? In which case it might be feasible to teleport to your "limbo" surface and back (possibly with one tick delay).
Looking at the character prototye, maybe you could define an animation for an armor that is completely transparent? Which would reduce the problem to temporary swapping of the armor slot. Though if you start manipulating the character prototype you enter the realm where you have to decide wheather to support charcter skin mods or not.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: De-aggro unit commands?
See the other thread - this is a character, not a player, so it can't be transported cross-surface. Characters are disconnected from / not controlled by (but still associated with) the player during a cutscene - putting a disconnected character into a vehicle breaks even the association. Why you can only teleport a character when it is attached to a player remains a mystery but cross-surface teleports are players (with or without a character attached) and vehicles and nothing else.eradicator wrote: ↑Thu Oct 29, 2020 5:00 pmDoes teleporting to another surface de-aggro? In which case it might be feasible to teleport to your "limbo" surface and back (possibly with one tick delay).
I did look at swapping out armour for a new armour with a blank animation but then you're juggling armours and equipment grids and inventory bonuses and god knows what. It's next on my list of things to try if I decide I really don't like the half-blind messing with unit commands. The health = 0 thing works perfectly functionality-wise, it just has that unfortunate visual glitch (again because it's a disconnected character, not a player).
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: De-aggro unit commands?
I know that the character is not attached *during* the cutscene. But as far as i understood you so far you need to de-aggro *before* the cutscene starts. At which point the player is still attached.Deadlock989 wrote: ↑Thu Oct 29, 2020 5:22 pmSee the other thread - this is a character, not a player, so it can't be transported cross-surface.eradicator wrote: ↑Thu Oct 29, 2020 5:00 pmDoes teleporting to another surface de-aggro? In which case it might be feasible to teleport to your "limbo" surface and back (possibly with one tick delay).
I just tested this and
Code: Select all
/sudo x = here me.teleport(here,'test') me.teleport(here,'nauvis')
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
- Deadlock989
- Smart Inserter
- Posts: 2529
- Joined: Fri Nov 06, 2015 7:41 pm
Re: De-aggro unit commands?
Yep, that works well. Back and forth in the same tick = no visual clue that you just spent a millisecond in a dungeon dimension and all the biters immediately lose interest. Tested in multiplayer as well and it looks visually fine.eradicator wrote: ↑Thu Oct 29, 2020 5:53 pmI just tested this andThis instantly de-aggros all biters.Code: Select all
/sudo x = here me.teleport(here,'test') me.teleport(here,'nauvis')
Nice find, thanks.
- eradicator
- Smart Inserter
- Posts: 5206
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: De-aggro unit commands?
Glad i could help.
Awesome animation. Looking forward to that release .
Yea, because rendering only happens once per tick for ... obvious reasons .Deadlock989 wrote: ↑Thu Oct 29, 2020 6:47 pmno visual clue that you just spent a millisecond in a dungeon dimension
Awesome animation. Looking forward to that release .
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.