Neutral units/buildings remaining on map after defeat

I am currently looking to optimize a few areas/issues in Forest Nothing. When players are defeated/surrender during FN games, all of their units remain on the map, and this can lead to massive drops in performance(i.e. many idle woodcutters, traders). This issue is compounded when one cannot build over idle units without destroying first, and idle units blocking paths through the trees.

Is there any way these units can be removed from map on player elimination, either through the editor, or lua commands?

Thanks!

i tried these two separately and together… no luck…

World_KillPlayer(player.id, KPR_Lost)
Core_SetPlayerDefeated(player.id, Mod_LoserPresentation, WR_CONQUEST)

still units remain on the field…
it is amazing how even basic stuff does not work…
I don’t understand how they do it…

I also tried to use OnPlayerDefeated (delegate function so its sent to all participants)

function Mod_OnPlayerDefeated(player, reason)
World_KillPlayer(player.id, KPR_Lost)
end

no luck …

so this is what finally did the trick (called right before Core_SetPlayerDefeated)

				local egroup = ############################################## 				
				for i = 1, EGroup_CountSpawned(egroup) do
					local entity = EGroup_GetEntityAt(egroup, i)	
					Entity_Kill(entity)
				end

edit 2:
ok now I am 100% certain someone does not want people to make aoe4 mods…

see the hashtags above? they are censoring a function meant to be used in modding aoe4 …
why do that ?

I get that if you google any scardoc function you get 0 results because they don’t want to have obsolete documentation

but this … this is ridiculous…

here is the uncensored code