ok, i ran it through the editor, so i know this works
I have uploaded a zipped mission file incase you still have problems
Find it here
http://www.terox.nildram.co.uk/ofpec/randompos.zipI have added an additional line
dostop _soldierthis was to prevent the ai units from moving back into formation after the setpos code had been run
here's the full system
Mission Editorx * gamelogics, named logic1 to logicX
placed wherever you want a random starting position
x* units that you want sepossing
set formation to none
1 * gamelogic called "server"
*****************************************************
INIT.sqs;;; array containing all names of gamelogics
tx_spawnpos = [logic1,logic2,logic3,logic4,logic5,logic6,logic7,logic8,logic9,logic10]
;;; array containing all names of units you want to setpos
tx_spawnunits = [s1,s2,s3,s4,s5,s6,s7]
?(local server):[] exec "randomspawn.sqs"
*****************************************************
Randomspawn.sqs
~0.5
#INIT
;; following line auto counts the number of units that you want randomly positioning
_countunits = count tx_spawnunits
;; following line auto counts the number of locations (gamelogics) that you can setpos too
_countpos = count tx_spawnpos
;; counter for selecting the element in the tx_spawnunits array
_unit = 0
#START
~0.1
;; selects one of the gamelogics at random
_pos = random _countpos
_pos = (_pos - _pos mod 1)
;; following line sets the selected unit and setpos's the unit to the selected gamelogic
_soldier = tx_spawnunits select _unit
_position = getpos (tx_spawnpos select _pos)
_soldier setpos _position
doStop _soldier
;; following is just a hint marker to check script operation
;; This is how you debug scripts
hint format ["Soldier = %1\n\nPosition = %2\n\nUnit Number = %3",name _soldier,_position,_unit]
_unit = _unit + 1
?(_unit >=(_countunits )): exit
;;;;tx_spawnpos = tx_spawnpos - [_pos]
;;;;_countpos = count tx_spawnpos
goto "START"
The blue line shows how to debug scripts.
What you basically do is display the value for a variable in text form, either using a titletext or hint message so that you can see if a certain value is what you expect it to be
or place a hint message at a certain point in a script to see if that part of the script is ever reached
In the example above, i look to see the value for
1) The name of the soldier, expecting a different name on each loop
2) A position coordinate, this ensures me the script is actually setpossing to a real position
3) and how many units have been setpossed (the first being Unit 0)
obviously you need to slow the looping speed down to see this clearly
You can delete the blue lines, or comment them out
THESE ARE FOR AI???if they are for players then use the following code
INIT.sqs;;; array containing all names of gamelogics
tx_spawnpos = [logic1,logic2,logic3,logic4,logic5,logic6,logic7,logic8,logic9,logic10]
?(local Player):[] exec "randomspawn.sqs"
*****************************************************
Randomspawn.sqs
~0.5
#INIT
;; following line auto counts the number of locations (gamelogics) that you can setpos too
_countpos = count tx_spawnpos
#START
~0.1
;; selects one of the gamelogics at random
_pos = random _countpos
_pos = (_pos - _pos mod 1)
_position = getpos (tx_spawnpos select _pos)
Player setpos _position
exit