Jump to content
Sign in to follow this  
PiNs_Da_Smoka

Random MP Spawning?

Recommended Posts

Say at the beginning of a mission (MP) I want OPFOR to spawn at different locales. Meaning ALL of the OPFOR side at the same place. One mission they may spawn at base #1 the next maybe base #5. How exactly would I go about this. I imagine a script set to randomly call up pre-made markers at the bases but I have the slightest idea as how to go about it. Sorry, I haven't touched this editor or scripts since OFP, so sorry if this is really vague.

Also, is it possible to do with the base itself if each one was say, in the middle of a field?

Share this post


Link to post
Share on other sites

Ok so i kind of answered my own question. I found this script.

init.sqs

;;; array containing all names of gamelogics
tx_spawnpos = [logic1,logic2,logic3]
?(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

My question now is. How can I make this for every player on the OPFOR side of the server, and ALSO for all vehicles and buildings with them. Not just bring the vehicles/buildings with them, but have them spawn in the same way they were created? I imagine they will do that regardless, but I have yet to figure out how to get them to go anyways. Any help is much appreciated.

Edit: How can I make this so only one side, OPFOR, does this random spawning? I want the BLUFOR to spawn in one static position.

Edited by PiNs_Da_Smoka

Share this post


Link to post
Share on other sites

For the objects i think the easiest way to basicly spawn a all buildings that you created as a whole as: dynamic object composition. What it gives you is basicly exactly what you ask. You can then call a BIS function (see function module) to spawn that whole Dynamic object group on a position.

That position can be (by example) a random from a 5 element array containing positions ([pos,pos,pos,pos,pos]). There is a random function availabe in the functions module (check out the help in that).

That same pos can then be used to move all players and stuff. Most easy way to determine a " safe pos" is use hte funciton bis_safe_pos (or something like that) in the functions module.

I realise this is not concrete to immidiately get you finish it. Its one way of doing it. have fun figure it all out:)

Share this post


Link to post
Share on other sites

Step by step,

1. Get the locations you want the player to spawn at and store em in a global variable.

ex:

respawnLocation=[base1,base2,base3,base4,base5]

2. Add a Killed EventHandler to the players.

ex:

player addEventHandler ["Killed",{[]ExecVM "Client_Killed.sqf"}]

3. In the Killed Eventhandler triggered action add some stuff like that:

//--- Maximum of respawn locations, we use -1 since a count start at 1 & a select start at 0.
_max = count respawnLocation -1;
//--- Randomizing.
_randomMax = round(random(_max));
//--- We get a random location from the bases.
_location = respawnLocation select _randomMax;

//--- we wait until player is back alive before moving him (he is still respawning).
waitUntil {alive player};

//--- we move the player to the random location.
player setPos _location;

Edited by Benny.

Share this post


Link to post
Share on other sites

Thanks for the input Benny. While there is no respawn in the mission, this was not able to be used. But I did have somebody come up with this.

init.sqs

if (isServer) then { [] spawn compile preprocessFile "randomOpforSpawn.sqf" };

randomopforspawn.sqf

_initial_area = opfor_setup; // The game logic object at the center of the setup area for opfor
_move_radius = 200; // The radius around the above object to grab stuff
_spawns = [spawn1, spawn2, spawn3,spawn4,spawn5,spawn6]; // an array of the random spawns on the map
_spawn = _spawns select floor random count _spawns; // selects one of those random spawns
[getpos opfor_setup, getpos _spawn, _move_radius] spawn compile preprocessFile "moveArea.sqf"; // moves everything from one area to the other

movearea.sqf

waituntil {!isnil "BIS_fnc_init"}; // wait until BIS functions are ready (for vector functions)
_start = _this select 0;
_end = _this select 1;
_radius = _this select 2;
_nearobjs = _start nearObjects _radius;
{
_pos_diff = [getpos _x, _start] call BIS_fnc_vectorDiff;
_end_pos = [_pos_diff, _end] call BIS_fnc_vectorAdd;
_x setDir ((getDir _x + 180) mod 360);
       _x setPos _end_pos;
} forEach _nearobjs;

And this worked great up until you try it on a dedicated server. If the unit is used by a real player, they wont move. But if its just AI then it will go just fine.

So my question is this. Does anyone have any idea why it won't work when someone is in control of the unit on a dedicated server?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×