Jump to content
Sign in to follow this  
Alpine_gremlin

Force Players to Spectate After 2 Lives

Recommended Posts

Hey guys its been a while since I`ve written any code for ArmA so I`m super rusty. Using the ACE mod, I`m trying to make it so that after an individual player dies twice, they are transferred to the spectator screen. The code seems really simple, so I`m not sure why it isn`t working. I`m not getting any script errors so is it just bad syntax?

 

"handleSpectator.sqf" is called via initPlayerLocal.sqf:

 

[[west], [east,civilian]] call ace_spectator_fnc_updateSides;
[[0,1,2], []] call ace_spectator_fnc_updateCameraModes;
[[], [allPlayers]] call ace_spectator_fnc_updateUnits;


hint "First Life...";

waitUntil {!alive player};
sleep 5;

hint "Second Life...";

waitUntil {!alive player};

[true] call ace_spectator_fnc_setSpectator;

 

Share this post


Link to post
Share on other sites

I'd use something along the lines of

private _lifeNumber = profileNameSpace getVarible ["SomeUniqueVariableName", 0];
_lifeNumber = _lifeNumber + 1;

if ( _lifeNumber > 2) then {
	[true] call ace_spectator_fnc_setSpectator;
} else {
	profileNameSpace setVariable ["SomeUniqueVariableName", _lifeNumber ];
  	hint format ["Life number %1", _lifeNumber];
};

in OnPlayerRespawn.  (Untested)

 

An alternative to a var in profilenamespace could be a global variable. 

  • Like 1

Share this post


Link to post
Share on other sites

That piece of code does the following:

It goes to a players profilenamespace and fetches the variable with a given name.  If this variable does not exist it uses 0 as a default value.  It puts that value into _lifenumber.  Once that's done it adds 1 to this value.  Then it checks whether or not that value is greater than 2.  If it is that ace function is called.  If not the new value is stored in the profilenamespace so next time a player respawns when we fetch that variable again it'll be 1 higher than this time. 

Hope that helps. 

  • Thanks 1

Share this post


Link to post
Share on other sites

Oh I forgot to mention this: put <profileNameSpace setVariable ["SomeUniqueVariableName", nil];> into initplayerlocal.  Otherwise that number will be persistent over several game sessions. 

Share this post


Link to post
Share on other sites
7 hours ago, stanhope said:

Oh I forgot to mention this: put <profileNameSpace setVariable ["SomeUniqueVariableName", nil];> into initplayerlocal.  Otherwise that number will be persistent over several game sessions. 

Understood. Thank you!

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  

×