Binary 0 Posted February 28, 2008 Hello all I'm currently designing a mission that have 8 players that need to spawn eight different places at random. By this i mean, that i have 8 markers on the map. The 8 players should spawn RANDOM at any of these markers upon starting the mission. The 8 players should all start at a different marker, no 2 players should spawn at the same spot. I've searched the forums a bit, but haven't found anything applicable in my scenario. Any thoughts? Share this post Link to post Share on other sites
Dragonian 0 Posted February 28, 2008 Try one of these: SQF format Quote[/b] ]// array of the units _playerarray = [unitname1, unitname2, unitname3, unitname4, unitname5, unitname6, unitname7, unitname8]; // array of the marker names (remember double quotes "") _markerarray = ["marker1", "marker2", "marker3", "marker4", "marker5", "marker6", "marker7", "marker8"]; // 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]; }; SQS format: Quote[/b] ]; array of the units _playerarray = [unitname1, unitname2, unitname3, unitname4, unitname5, unitname6, unitname7, unitname8] ; array of the marker names (remember double quotes "") _markerarray = ["marker1", "marker2", "marker3", "marker4", "marker5", "marker6", "marker7", "marker8"] ; loop through playerarray and move each player to a marker selected randomly _i=0 #markerloop ?(_i>=(count _playerarray)): goto "end" _currentplayer = _playerarray select _i _randommarker = _markerarray select (floor(random(count _markerarray))) _currentplayer setpos (getmarkerpos _randommarker) _markerarray = _markerarray - [_randommarker] _i=_i+1 goto "markerloop" #end You can put as many players and markers as you want as long as there is at least one marker for each player (yes, you can put more markers than players to randomize it even more). Share this post Link to post Share on other sites
Binary 0 Posted February 28, 2008 Thats perfect ! Just what i was looking for Will try it out right away. Share this post Link to post Share on other sites
Binary 0 Posted February 29, 2008 Works like a charm Thanks Share this post Link to post Share on other sites
dwringer 45 Posted March 1, 2008 Wow, this script is great for a lot of things; it's exactly what I've been trying to figure out for urban scenarios (random insurgents popping in at unexpected locations, for example). Heck, enough of these scripts in a mission and you can have call of duty style gameplay, except more dynamic Share this post Link to post Share on other sites
Αplion 1122 Posted March 20, 2008 Is it possible to have all the players randomly respawned ? I mean all together without the need to be grouped. Also is it possible to advise from where we must call this script (trigger - marker - player init .......). thanks Share this post Link to post Share on other sites
dwringer 45 Posted March 21, 2008 Yeah, there should be a few ways to cause several units to spawn at the same randomly selected marker. I took the liberty of modifying the above sqs script for my own missions, and did it thusly: [in this example, you can move any number of troops in 5-man increments to randomly selected markers. you could easily make this 8, 9, 12, whatever. if you want one of the sets of troops to be less than that number, you can just fill it with game logic units instead of soldiers to take up the empty space.] <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _manarray = [t00, t01, t02, t03, t04, t00_1, t01_1, t02_1, t03_1, t04_1, t00_2, t01_2, t02_2, t03_2, t04_2, t00_3, t01_3, t02_3, t03_3, t04_3, t00_4, t01_4, t02_4, t03_4, t04_4] _markerarray = ["m00", "m01", "m02", "m03", "m04", "m05", "m06", "m07", "m08", "m09", "m0a", "m0b", "m0c", "m0d", "m0e", "m0f"] _i=0 #markerloop ?(_i>=(count _manarray)): goto "end" _randommarker = _markerarray select (floor(random(count _markerarray))) "x1" setmarkerpos getmarkerpos _randommarker "x2" setmarkerpos [(getmarkerpos _randommarker select 0) + 1.5, (getmarkerpos _randommarker select 1) + 1, (getmarkerpos _randommarker select 2) + 1] "x3" setmarkerpos [(getmarkerpos _randommarker select 0) + 3, (getmarkerpos _randommarker select 1) + 2, (getmarkerpos _randommarker select 2) + 2] "x4" setmarkerpos [(getmarkerpos _randommarker select 0) - 1.5, (getmarkerpos _randommarker select 1) + 1, (getmarkerpos _randommarker select 2) + 1] "x5" setmarkerpos [(getmarkerpos _randommarker select 0) - 3, (getmarkerpos _randommarker select 1) + 2, (getmarkerpos _randommarker select 2) + 2] _xa = ["x1", "x2", "x3", "x4", "x5"] _j=0 #populate ?(_j>=(count _xa)): goto "cont" _currentman = _manarray select _i _currentmarker = _xa select _j _currentman setpos (getmarkerpos _currentmarker) _i=_i+1 _j=_j+1 goto "populate" #cont _markerarray = _markerarray - [_randommarker] goto "markerloop" #end Also, keep in mind that for the above script, you must place "dummy markers" anywhere in your map named x1, x2, x3, x4, and x5. These are used in calculating the positions to spawn the troops once a marker has been selected. This is probably the sloppiest area of my script, as you don't really need to do it that way. I just like the way it makes sense to me [Edit: You may also notice that this starts each set of five units out in a compact wedge facing south. If they're grouped, you'll see them move around after being spawned to get themselves into a more proper formation. You can add some code to the script to get them to watch a certain direction or target too, but it's largely mission dependent unless someone has a nice elegant way to put them in tactically advantageous orientations Share this post Link to post Share on other sites
Αplion 1122 Posted March 22, 2008 Thanks a lot dwringer much obliged Share this post Link to post Share on other sites