Home   Help Search Login Register  

Author Topic: Random Spawning  (Read 3945 times)

0 Members and 1 Guest are viewing this topic.

deuxmad

  • Guest
Random Spawning
« on: 15 Apr 2005, 01:24:22 »
Hello all,

Before you wonder if I have used the search feature or checked all 46pages of this forum. I have. After the 47th page my vision started to blur lol.


Question: I need a group to spawn (at mission start) at random spots.

I know it has something to do with using GameLogic and using a random script. But no joy yet.

Could anyone help me on this?

Thanks in advance.




Offline Zombie

  • Members
  • *
  • Beware the night, the zombie walks among you
    • USI
Re:Random Spawning
« Reply #1 on: 15 Apr 2005, 12:17:32 »
you can also do it by setting the placement radius of the group leader to an area large enough to cover the area you want.  Setting the placement radius is only needed on the group leader, the rest of the group will go where he goes.

deuxmad

  • Guest
Re:Random Spawning
« Reply #2 on: 15 Apr 2005, 13:53:38 »
Using the placement radius will not work. Since I need the 'spawn' group to be spawned at specific locations.

24Gamer

  • Guest
Re:Random Spawning
« Reply #3 on: 15 Apr 2005, 19:06:07 »
i did this for RTSX, create a trigger with the area you want them to spawn, then move the player about to random locations until they are in the trigger area, this might be a bit slow if your trigger area is small tho

itchie

  • Guest
Re:Random Spawning
« Reply #4 on: 16 Apr 2005, 02:37:33 »
i really doubt u read all the pages in this forum, actually i dont think u read any page at all and posted this question right away. If you check the sticky thread called "Respawning" you can find your answer on the very first page (12th reply).

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Random Spawning
« Reply #5 on: 16 Apr 2005, 20:48:40 »
INIT.sqs

tx_spawnpos = [logic1,logic2,logic3,logic4]

Mission Editor
create as many gamelogics as you need
set their presence radius wide enough to encompass a decent land area
name the gamelogics
logic1
logic2
logic3
etc etc

the populate an array called tx_spawnarray with the names of your gamelogics
and populate an array with all the units you want to randomly setpos
and run a script

by doing the following

INIT.sqs
tx_spawnpos= [logic1,logic2,logic3,logic4]
tx_spawnunits = [Unit1,Unit2,Unit3,Unit4 etc etc]
[] exec "randomspawn.sqs"

Randomspawn.sqs
Quote
#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)m that you can setpos too
_countpos = count tx_spawnpos
;; counter for selecting the element in the tx_spawnunits array
_unit = 0

#START
~0.5
;; 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
tx_spawnunits select _unit setpos (getpos tx_spawnpos select _pos)
_unit = _unit + 1
?(_unit >=(_countunits - 1)): exit
;;;tx_spawnpos = tx_spawnpos - [_pos]
;;;_countpos = count tx_spawnpos
goto "START"

the above script can set different units to the same gamelogic
If you want the gamelogic position to be used only once, then uncomment the red lines
NB>> if you do this, make sure there are more gamelogics than units

each time your mission runs, the individual gamelogics will be setpossed to somewhere within their placement radious, therefore each mission will give differing results both as to which gamelogic a unit is setpossed too and where that gamelogic is.
One more thing to note, try to make sure that the gamelogics dont encompass building locations, you dont want to be trapped in one at mission start



EDITED 19/04/05  Due to syntax error, see green text
« Last Edit: 19 Apr 2005, 17:53:15 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

deuxmad

  • Guest
Re:Random Spawning
« Reply #6 on: 17 Apr 2005, 17:06:22 »
Thank you very much Terox

This is just the thing I was looking for. Much appreciated.

@itchie,

I have looked every single page as I have previously posted. However, since some of the posts are either not relavant or has another totally unrelated subject and covers it due to someone 'thread jacking'. I wasnt able to find it.

If you look at the original post of the 'Respawn' my question was totally different than of the one posted. That type of respawn is was specifically for the 'group respawn' when you die.

I wanted to place my group before they died.

Hence, Terox there with his kind nature posted the info that I needed. Rather than useless criticism.

EDIT:
@Terox,

I have followed your instruction to the letter, but the grouped units still start out at the area placed in the editor.

I will post the init and the randomspawn.sqs here for you to see;

Init.sqs
;INIT.sqs
tx_spawnarray = [logic1,logic2,logic3,logic4,logic5,logic6,logic7,logic8,logic9,logic10,logic11,logic12,logic13,logic14,logic15]

tx_spawnunits = [s1,s2,s3,s4,s5,s6,s7]

[] exec "randomspawn.sqs"

Randomspawn.sqs
#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)m that you can setpos too
_countpos = count tx_spawnpos
;; counter for selecting the element in the tx_spawnunits array
_unit = 0

#START
~0.5
;; 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
tx_spawnunits select _unit setpos (getpos tx_spawnpos select _pos)
_unit = _unit + 1
?(_unit >=(_countunits - 1)): exit

;;;;tx_spawnpos = tx_spawnpos - [_pos]
;;;;_countpos = count tx_spawnpos

goto "START"

This is what I've done.

I have placed 7 units (all individually named s1~s7) and under the leaders init box;
tx = group this;

I have placed 15 logics (logic1~logic15)

No joy...suggestions?



« Last Edit: 17 Apr 2005, 17:35:44 by deuxmad »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Random Spawning
« Reply #7 on: 18 Apr 2005, 19:27:50 »
are you saying that for some units, not in a group the system works fine, however for units in a group, they dont

simple, set their special field to "none" in the mission editor, eg make sure it doesnt show "formation" otherwise they will always setpos themselves to their group leader at mission start
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

deuxmad

  • Guest
Re:Random Spawning
« Reply #8 on: 19 Apr 2005, 00:42:41 »
Nope they dont 'energise' (for star trek fans) or 'spawn' at the gamelogics at all.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Random Spawning
« Reply #9 on: 19 Apr 2005, 17:51:01 »
Duh my fault


i used tx_spawnpos  instead of tx_spawnarray

eg

_countpos = count tx_spawnpos

should be

_countpos = count tx_spawnarray

change all tx_spawnpos to tx_spawnarray

or easier still

rename tx_spawnarray (found in the init.sqs) to tx_spawnpos
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

deuxmad

  • Guest
Re:Random Spawning
« Reply #10 on: 20 Apr 2005, 00:37:34 »
Really sorry Terox, but that doesn't work either.

What I have:
Code: [Select]
;INIT.sqs


tx_spawnpos = [logic1,logic2,logic3,logic4,logic5,logic6,logic7,logic8,logic9,logic10,logic11,logic12,logic13,logic14,logic15]

tx_spawnunits = [s1,s2,s3,s4,s5,s6,s7]

[] exec "randomspawn.sqs"



Code: [Select]
#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)m that you can setpos too
_countpos = count tx_spawnarray
;; counter for selecting the element in the tx_spawnunits array
_unit = 0

#START
~0.5
;; 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
tx_spawnunits select _unit setpos (getpos tx_spawnarray select _pos)
_unit = _unit + 1
?(_unit >=(_countunits - 1)): exit

;;;;tx_spawnpos = tx_spawnposrray - [_pos]
;;;;_countpos = count tx_spawnarray

goto "START"

Recap.

Total of 7 player slots all grouped at start with 'none' in the 'Special' box.
Each of them are named from s1~s7.
Under the Leader of the group init box is 'tx = group this'

Placed random spawn areas for the 'logics' (1~15).

Is there something missing?


Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Random Spawning
« Reply #11 on: 20 Apr 2005, 16:57:10 »
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.zip

I have added an additional line

dostop _soldier

this was to prevent the ai units from moving back into formation after the setpos code had been run


here's the full system

Mission Editor
x * 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
Quote
;;; 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
Quote

~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
Quote
;;; 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
Quote

~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
« Last Edit: 20 Apr 2005, 17:02:24 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

deuxmad

  • Guest
Re:Random Spawning
« Reply #12 on: 21 Apr 2005, 05:03:14 »
Works like a charm on my end too with your updated randompos.zip.

However, this isnt something I was looking for but, you're surely helping me understand the OFP language abit more at a time. :)
I really appreciate that Terox.

But how can I have it, so that the whole group spawns (without separating from the group at spawn) at the same 'logic#'.

The current version allows each soldier in the group to spawn at separate 'logic#s'.
 i.e - the spawned soldier is no where near the other soldiers.
 or
 i.e - s1 spawns at logic3 while s5 spawns at logic10
I would really like all of them to spawn together at the same logic#, but obviously with other logics to randomize their initial spawn at the start.


At least we're heading in the same direction this time.  :)

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Random Spawning
« Reply #13 on: 21 Apr 2005, 16:18:35 »
you simply setpos each unit in the group to the same logic

Randomspawn.sqs
Quote

~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)
;; for a list  of units held in an array, use the following
{_x setpos _position}  forEach tx_spawnunits


;; or alternatively to setpos all the units within the same group use the following
{_x setpos _position}  forEach units  tx

exit

this is used on the conditions
a) the group is called tx
b) and the script is run on the server, eg ?(local server):
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

deuxmad

  • Guest
Re:Random Spawning
« Reply #14 on: 21 Apr 2005, 17:03:19 »
Thanks Terox, I'll check it out.