Jump to content
Somemech

Team Deathmatch win/end mission help.

Recommended Posts

Hello, I've been working on a small scale team deathmatch scenario. I've got most features working the way I want them, but I just need a bit of assistance with ending the mission and possibly resetting the round. 

 

So basically I need to check when one team is dead and grant victory to the winning team then reset the round. I tried searching for examples or tutorials of this but all of them so far have been about running out of tickets or something else. I just need to check when one team has been killed because I have it so that each player only has one life. Any help is appreciated. Thanks.

Share this post


Link to post
Share on other sites

One simple way to do so is to create two different groups in the editor and name their leader something like leader_1 and leader_2. Then in a script you could do something like

// This could go into init.sqf or initServer.sqf in case of MP
// Get the groups of the two leaders
private _grp1 = (units leader_1); // First group
private _grp2 = (units leader_2); // Second group

// Wait until one of the two groups is full of dead people
waitUntil {
	// Sleep a bit to save some CPU usage
	sleep 3; // Sleep for 3 seconds

	// Get alive units of both groups
	private _grp1_alive = _grp1 findIf{alive _x};
	private _grp2_alive = _grp2 findIf{alive _x};

	// Leave the waitUntil loop if any of the groups doesn't
	// have any units alive
	_grp1_alive == -1 || {_grp2_alive == -1};
};

// Do some ending cinematics or whatever here

Of course this assumes that the leader positions will be occupied or they will be playable AIs (they will be present when the mission starts). Alternatively, you could hardcode the names of the players variables in each group to make the groups yourself. This would look like

// First team
private _grp1 = [plr1, plr2, plr3, plr4]; // Consists of player 1 (plr1), up to player 4 (plr4)

// Second team
private _grp2 = [plr5, plr6, plr7, plr8]; // Consists of player 5 (plr5), up to player 8 (plr8)

// Wait until one of the two groups is full of dead people
waitUntil {
	// Sleep a bit to save some CPU usage
	sleep 3; // Sleep for 3 seconds

	// Get alive units of both groups
	private _grp1_alive = _grp1 findIf{alive _x};
	private _grp2_alive = _grp2 findIf{alive _x};

	// Leave the waitUntil loop if any of the groups doesn't
	// have any units alive
	_grp1_alive == -1 || {_grp2_alive == -1};
};

// Do some ending cinematics or whatever here

Finally, the "most correct" way of doing it (in my opinion at least) would be to get all the groups (hopefully you will have only two of them, one for each team) that contains players. This could be done like (copying from allGroups example 2)

// Get groups with players
private _grps = []; // Initialise groups variable
{
	// Add the group if not already in the array
	_grps pushBackUnique (group _x);
} forEach allPlayers;

// Wait until one of the two groups is full of dead people
waitUntil {
	// Sleep a bit to save some CPU usage
	sleep 3; // Sleep for 3 seconds
	
	// Find out if there's any group with all the players dead
	private _stop = (_grps findIf{((units _x) findIf{alive _x}) == -1;}) != -1;

	// Return if stop criterion is met
	_stop
};

// Do some ending cinematics or whatever here

Please keep in mind that these scripts are NOT tested and treat them with caution.

 

Hope this helps somehow. If not, or if you have any more questions, please don't hestitate to ask.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for your help. I'll try these out as soon as I can. 👍

  • Like 1

Share this post


Link to post
Share on other sites

Let me add some more info on the above examples. I spent some more time on it and realised that allPlayers returns all the units controlled by players (connected clients) plus the headless clients. In addition to that, if you happen to start the game without all the players being connected, the above scripts won't get the new players. If there's at least one player in each team this is not an issue, but if there's a team without a player then you won't be able to get that group. A workaround on that is to use playableUnits, BUT this command in single-player returns an empty array. Thus, you would have to use switchableUnits if you intend to use the mission on single-player too. A more complete example would be

// Get groups with players
private _grps = []; // Initialise groups variable

// Check whether we play MP or SP
if(isMultiplayer) then {
	// If in MP, use playableUnits
	{
		// Add the group if not already in the array
		_grps pushBackUnique (group _x);
	} forEach playableUnits;
} else {
	// If in SP, use switchableUnits
	{
		// Add the group if not already in the array
		_grps pushBackUnique (group _x);
	} forEach switchableUnits;
};

// Wait until one of the two groups is full of dead people
waitUntil {
	// Sleep a bit to save some CPU usage
	sleep 3; // Sleep for 3 seconds
	
	// Find out if there's any group with all the players dead
	private _stop = (_grps findIf{((units _x) findIf{alive _x}) == -1;}) != -1;

	// Return if stop criterion is met
	_stop
};

// Do some ending cinematics or whatever here

If you can be sure that all players will be online before the mission start you can use the last script provided in the previous answer with the difference that you should make sure you won't get headless clients. Copying from allPlayers example 1 you can do

// Get only players and exclude headless clients
private _plrs = allPlayers - (entities "HeadlessClient_F);

So, once more, copying the last script from the previous answer with this new "addition/correction" you have

// Get all players without headless clients
private _plrs = allPlayers - (entities "HeadlessClient_F");

// Get groups with players
private _grps = []; // Initialise groups variable
{
	// Add the group if not already in the array
	_grps pushBackUnique (group _x);
} forEach plrs; // <- CHANGED THE ARRAY TO ITERATE THROUGH

// Wait until one of the two groups is full of dead people
waitUntil {
	// Sleep a bit to save some CPU usage
	sleep 3; // Sleep for 3 seconds
	
	// Find out if there's any group with all the players dead
	private _stop = (_grps findIf{((units _x) findIf{alive _x}) == -1;}) != -1;

	// Return if stop criterion is met
	_stop
};

// Do some ending cinematics or whatever here

Hope one of these examples will be sufficient for your case. If not, don't hesitate to communicate your needs to find a better solution together.

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

×