; dontgoaway.sqs
; this is a remark if it starts with a semi-colon
; most of my remarks are half-arsed so it's apt
; but OFP will ignore the line so it's good for explaining things
; one day you will find a line and wonder why you wrote it!
; anyway, open wordpad, copy all of this down to the 'exit' and paste it in.
; save in text format as dontgoaway.sqs - make sure it isn't dontgoaway.sqs.txt !
; then move the file to your mission folder in Flashpoint\...\Users\youridentity\missions\mymissionnamefolder
; this is a quick exercise in scripting:
; place an Invisible H OBJECT at the centre of your area and name it: mycentrepoint
; type: [] Exec "dontgoaway.sqs" in the init field of the player or any other unit to run the script
; first set up an ARRAY of the units you want on a lead:
; type the names of your single units in the brackets :
_myloneeastieswhoiwanttocontrol = [eunit1,eunit2,eunit3]
; type the names of your groups in the brackets :
_mygroupedeastieswhoiwanttocontrol = Units egroup1 + Units egroup2
; add them all together in one array:
_allmyeastieswhoiwanttocontrol = _myloneeastieswhoiwanttocontrol + _mygroupedeastieswhoiwanttocontrol
; put a bookmark so we know where to restart the check on all units
#startcheck
; wait 30s because they are going to start in the area so we can ignore them for a bit
; we need a PAUSE or the script will run so fast your PC will not do anything else and get a little laggy
~30
; set the initial value for the loop
_index = 0
; set the maximum value so we know when to stop the loop
_unitcount = Count _allmyeastieswhoiwanttocontrol
; put a bookmark so we know where to loop to
#startoftheloop
; pick the unit from the array
_unittocheck = _allmyeastieswhoiwanttocontrol Select _index
; next is the bit where we stop them wandering off
; it's an IF-THEN statement in OFP shorthand
; in the command reference, find the COMMAND to complete the CONDITION in the brackets
; that measures the DISTANCE between _unittocheck and mycentrepoint (there is a CLUE!)
?(WORKOUTWHATGOESHERE > 150): _unittocheck DoMove GetPos mycentrepoint
; next unit
_index = _index + 1
; exit the loop if we've done everybody
?(_index >= _unitcount): Goto "startcheck"
; if not, loop to the next unit
Goto "startoftheloop"
exit
Here's a little exercise - sit down with the command reference and see if you can make sense of the above. You know what you want to do so it should make sense. It's only 14 lines of code amongst the notes so it's manageable.
The commands are not just for script scripting - you can use most of them in trigger or waypoint conditions as well. Or in the 'on activation' fields to get a unit to do something.
Actually, I've left one command out so you'll have to use the comref to find it and give yourself a bit of confidence! We've all learned from our mistakes so the sooner you stop worrying about making them the bettter! In fact, I haven't tested this so it may be more of a learning experience than we've both bargained for. Good luck.