I propose you something similar.
I'll take and modify my script to fit your needs.
These are the requirements:
° create a trigger you will call "trg_removal" and
setup it "anybody,once", size to cover all units on map,
empty init line;
° create a logic you will call "lgc_iamserver";
° put: 0 Exec "removal.sqs" in the init.sqs -the best way- or
in the init of an other trigger "none,once", condition:true;
No names, no global variables.
[removal.sqs]
?!(Local lgc_iamserver):Exit
_uns=(List trg_removal)
_grs=[]
_i=0
_t=(Count _uns)
#LoopGroups
_gr=(Group (_uns Select _i))
?_gr In _grs:GoTo "NextGroup"
_grs Set [(Count _grs),_gr]
{_x AddEventHandler ["KILLED",{_THIS Exec "removedead.sqs"}]} ForEach (Units _gr)
#NextGroup
_i=_i+1
?_i<_t:GoTo "LoopGroups"
Exit
[removedead.sqs]
~90
DeleteVehicle (_THIS Select 0)
Exit
This script retrieves all groups and works the related units, also those ones the trigger doesn't list: the gunners and commanders of the vehicles.
Of course, it expects the AI units are all local to the server, so you must provide a separate script for the bodies of:
° players (each machine has its player local);
° AI in which leader is a player (they are local to that player's machine);
I didn't consider the vehicles, because locality tests should be done:
° a vehicle becomes local to the player who drives it, can the server delete it?;
° when a vehicle is destroyed, does it return local to the server?;
For the moment, try this solution for soldiers.