Script-explanation delux:
_marker = _this select 0
_unittype = _this select 1
_groupname = _this select 2
_side = _this select 3
#loop
_unittype createunit [getmarkerpos _marker, _groupname]
? _side countside units _groupname > 5 : goto "check"
~0.5
goto "loop"
#check
? _side countside units _groupname < 6 : goto "loop"
~0.01
goto "check"
==============================================
We'll do it in steps, so it's easier to grasp.
1.
_marker = _this select 0
_unittype = _this select 1
_groupname = _this select 2
_side = _this select 3
This creates the following variables:
marker
unittype
groupnameand
side The little
_ infront of them makes them local, so they can only be accessed in this script.
Now, we have to store some data in those variables, don't we?
Cue
_this select 0.
_this select 0 will take the first parameter passed to the script* and store it in the variable.
_this select 1 will take the second parameter and to the same thing, and so on and so forth with
_this select 2 and
3.
Pretty straight forward.
*Passing parameters to the script:
["MarkerName","UnitType",GroupName,UnitsSide]There you are passing four parameters to the script.
"MarkerName" as the first one (
_this select 0) is the name of the marker where you want to
create your units.
"UnitType" as the second (
_this select 1) will tell the script what type of unit we want to create.
In this case: "Civilian7".
groupName as the third, (
_this select 2) will store the value of what group we want the unit to
spawn into. You have to have a group to spawn the unit into.
side as the fourth and last one (
_this select 3) will store the value of what side the unit will be on.
West, East, Resistance or Civilian. Civilian in our case.
==============================================
2.
#loop
_unittype createunit [getmarkerpos _marker, _groupname]
? _side countside units _groupname > 5 : goto "check"
~0.5
goto "loop"
#loop and
goto "loop"These are the only two components you need to make a loop.
#loop will create a label in the script, called "loop". It could be called whatever you want, but it is good to
name it after what it is. A loop.
goto "loop" tells the script to skip to the place labeled #loop and continue to run the script from there, in this
case repeating what it just did.
_unittype createUnitThis will take the variable _unittype, in which we had stored what type of unit we wanted to create (Civilian7) and tell the
script to create that unit.
[getMarkerPos _marker, _groupname]But you need this line as well. It tells the script where to create the unit, and in which group to place it. It first gets the
position of a marker, then the name of a group, after that the unit is created. Simple enough.
? _side countSide units _groupnameOkay, this will check the group stored in _groupname for any units belonging to the side we specified in _side. Are you with me?
It asks the script "How many civilian units are there in the group called _groupname?"
> 5 : goto "check" asks "Are there more than five units? If so, then go to the place called "check"".
~0.05 tells the script to halt there for 0.05 seconds.
Now, a quick summary of this piece of code.
It starts up, creates a unit (of our choice) at a place (of our choice), then it counts how many civilian units there are.
If there are more than 5, it skips ahead in the script, if there are less than five, it halts for 0.05 seconds then moves back and does
it all over again, until there are more than 5 units.
==============================================
3.
#check
? _side countside units _groupname < 6 : goto "loop"
~0.01
goto "check"
Again,
#check and
goto "check sets up a loop. Of course we have to name it differently
? _side countSide units _groupname < 6 : goto "loop"You know all the commands here, so I'll just explain why it's there.
This part of the script will always be running, and keep checking if the number of units in the group is
6 or lower, if yes (true) then skip to "loop", if no (false) then continue forward.
~0.01 another pause in the script, for 0.01 seconds.
Quick summary, once again.
This will keep checking the mission if there are 6 or fewer units in the group, if yes go back to the previous part
and create more. If no, just continue checking. One of them might die, after all.
Now, do note that When making loops, you always have to have a pause. A ~ that is, followed by a number. If you want a loop checking things
almost constantly, make the number really small.
Yikes, looking back this grew to be pretty big. Oh well, as long as you learn something from it mate ;D
/KTottE