Home   Help Search Login Register  

Author Topic: Randomly placing groups  (Read 1155 times)

0 Members and 1 Guest are viewing this topic.

Offline Binary

  • Members
  • *
Randomly placing groups
« on: 16 Apr 2008, 00:37:59 »
Hi all :)

Below i have posted a .sqf sample that randomly places 8 units at 14 random spawn points.
I am looking for a way to modify this so that it instead randomly places these units in buddyteams.

Currently there are 8 groups of 1 units - that spawn at one of the 14 spawn points.

Just to clarify:
I want to have 4 groups of 2 units.
These buddyteams should spawn at any of the 14 spawn points.
No buddyteams should spawn at the same place.

Code sample from init.sqf:

// array of the units
_playerarray = [player1, player2, player3, player4, player5, player6, player7, player8];

// array of the marker names (remember double quotes "")
_markerarray = ["spawn1", "spawn2", "spawn3", "spawn4", "spawn5", "spawn6", "spawn7", "spawn8", "spawn9", "spawn10", "spawn11", "spawn12", "spawn13", "spawn14"];


// loop through playerarray and move each player to a marker selected randomly
for[{_i=0},{_i<(count _playerarray)},{_i=_i+1}]
do
{
_currentplayer = _playerarray select _i;
_randommarker = _markerarray select (floor(random(count _markerarray)));

_currentplayer setpos (getmarkerpos _randommarker);
_markerarray = _markerarray - [_randommarker];
};



The script is something i grapped of the BIS forums - my personnel scripting ability is very limited.

Any help would be greatly appreciated :)
"Ah.. Home sweet hell !" - Al Bundy

Offline Loyalguard

  • Former Staff
  • ****
Re: Randomly placing groups
« Reply #1 on: 16 Apr 2008, 13:57:07 »
This is untested but I think it will work.  I have placed comments where I have changed or added code with an explanation as to what it does.  Basically, the loop now counts by twos so that there are half as many loops since we are teaming players by twos (note, if you use an uneven number of units this may fail).  In the step code we add a second player and put him in the same place as the player before him.  This was 1&2 are a team, 3&4, etc, etc.  I hope this helps or is at least a start:

Code: [Select]
// array of the units
_playerarray = [player1, player2, player3, player4, player5, player6, player7, player8];

// array of the marker names (remember double quotes "")
_markerarray = ["spawn1", "spawn2", "spawn3", "spawn4", "spawn5", "spawn6", "spawn7", "spawn8", "spawn9", "spawn10", "spawn11", "spawn12", "spawn13", "spawn14"];


// loop through playerarray and move each player to a marker selected randomly
for[{_i=0},{_i<(count _playerarray)},{_i=_i+2}] // Changed _i+1 to _i+2 so the loop skips the second buddy team member.
do
{
     _currentplayer = _playerarray select _i;
     _nextplayer = _playerarray select (_i+1); // Add the second buddy team member who is the next player in the array.
     _randommarker = _markerarray select (floor(random(count _markerarray)));

     _currentplayer setpos (getmarkerpos _randommarker);
     _nextplayer setpos (getmarkerpos _randommarker); // setPos the second buddy team member to the same pos as the player before.
     _markerarray = _markerarray - [_randommarker];
};
« Last Edit: 16 Apr 2008, 14:03:35 by Loyalguard »

Offline Binary

  • Members
  • *
Re: Randomly placing groups
« Reply #2 on: 16 Apr 2008, 21:41:55 »
Loyalguard...................  :clap: :clap:
You my good sir, is a fantastic man  :D

Works perfect, like a charm :)
"Ah.. Home sweet hell !" - Al Bundy