Forum Jump :

Author Message

Posts: 1589

Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 60
In-game name: Kobayashi Maru

#1 Posted at 2015-04-14 07:06        
Hi everyone!
This time, I need your experience to manage the team switch. I didn't pay attention for that before.
I usually script for SP. So, in a addon, my player have a addaction toggling menu which works without problem.
In in MP, I can use this custom menu and respawn with it. All good so far!

Problem is, I would like keeping addaction (menu) effect in team switch context.
I tried the onTeamSwitch {} function but it seems it's firing one shot. On a second switch, there is no more menu.
I tried also a EH "killed". I can obtain the same thing the first time my player dies. Then, no more addAction menu.

I guess, the problem is a "player" data transfer. At start, player is defined. When dying, you can waituntil {alive player} in an EH "killed" it works but what becomes "player" ? On a second time the player addEventHandler "killed" is not fired because the player remains the first dead entity. grrrrr!

Unfortunately, selectedPlayer function doesn't exist. This could be great!
Any idea to switch team , wanted dead or alive!, player with his pack of addAction menu?

Added 20 hours 16 minutes later:

So, I found a solution. Probably not the smartest, but it works!

For those who would like to transfer "addAction" menu while switching units in team, and by the way, keep the lead, here is an alternate solution for poor "onTeamSwitch" command (just one instance per mission).

0= [] spawn {while {true} do {
   private "_unit_sel";
   if (count switchableUnits == 0) exitWith {
    // place your code in case of player's death & no more switchable units

   for "_i" from 0 to (count switchableUnits -1) do {
      if (isplayer (switchableUnits select _i) && alive (switchableUnits select _i)) exitWith {
        _unit_sel = (switchableUnits select _i);
	if (_unit_sel getVariable ["switched",false]) exitWith {};
	if (_unit_sel != leader (group _unit_sel)) then {(group _unit_sel) selectLeader _unit_sel};

	action_on =  _unit_sel addAction ["<t color='#11ff11'>Start On</t>", {
        // your code here
	},nil,_nbr_in_menu,false,true,"", "_cond"];

	action_off = _unit_sel addAction ["<t color='#ff1111'>Start Off</t>",{
        // your code here
	},nil,_nbr_in_menu,false,true,"", "_other_cond"];
	_num = _unit_sel addEventHandler ["Killed", {
	// your code for EH killed
	_unit_sel setVariable ["switched", true];
   sleep 2}};

This post was edited by Pierre MGI (2015-04-15 03:25, ago)