Jump to content
Sign in to follow this  
boriz

How to temporarily Enable/Disable player respawn with a script?

Recommended Posts

Solved thanks to sxp2high!

Hello dear ARMA community!

I am working on a new version of my cooperative Stress Fortress mission and I've ran into one major problem I need help with.

This is what I wanna do:

1) Mission starts, all players are spawned. Respawn is set to X seconds.

2) When an enemy enters the respawn zone, players respawn is disabled.

3) During this time, all dead players will stay in spectate mode.

4) When the respawn zone is clear again, players respawn is enabled.

5) From this moment, players will respawn as usual until step 2 repeats.

This is the problem:

I don't know how to disable and enable players' respawn with a script during a mission.

Does anyone know how to do this?

Edited by Boriz

Share this post


Link to post
Share on other sites

Hello :)

Haven't tested this, so it might not work as is.

Maybe I overlooked some things too.

But something like this should do it. Have a look and play around with it :)

// Use this variable to control respawn
respawn_disabled = false;

[] spawn {

// Some variables that control spectator options
RscSpectator_allowFreeCam = true; // Free cam
RscSpectator_hints = [true,true,true]; // Shows the controls as hint

// Get initial respawn time
_respawnTime = playerRespawnTime;

// Main loop
while {true} do {

	// Wait until respawn disabled
	waitUntil {respawn_disabled};

	// "Disable" actual respawn
	setPlayerRespawnTime 9999;

	// Wait until respawn is enabled again or player died
	waitUntil {!(respawn_disabled) || !(alive player)};

	// if respawn disabled AND player dead
	if (respawn_disabled && !(alive player)) then {

		// Maybe a little sleep so its not switching to spectator immediatly
		sleep 5;

		// Disable post processing effects for spectator (Fatigue blur and such)
		BIS_fnc_feedback_allowPP = false;

		// Start spectator
		cutRsc ["RscSpectator", "PLAIN"];

		// Wait until respawn is enabled again
		waitUntil {!(respawn_disabled)};

		// Re-enable post processing effects
		BIS_fnc_feedback_allowPP = true;

		// Set original respawn time
		setPlayerRespawnTime _respawnTime;

		//Respawn the player
		forceRespawn player;

	} else {

		// Set original respawn time
		setPlayerRespawnTime _respawnTime;

	};

};

};

Edited by sxp2high

Share this post


Link to post
Share on other sites

Thank you for such quick reply!

I've been implementing your script into my mission and it seems to be the exact thing I need. However there is one problem I don't know how to solve.

cutRsc ["RscSpectator", "PLAIN"];

This command starts the spectator mode but later it causes problems with the GUI when the player is respawned.

If I disable the spectator mode before or after spawning the player, it should be okay, but how do I do that?

I've already tried cutRsc ["Default", "PLAIN"]; but it did not helped. I've just got some error message.

Any ideas?

Share this post


Link to post
Share on other sites

Oh, right, the spectator should be terminated properly.

This should do it:

// Register layer once
_layer = ["specator_layer"] call BIS_fnc_rscLayer;

// Start spectator
_layer cutRsc ["RscSpectator", "PLAIN"];

// Stop spectator
_layer cutRsc ["", "PLAIN"];

Share this post


Link to post
Share on other sites

Thank you!

This is the finished script for anyone who needs it:

// Use this variable to control respawn
respawn_disabled = false;

[] spawn {
   // Some variables that control spectator options
   RscSpectator_allowFreeCam = true; // Free cam
   RscSpectator_hints = [true,true,true]; // Shows the controls as hint
// Register layer once
_spectatorLayer = ["specator_layer"] call BIS_fnc_rscLayer; 

   // Get initial respawn time
   respawnTime = 3;

   // Main loop
   while {true} do {
       // Wait until respawn disabled
       waitUntil {respawn_disabled};

       // "Disable" actual respawn
       setPlayerRespawnTime 9999;

       // Wait until respawn is enabled again or player died
       waitUntil {!(respawn_disabled) || !(alive player)};

       // if respawn disabled AND player dead
       if (respawn_disabled && !(alive player)) then 
	{
           // Maybe a little sleep so its not switching to spectator immediatly
           sleep 3;

           // Disable post processing effects for spectator (Fatigue blur and such)
           BIS_fnc_feedback_allowPP = false;

           // Start spectator
           _spectatorLayer cutRsc ["RscSpectator", "PLAIN"]; 

           // Wait until respawn is enabled again
           waitUntil {!(respawn_disabled)};

           // Re-enable post processing effects
           BIS_fnc_feedback_allowPP = true;

           // Set original respawn time
           setPlayerRespawnTime respawnTime;

           //Respawn the player
           forceRespawn player;

           // Stop spectator
    _spectatorLayer cutText ["", "PLAIN"];

       } else {
           // Set original respawn time
           setPlayerRespawnTime respawnTime;
       };
   };
};

Edit:

_spectatorLayer cutRsc ["", "PLAIN"]; - this did not worked for me so I am using _spectatorLayer cutText ["", "PLAIN"]; instead

Now I need to modify the script so it works on AI units too.

Thanks again!

Share this post


Link to post
Share on other sites

Oops, my bad... cutText is correct. :)

Glad it works.

With AI it should be easier, you could just teleport them away while respawn is disabled.

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  

×