Thanks Hawke, that script seems to work perfectly, apart from the missing ) in line 34.
Thanks for your advice too, Walter, but I'm not much into SQF, to be honest. I find it too complicated.
Edit #1: Well, another problem... How do I remove certain elements from the array later in the mission, so they would be disregarded from the script then? I tried the command below, which didn't seem to have any effect at all...
array = array - [element1]
I checked the amount of elements in the array before and after with a "hint format" command and it was always the same, nothing was changed.
I changed the _array in the script to a global array which is initilialized in init.sqs, so elements could be later removed from it...
Edit #2: According to
Biki, nested arrays cannot be substracted. However, I got an idea out of nowhere to rewrite the script a little, to avoid those nested arrays. Here's what I came up with:
init.sqsarray = [element1,element2,element3]
script.sqs_unit = _this select 0
_max = count array
_nearest = array select 0
_num = 0
_dist = array select 0 distance _unit
#check
?(_num > _max): goto "nearest"
_newdist = _unit distance (array select _num)
? _newdist < _dist: _nearest = array select _num
_num = _num + 1
goto "check"
#nearest
_pos = position _nearest
_unit setPos _pos
exit
This script seems to work as good and the elements can be removed from the array too without any problems. Thanks to Hawke for the reference from the original script.
I learned a lot from it.
Problem solved.