The following function is used for spawning:
SpawnSquad.sqf
Private ["_squadtype","_location","_group","_behaviour","_combatmode","_formation","_itemnum","_unit",
"_unitClass","_unitCount","_unitType","_unitInit","_unitSkill","_unitRank","_count"];
_squadtype = _this Select 0;
_location = _this Select 1;
_group = _this Select 2;
_behaviour = _this Select 3;
_combatmode = _this Select 4;
_formation = _this Select 5;
_itemnum = 0;
If (local server) Then
{
While {_itemnum < count _squadtype} Do
{
_unit = _squadtype Select _itemnum;
_unitClass = _unit Select 0;
_unitCount = _unit Select 1;
_unitType = _unit Select 2;
_unitInit = _unit Select 3;
_unitSkill = _unit Select 4;
_unitRank = _unit Select 5;
_count = 0;
While {_count < _unitCount} Do
{
_unitClass createUnit [GetPos _location, _group, _unitInit, _unitSkill, _unitRank];
_count = _count + 1;
If (_count == 1 && _itemnum == 0) Then
{
_newLeader = NearestObject [_location, _unitClass];
[_newLeader] Join GRPNULL; _group = _newLeader;
};
};
_itemnum = _itemnum + 1;
};
{
   _x SetCombatMode _combatmode;
   _x SetBehaviour _behaviour;
   _x RemoveAllEventHandlers "killed";
   _x SetFormation _formation;
   _x AddEventHandler [{Killed}, {_this Exec {OPFOR_Delete.sqs}}];
} ForEach units _group;
TRUE
}
Else
{
FALSE
};
_group
Is is called via the following line:
[civiGroup, spawn1, dummy, combat, red, column] call SpawnSquad
where
CiviGroup = [["Civilian",3,"sld","[this] exec {civiAK47.sqs}",0.7,"CORPORAL"],["Civilian2",3,"sld","[this] exec {civiFAL.sqs}",0.7,"PRIVATE"],["Civilian3",3,"sld","[this] exec {civiG3.sqs}",0.7,"PRIVATE"],["Civilian4",3,"sld","[this] exec {civiM16.sqs}",0.7,"PRIVATE"]];
;["Civilian2",1,"sld","[this] exec {civiFAL.sqs}",0.7,"PRIVATE"]
(note: the above is all one line)
spawn1 is a game logic
dummy is a single unit of the desired side placed in some far away region of the map.
It works like a charm, but I do not fully understand why.
Here are my questions:
1) On the first iteration loop, the function takes the first unit spawned and assigns it to GRPNULL. I thought OFP could not create groups at run time, so what is the actual group of the spawned squad?
2) Does spawned squad actually have a real leader?
3) I thought lag in missions was related to the number of groups on a map. Would this method of spawning create more lag since it is in essence adding more groups at run time, instead of spawning from old groups?
4) Unit dummy is passed into the function as private variable _group. _group is assigned to _newLeader The function then uses _group as the group name for the CreateUnit command. This makes it seem like the leader of a group can be used as the group. I have not seen this documented on OFPEC. Furthermore, since _group has been altered in the function wil the original unit dummy be affected, or was it passed by value and not reference?
5) Do the TRUE and FALSE statements do anything?
6) In the line that calls the function, red, column and combat are passed as arguments, not as string arguments. Are these reserved words automatically treated as strings?
#Long line of code broken so post fits on page - maguba[/size]