Jump to content
Victor G Vilar

Spawning randomly playable units

Recommended Posts

Super newbie here, sorry. I've been searching but no luck. I tried this script where I see how to randomly spawn the player

https://forums.bohemia.net/forums/topic/188007-random-player-spawn/

 

_spawn_pos = ["marker1", "marker2", "marker3", "marker4", "marker5", "marker6", "marker7", "marker8", "marker9", "marker10"] call BIS_fnc_selectRandom;
waitUntil {!isnull player};
player setPos (getMarkerPos _spawn_pos);

 

But the same script doesn't work with other playable units because instead 'player' might be another name, I guess, but I don't know what. Those playable units remain where I placed them in the editor. Any idea?

Thanks

  • Like 1

Share this post


Link to post
Share on other sites
13 minutes ago, Victor G Vilar said:

I tried this script

 

Where are you placing the script? It should be in initPlayerLocal.sqf.

 

"Player" is a command.

Share this post


Link to post
Share on other sites

Hey @Victor G Vilar and welcome 🤚!

 

If your playables unit are in the same group as you, you can set random spawn using the group leader init in the editor :

 

this setPos (selectRandom [getMarkerPos namemarker1,getMarkerPos namemarker2,...etc...]); {vehicle _x setpos formationposition _x} foreach units this;

This code make your group stay in formation and stay in following the leader, so if your group leader is spawning somewhere, others would be here too.

 

To do something more specific, you can check this topic and as @Harzach said, you need to place this kind of script in initPlayerLocal.sqf in your mission's folder.

 

Hope this help ! 😊

Share this post


Link to post
Share on other sites

Thanks both.

The code I posted it's included in the initPlayerLocal. And it works in the current player (it appears in different markers each time the mission begins) but not the playable ones. I want each player in different places not together.

The other alternative in the link I posted before is a init.sqf file, yes (below)  but it doesn't work either. In fact it's worst since the current player appears in the lower left corner of the map and the other one still is in the init location without placing it in any marker position:

if (hasInterface) then {

_spawn_pos = ["marker1", "marker2", "marker3", "marker4", "marker5", "marker6", "marker7", "marker8", "marker9", "marker10"] call BIS_fnc_selectRandom;
waitUntil {!isnull player};
player setPos (getMarkerPos _spawn_pos);
};

 

 

Share this post


Link to post
Share on other sites

With each player in a random place, you can use InitServer.sqf and name your playables units :

 

_spawn_pos = ["marker1", "marker2", "marker3", "marker4", "marker5", "marker6", "marker7", "marker8", "marker9", "marker10"] call BIS_fnc_selectRandom;
waitUntil {!isnull player};
unit1name setPos (getMarkerPos _spawn_pos);
unit3name setPos (getMarkerPos _spawn_pos);
unit2name setPos (getMarkerPos _spawn_pos);
...

Not really elegant but functional i think. But you maybe spawn at the same marker as another unit.

 

You can also use empty markers on the editor and link them to your unit as right click -> Link -> random position
Every linked marker could be a spawn position to the unit.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Victor G Vilar said:

but not the playable ones.

 

How many players are joining your server to test this? If you have multiple playable units, but only one person joins the server, only that player's unit will be moved. To be clear, a playable unit will only be moved once it is being controlled by a human player. That is what hasInterface is checking for.

  • Like 1

Share this post


Link to post
Share on other sites
11 hours ago, Harzach said:

 

How many players are joining your server to test this? If you have multiple playable units, but only one person joins the server, only that player's unit will be moved. To be clear, a playable unit will only be moved once it is being controlled by a human player. That is what hasInterface is checking for.

Ok, I was testing all the time in editor not the server... I thought it could run without using a server but as you say this must be the problem, just an AI player.

 

 Thanks both, your answers helped me

Share this post


Link to post
Share on other sites

Funny i did a few videos on this subject:

 

Start Your Scenario at a Random Helicopter Crash Site with this Script!

 

How to setup Random Starting Positions for Players, Vehicles, or Objects!

 

Start in Random Locations in Your Scenarios!

 

  • Like 1

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

×