Jump to content

Recommended Posts

HI All,

I'm using the following scripts to update the respawn sectors in a MP COOP game. It works, however, every time more than one player dies the RESPAWN MENU generates multiple respawn sectors of the same type, depending on how many players are dead, which looks confusing.

 

How should I modify this so that the RESPAWN MENU only uses the latest sectors from the last player that died?

 

description.ext 

respawnTemplates[] = {"MenuInventory","MenuPosition"};

onPlayerRespawn.sqf

//run on all player clients incl. player host and headless clients
if (!isDedicated) then {
	//Once the player has respawned
	//Remove all sector respawn positions
	[ "REM_ALL" ] call TAG_fnc_respawnPositions;
};	

onPlayerKilled.sqf

//When player dies
//For every sector
{		
	//If the sector is owned by the players side
		if ( ( _x getVariable "Owner" ) isEqualTo playerSide ) then {
			//Add a respawn position
			[ "ADD", _x ] call TAG_fnc_respawnPositions;
		};
}forEach BIS_fnc_moduleSector_sectors;

 

initPlayerLocal.sqf

Quote

TAG_fnc_respawnPositions = {
	params [ "_mode", "_sector" ];
		hint format ["%1",_mode];
	//Get player current sector respawn positions
	_respawnPositions = player getVariable [ "respawnPositions", [] ];
	switch ( _mode ) do {
		
		case "ADD" : {
			
			//Obtain array of dead players from each side
				_deadPlayersArray = [];
				_allPlayersArray = call BIS_fnc_listPlayers;
				{
					if !(alive _x) then {_deadPlayersArray pushBackUnique _x};
				} forEach _allPlayersArray;
				// only run add sectors if there is no more than on dead player from either side otherwise it will add the same respawn position for every dead player
				hint format [" _deadPlayersArray: \n %1 \n\n count _allPlayersArray: \n %2 ", _deadPlayersArray,_allPlayersArray];
				if ( count _deadPlayersArray > 1 ) then {
			
			
			//Get a random sector area trigger ( as a sector can have multiple areas )
			_sectorTrig = selectRandom ( _sector getVariable "Areas" );
			//Get a random position inside the trigger
			_pos = [ _sectorTrig ] call BIS_fnc_randomPosTrigger;
			//Add a respawn position for this player
			_name = "";
			switch (_sector) do {
				{
					case _x : {_name =  _x getVariable "Name"};
				}forEach BIS_fnc_moduleSector_sectors;
				//}forEach allSectorsArray;
			};
			if ( count _deadPlayersArray == 1 ) then {
				_respawnPos = [ playerSide, _pos, _name ] call BIS_fnc_addRespawnPosition;
				//update current sector respawn positions
				_nul = _respawnPositions pushBack [ _sector, _respawnPos ];
			} else {
				_respawnPos = [ playerSide, _pos ] call BIS_fnc_addRespawnPosition;			
			};
		};
		
		case "REM" : {
			//For each of the players sector respawn positions
			{
				_x params[ "_sec", "_respawnID" ];
				//if the sector is the one we are looking for
				if ( _sector isEqualTo _sec ) then {
					//Remove the respawn position
					_respawnID call BIS_fnc_removeRespawnPosition;
					//Update players sector respawns
					_respawnPositions deleteAt _forEachIndex;
				};
			}forEach +_respawnPositions;
		};
		
		case "REM_ALL" : {
			//For each of the players current respawn positions
			{
				_x params[ "_sector", "_respawnID" ];
				//Remove the respawn position
				_respawnID call BIS_fnc_removeRespawnPosition;
			}forEach _respawnPositions;
			//Empty players respawn ARRAY
			_respawnPositions = [];

		};
	};
	
	//Update respawn positions variable on the player
	player setVariable [ "respawnPositions", _respawnPositions ];
}; 


//BI RESPAWN MENU - IDD 58 PLAY OutfitMenuMusic
if (!isDedicated) then { 
	waitUntil {!(isNull (findDisplay 58))}; 
	if (isNil "BEAK_MUSIC_INIT") then {
		BEAK_MUSIC_INIT = 1;
		playMusic "OutfitMenuMusic";
		_music = addMusicEventHandler ["MusicStop",{playMusic (_this select 0)}];
		waitUntil {isNull (findDisplay 58)};
		removeMusicEventHandler ["MusicStop",_music];
		playMusic "";
	};  
};

// Remove RESPAWN from Pause Menu since respawnButton = 0; does not work!
if (!isDedicated) then {
    for "_i" from 0 to 1e+1000 do 
    { 
        waitUntil {!isNull (findDisplay 49)}; 
        ((findDisplay 49) displayCtrl 1010) ctrlEnable false; 
    }; 
};

 

 

initServer.sqf

Quote


//Update respawn positions if they change whilst the player is dead
//For every sector
{
	//When the sectors owner changes
	[ _x, "ownerChanged", {
		params[ "_sector", "_owner" ];
		
		{
			//If the player is dead
			if !( alive _x ) then {
				//And the sector is owned by players side
				if ( _owner isEqualTo side group _x ) then {
					//Add a respawn position
					[ "ADD", _sector ] remoteExec [ "TAG_fnc_respawnPositions", _x ];
				}else{
					//Else remove this sectors respawn position
					[ "REM", _sector ] remoteExec [ "TAG_fnc_respawnPositions", _x ];
				};
			};
		}forEach allPlayers;
	}] call BIS_fnc_addScriptedEventHandler;
}forEach BIS_fnc_moduleSector_sectors;	

 

 

Share this post


Link to post
Share on other sites
4 hours ago, cklymowsky said:

however, every time more than one player dies the RESPAWN MENU generates multiple respawn sectors of the same type

Because you have changed the call to BIS_fnc_addRespawnPosition to use the players side.

_respawnPos = [ playerSide, _pos, _name ] call BIS_fnc_addRespawnPosition;

If a side is used in the call then the positions are publicly shared for all players of this side. My original script used player, so the positions where relevant to that client only.

Share this post


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

My original script used player, so the positions where relevant to that client only.

 

Thanks Larrow,

 

Switching from playerSide to player, resolves the duplication of sector names in the RESPAWN MENU, with on slight, very minor issue, the RESPAWN MENU for a player already dead, will not be updated with the sector "Name" of a newly captured sector, until they die and the list of sector "Name" are updated.

 

Still works even though an area with a same sector is available to respawn in. during this time.

 

 

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

×