Sorry for replying so late ;(
CnB, I think that doesn't solve the lag issue the TS is trying to deal with.
Here's how I do it, step by step:
step 1I create a ResUnit in the editor:
Resistance Officer
Rank: Sergeant
init: resgroup1 = group this
-> Now I have a group consisting of 1 unit.
This unit will be in the mission right from the start. Advantage is I can easily give him waypoints in the editor. The units created during the mission are just added to him, so they will also get his waypoints.
step 2I have a trigger (could be script ofcourse to) which will determine when I need to create units (I'm only creating them once they are really needed, once the player is about to fight them, to reduce lag).
In my mission I have a East Present trigger at ~500 meter from the above editor-created unit (player plays as east):
Trigger: East Present, Once
OnAct: [resgroup1, 6, ""] exec "units.sqs"
Where units.sqs looks like this:
;only add units once they are needed to reduce lag/cpu strain
;written by ponq for Desert Ambush Revisited
;[leader, number of unites to add] exec "units.sqs", where leader is an existing leader *with group name*
; and number of units the number of units you want added.
;[loon1, 5] exec "unit.sqs" would create 3 solds, 1 mg and 1 rpg
;a group can only consist of 12 units, so 11 can be added max.
;the newly created units will have the same behaviour as the leader of the group.
;run only on server
?!(local server): exit
_leader = leader (_this select 0)
_amount = _this select 1
_beh = behaviour _leader
_group = group _leader
_skill = difficulty
;difficulty is a Global Variable, set at the start of this MP mission. Use 0.5 here if you don't have the option to set difficulty
_delay = 0.2
_keer = 1
_init = ""
;adjust number of units and/or skill to fit with amount of players
;skip this part :) it's too spefic for my mission
;_amount = _amount - 3
;_amount = _amount + NumberOfPlayers
;?(_amount >= 12): _skill = _skill + 0.1
;?(_amount >= 12): _amount = 11
;?(_amount <= 0): _amount = 1
~3
#loop
;normal sold
"JAM_GBSoldier" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
"JAM_GBSoldier" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
;machine gunner
"JAM_GBMG" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
;rpg soldier
"JAM_GBSoldierRPG" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
;sniper
"JAM_Gsniper" createUnit [getPos _leader, _group, _init, _skill, "private"]
_keer =_keer + 1
?_keer > _amount: goto "exitscript"
_delay
goto "loop"
#exitscript
~1
;set new units to same behaviour as leader
_leader setbehaviour _beh
As you see, this script will create units into a group (the group of the unit we created in the editor).
Right after creating the new units we have to "record" their existance somewhere.
step 3So in the script where you call units.sqs add the new units to an array.
part1resunits = [r1,r2,r3,r4,r5,r6,r7,r8,r9]
part1resunits = part1resunits + (units resgroup2) + (units resgroup3) + units (resgroup1)
The r1, r2 etc are also units I created in the editor. The resgroups2 and 3 are created just like the example I used in this post.
Now part1resunits will hold all the names of the units, editor created and script-created ones.
(I couldn't give the units I create with CreateUnit a name btw)
step 4Now I use a trigger to check when to remove the dead bodies (since I don't want them to sink into the ground when the player can still see that).
In my case it simply means all Resistance units have been killed ina specific area. Trigger, not present resistance, once, onact: [] exec "part2.sqs".
Now in part2.sqs I have a small cutscene, and once the camera leaves the battlefield of part1 I can safely remove the dead bodies without any1 seeing it.
"[_x] exec {delbody.sqs}" foreach part1resunits
where delbody.sqs is:
;delbody.sqs by myke13021 (from ofpec forum)
;bodyhider is an blackop which can do "Hide Body" so the dead units sink slowly into the ground. You can comment that part if you want the to be removed instantly.
?!(local server): exit
_dude = _this select 0
removeallweapons _dude
bodyhider action ["hidebody", _dude]
~10
deletevehicle _dude
exit
That's it step by step.
___________
Now to answer your question:
That looks to me like you have placed these units in the mission via the editor from the start, correct?
I only create the 1st unit of the group in the editor. I hope I did explain this more cleary in this post
I only have a group leader for each group in the editor at the start.
Here you go, that's what I do too
Also, it looks like you don't create additional units into those bodies until the previous owners are dead and buried, right?
If that's true , it's a bit different than my scenario, as I will have several groups alive at the same time and not know which will die first.
I don't fully understand your question, but you could check each group seperatly to see if it has been killed completely ?(count units resgroup1)==0: "[_x] exec {delbody.sqs}" foreach resgroup1array . (not sure about the code though). This would ofcourse require you to also have an array which holds all the units created just like I described above.
Then you create the array for part1resunits as unit names ...ok. But then you change part1resunits value to add other groups ...totally lost me there.
I store the editor-created units in the array first, then I add the scriptcreated units to that array too. The whole point is that I know all these resunits have to be dead before i move on to part2 of my mission. So all these units will be removed once part2 starts.
I just tested again my method using a simple radio trigger telling unit
C0 move getpos PoleZ
and nothing happened, so I think it's not recognizing the "unitname" portion of the unit creation line.
I can't set the unitname while using createunit, and I guess the "option" is still in the script, which should be removed I guess. Sorry.
However, while I couldn't name the created units myself, ofp did seem to be able to identify them. The whole point of storing the created units into an array is to extract the "ofp-name" from the units.
If you want, you can email me the mission so I can see if I can get this script up and running for you (da.haarsma@student.unimaas.nl)
I hope this helps, and plz ask for clarification if I'm being unclear. I will respond faster next time, promised