Jump to content
bertram

Select certain percentage of players randomly

Recommended Posts

I'm creating a Team vs Team mission where the sides are completely random aside from three players that selected the only Blufor, Opfor, and Independent role respectfully. Every other player will slot a civilian role and then from that pool it will be split evenly 3 ways and the players for each side will be teleported to their leader, assigned to that side and given gear based on their faction. I'm able to accomplish everything except splitting the players evenly three ways. I tried adding all players on the civilian side to an array and then randomly selecting from that and teleporting them however this doesn't ensure even distribution as each instance is random. Is there any MP reliable way to accomplish this? To state it simply, I just want to be able to select a third of players on the civilian side and be able to affect that third with another script and then do the same with the remaining 2/3rds.

Share this post


Link to post
Share on other sites

In MP, the first question is for JIP. The number of players can start at 0 on dedicated, 1 on hosted, then increases with the JIP.

If your mission starts for few people waiting for all slots played, there is no difficulty.

If on dedicated server with logging/delogging players,... it's more a count for played slots on each side and balance between them.

Did I miss something?

  • Thanks 1

Share this post


Link to post
Share on other sites

The mission is not persistent it will just have a pool of players at the start that need to be balanced, but to re-iterate, I want the players to be divided three ways randomly. So every player will only be able to slot on the civilian side and once the mission starts the script will randomly assign them their team. I'll look through this thread you linked and see if I can work out my goal when I have some time, but just glancing at it it seems like the OP here wanted a balance on the fly in which the players select their team themselves.

Share this post


Link to post
Share on other sites
Spoiler


//initServer.sqf

//When does automatic team selection happen??
waitUntil{ time > 0 }; //As mission starts

//Get all civilian players
_selection = allPlayers select{ side group _x isEqualTo civilian };

//How many teams to split them into
_numTeams = 3;

_teams = [];
_teams resize _numTeams;
_teams = _teams apply{ [] };

for "_i" from 1 to floor( count _selection / _numTeams ) do {
	for "_j" from 0 to ( _numTeams - 1 ) do {
		//Select random player
		_player = _selection deleteAt floor random( count _selection );
		//Assign as team _j
		_teams select _j pushBackUnique _player;
	};
};

//If we have any left over
if !( _selection isEqualTo [] ) then {
	{
		_teams select _forEachIndex pushBackUnique _x;
	}forEach _selection;
};


_teamData = [
	//Team 1
	[ BLU_leader, "B_Soldier_F" ],
	//Team 2
	[ OPFOR_leader, "O_Soldier_F" ], 
	//Team 3
	[ INDEP_leader, "I_Soldier_F" ]
];

{
	_teamData select _forEachIndex params[ "_leader", "_unitLoadout" ];
	{
		_x params[ "_player" ];
		
		//Do something with unit
		
		_group = group _player;
		
		[ _player ] joinSilent group _leader;
		_player setPosATL ( formationPosition _player );
		_player setUnitLoadout _unitLoadout;
		
		if ( units _group isEqualTo [] ) then {
			deleteGroup _group;
		};

	}forEach _x;
}forEach _teams;

Should give you something to work from.

 

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, Larrow said:
  Reveal hidden contents



//initServer.sqf

//When does automatic team selection happen??
waitUntil{ time > 0 }; //As mission starts

//Get all civilian players
_selection = allPlayers select{ side group _x isEqualTo civilian };

//How many teams to split them into
_numTeams = 3;

_teams = [];
_teams resize _numTeams;
_teams = _teams apply{ [] };

for "_i" from 1 to floor( count _selection / _numTeams ) do {
	for "_j" from 0 to ( _numTeams - 1 ) do {
		//Select random player
		_player = _selection deleteAt floor random( count _selection );
		//Assign as team _j
		_teams select _j pushBackUnique _player;
	};
};

//If we have any left over
if !( _selection isEqualTo [] ) then {
	{
		_teams select _forEachIndex pushBackUnique _x;
	}forEach _selection;
};


_teamData = [
	//Team 1
	[ BLU_leader, "B_Soldier_F" ],
	//Team 2
	[ OPFOR_leader, "O_Soldier_F" ], 
	//Team 3
	[ INDEP_leader, "I_Soldier_F" ]
];

{
	_teamData select _forEachIndex params[ "_leader", "_unitLoadout" ];
	{
		_x params[ "_player" ];
		
		//Do something with unit
		
		_group = group _player;
		
		[ _player ] joinSilent group _leader;
		_player setPosATL ( formationPosition _player );
		_player setUnitLoadout _unitLoadout;
		
		if ( units _group isEqualTo [] ) then {
			deleteGroup _group;
		};

	}forEach _x;
}forEach _teams;

Should give you something to work from.

 

I was trying to work this out myself and your post basically fulfilled everything I needed and a bit more. In particular giving members of each team gear. I may make changes as I go but at the moment I only made one minor change to line 53.

		_player setUnitLoadout (getUnitLoadout _leader);

This way team members will have the same gear as the leader. 

 

 

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

×