Jump to content
Sign in to follow this  
-TFP- Bridge.J

Help needed with random spawnpoints

Recommended Posts

Hi all,

I'm working on a mission which has over 20 initial spawns the player could get. It's a co-op mission and I can't get it to pick the same spawn for the other players.

I want it to pick a spawn, move the players to that spawn and then move some static parachutes (from invasion 1944) to the players themselves.

Been trying to work this out for ages, and now I'm turning to you guys for assistance. :)

Jake.

Share this post


Link to post
Share on other sites

_spawns = ["spawn1","spawn2","spawn3"];
_spawn = _spawns select (floor(random(count _spawns)));

player setpos (getmarkerpos _spawn);

Something like that for every player. Make sure you select the spawn OUTSIDE any for, while or foreach loop.

Share this post


Link to post
Share on other sites

Wouldn't that set a different spawn for each player? I want them all to start at the same spawn point.

Share this post


Link to post
Share on other sites

It wouldn't if you do it outside a loop.

_spawns = ["spawn1","spawn2","spawn3"]; // These are your markers.
_spawn = _spawns select (floor(random(count _spawns))); // This selects the marker name (for example sake it'll equal 1, so "spawn2").

{_x setpos (getmarkerpos _spawn)} foreach playableUnits;

This will get everybody to 1 location, whereas the below will select a new spawnpoint for every player:

while {true} do {
_spawns = ["spawn1","spawn2","spawn3"]; // These are your markers.
_spawn  = _spawns select (floor(random(count _spawns))); // This selects the  marker name (for example sake it'll equal 1, so "spawn2").

player setpos (getmarkerpos _spawn);
};

Share this post


Link to post
Share on other sites

It doesn't work :/

Just leaves all the players where they were placed in the editor.

I was putting the script in my init.sqf, is that right?

(Edit) Here is my full init.sqf file. I've never scripted before so I may not have this done correctly. The title text part works but the spawning doesn't.

_spawns = ["SpawnA","SpawnB","SpawnC"]; // These are your markers.
_spawn = _spawns select (floor(random(count _spawns))); // This selects the marker name (for example sake it'll equal 1, so "spawn2").

{_x setpos (getmarkerpos _spawn)} foreach playableUnits;  

titleCut ["", "BLACK FADED", 999];
[] Spawn {
waitUntil{!(isNil "BIS_fnc_init")};

titleText ["On the run.","PLAIN DOWN"]; 
titleFadeOut 7;
sleep 3;

titleText ["Created by Omegaspectre & Cheeserdude.","PLAIN"];
titleFadeOut 7;
sleep 3;

titleText ["Your B17 has been shot down behind enemy lines,","PLAIN"];
titleFadeOut 9;
sleep 5;

titleText ["Now you must try and escape the Germans and get out of Chernarus. Good luck.","PLAIN"];
titleFadeOut 12;
sleep 5;

// Info text
[str ("Behind enemy lines.."), str("30 minutes after crash.."), str(date select 1) + "." + str(date select 2) + "." + str(date select 0)] spawn BIS_fnc_infoText;

sleep 3;
"dynamicBlur" ppEffectEnable true;   
"dynamicBlur" ppEffectAdjust [6];   
"dynamicBlur" ppEffectCommit 0;     
"dynamicBlur" ppEffectAdjust [0.0];  
"dynamicBlur" ppEffectCommit 5;  

titleCut ["", "BLACK IN", 5];
};

Share this post


Link to post
Share on other sites

The problem here is that the init.sqf will be executed for every client AND the server, so naturally all of your players will be placed to a different location.

What you need to do is to pick a random spawnlocation and send this to every player who joins (even JIT players).

This is done rather easy so here's an example init.sqf:


if (isServer) then
{
   _spawns = ["SpawnA","SpawnB","SpawnC"]; // These are your markers.
   spawnLocation = _spawns select (floor(random(count _spawns))); // This selects the marker name (for example sake it'll equal 1, so "spawn2").

   publicVariable "spawnLocation";
}
else
{
   waituntil {!isNil "spawnLocation"};   // Wait until the server did choose a spawnlocation and broadcasted it
   player setPos (getmarkerpos spawnLocation);

   titleCut ["", "BLACK FADED", 999];

   [] Spawn {
   waitUntil{!(isNil "BIS_fnc_init")};

   titleText ["On the run.","PLAIN DOWN"]; 
   titleFadeOut 7;
   sleep 3;

   titleText ["Created by Omegaspectre & Cheeserdude.","PLAIN"];
   titleFadeOut 7;
   sleep 3;

   titleText ["Your B17 has been shot down behind enemy lines,","PLAIN"];
   titleFadeOut 9;
   sleep 5;

   titleText ["Now you must try and escape the Germans and get out of Chernarus. Good luck.","PLAIN"];
   titleFadeOut 12;
   sleep 5;

   // Info text
   [str ("Behind enemy lines.."), str("30 minutes after crash.."), str(date select 1) + "." + str(date select 2) + "." + str(date select 0)] spawn BIS_fnc_infoText;

   sleep 3;
   "dynamicBlur" ppEffectEnable true;   
   "dynamicBlur" ppEffectAdjust [6];   
   "dynamicBlur" ppEffectCommit 0;     
   "dynamicBlur" ppEffectAdjust [0.0];  
   "dynamicBlur" ppEffectCommit 5;  

   titleCut ["", "BLACK IN", 5];
   };  
};

Share this post


Link to post
Share on other sites

Doesn't work :/

When I used it as my init.sqf I just spawned wherever the unit had been placed in the editor. Only this time I got none of my title text either.

Share this post


Link to post
Share on other sites

Okay I think I know why you got placed there and no text appeared: I thought you were using a dedicated server, where the above code would have been executed just the way you wanted. But if you host the game and are the server, the above code would lead to blocking your init, hence no text.

Try this init.sqf :D

if (isServer) then
{
   _spawns = ["SpawnA","SpawnB","SpawnC"]; // These are your markers.
   spawnLocation = _spawns select (floor(random(count _spawns))); // This selects the marker name (for example sake it'll equal 1, so "spawn2").

   publicVariable "spawnLocation";
};

if (!isDedicated) then
{
   waituntil {!isNil "spawnLocation"};   // Wait until the server did choose a spawnlocation and broadcasted it
   player setPos (getmarkerpos spawnLocation);

   titleCut ["", "BLACK FADED", 999];

   [] Spawn {
   waitUntil{!(isNil "BIS_fnc_init")};

   titleText ["On the run.","PLAIN DOWN"]; 
   titleFadeOut 7;
   sleep 3;

   titleText ["Created by Omegaspectre & Cheeserdude.","PLAIN"];
   titleFadeOut 7;
   sleep 3;

   titleText ["Your B17 has been shot down behind enemy lines,","PLAIN"];
   titleFadeOut 9;
   sleep 5;

   titleText ["Now you must try and escape the Germans and get out of Chernarus. Good luck.","PLAIN"];
   titleFadeOut 12;
   sleep 5;

   // Info text
   [str ("Behind enemy lines.."), str("30 minutes after crash.."), str(date select 1) + "." + str(date select 2) + "." + str(date select 0)] spawn BIS_fnc_infoText;

   sleep 3;
   "dynamicBlur" ppEffectEnable true;   
   "dynamicBlur" ppEffectAdjust [6];   
   "dynamicBlur" ppEffectCommit 0;     
   "dynamicBlur" ppEffectAdjust [0.0];  
   "dynamicBlur" ppEffectCommit 5;  

   titleCut ["", "BLACK IN", 5];
   };  
};  

This time the code for the text and setting the position of the player is only executed when the client is not a dedicated server, as it doesn't need to show (it can't even "see") the text and doesn't have a "player" to move :D

If this doesn't work either, please report any error messages you encounter (if there were some).

Share this post


Link to post
Share on other sites

Still doesn't work :/

Getting no error messages either, it just places me where I put them in the editor.. and there's still no starting text.

Does it matter that I'm using letters for the spawns and not numbers? I've got SpawnA, SpawnB etc. instead of Spawn1, Spawn2 and such.

Share this post


Link to post
Share on other sites

Thats strange, I did test it now and it's working fine for me!

I just did paste the code from my last post into my init.sqf and I got to see the text and everytime I joined the game I got another spawn location (which is okay because I'm the server and the only one in the server).

You can use whatever name you want to give to your markers, there is no practical limitation (except of special characters I guess).

So we have to figure out why this script isn't working for you when it's working for me :D

Share this post


Link to post
Share on other sites

I'm confused, if it's working for you then I don't get why it's not working for me :(

I'm running this by going to multiplayer, hitting create game and then hosting it on LAN for my friend to join.

Could it be something to do with the fact the mission uses Invasion 1944 + CBA?

Also is there any modules or anything you have to place in the mission for it to work?

Share this post


Link to post
Share on other sites

Not that I know of, I'm not using any mod or anything else but the vanilla arma2.

I just exported the mission with this init.sqf as a multiplayer mission, made a new multiplayer game and joined it - worked for me, I saw the text as well as beeing spawn to one of the three locations.

So I guess it somehow has to do with your mission additions, maybe something is interfering with your init.sqf or you have to use another scriptfile to place this code? Well, to be honest, I don't know because I didnt ever use Invasion and the like ^^

Share this post


Link to post
Share on other sites

So could I put the code for the spawns and text in a separate script and have the init.sqf run that script? What command would tell the init to call another script?

Share this post


Link to post
Share on other sites

ExecVM is used to execute a SQF-File.

You'd insert it like this into your init.sqf:

execVM "setSpawnLocation.sqf";

But doing so would create new problems, because you actually want to delay the initialization of your game until a spawn point is chosen and relayed over network to the other clients.

Further more I don't think this will really help solve the problem, but it's worth a shot nevertheless.

In your shoes I'd try to copy the mission and strip out everything which is not vanilla to be able to discern the problem - if the problem subsides after you put out Invasion and/or CBA, you could slowly put them back and look when the problem is occuring again.

Share this post


Link to post
Share on other sites

i was having issues with this as well, if you want use this and add all of your stuff to it ( works well for me and sets the marker for the objective and moves the players to the spawn point

townlocations = 0;
spawnlocations = 0;


if (isServer) then { //server side random picks
townlocations = ["stratisairbase","agiamarina","killfarm","camprogain","kaminofiringrange","lzbaldy","camptempest","airstationmike","oldoutpost","satalite1","campmaxwell","girna","agiosloannis","agioscephas","jaycove","thespartan"] call BIS_fnc_selectRandom;
spawnlocations = ["sp","sp_1","sp_2","sp_3","sp_4","sp_5","sp_6","sp_7","sp_8","sp_9","sp_10","sp_11","sp_12","sp_13","sp_14","sp_15","sp_16","sp_17","sp_18","sp_19","sp_20","sp_21","sp_22","sp_23","sp_24","sp_25","sp_26","sp_27","sp_28","sp_29","sp_30"] call BIS_fnc_selectRandom;


"attack" setMarkerPos (getmarkerPos townlocations); //server side setpos of attack marker
publicvariable "townlocations";
publicvariable "spawnlocations";


{_x setpos (getmarkerpos spawnlocations)} foreach playableUnits; //server side move players to random spawn point


sleep 5; //testing
hint townlocations;
sleep 5; //testing
hint spawnlocations;
}
else {  //clients


};

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  

×