Jump to content
Sign in to follow this  
UpperM

Switch player side when die

Recommended Posts

Hi !

I search how to switch a BLUEFOR player to OPFOR in MP when he killed like "If BLUEFOR die, create OPFOR slot, switch BLUEFOR to OPFOR and delete BLUEFOR slot".

Thank !

Edited by LeXpLoSiF

Share this post


Link to post
Share on other sites

May not be exactly what your looking for:

//onPlayerRespawn.sqf

if (side (_this select 1) isEqualTo WEST) then
{
_newGrp = createGroup EAST;
[(_this select 0)] joinSilent _newGrp;
}
else
{
if (side (_this select 1) isEqualTo EAST) then
{
	_newGrp = createGroup WEST;
	[(_this select 0)] joinSilent _newGrp;
};
};

Share this post


Link to post
Share on other sites

Easy fix with it all in an:

if !(isNull (_this select 1)) then {stuff};

Edited by JShock

Share this post


Link to post
Share on other sites

Ah, see I thought that at first (I actually added that to the event scripts page - should really remove it now), but it's unreliable. The most reliable way to do it is to have a global variable initialize the first spawn, then check if !isNil to run code on subsequent spawns.

Edit:

I should clarify, the isNull check on the oldUnit is unreliable because it doesn't always return false on future respawns (depending on server latency and some other things that can factor in). I learnt that the hard way during slightly larger scale testing (18 players or so) of a mission I'm working on.

So I suggest:

if (isNil "UniqueVariableForDetectingRespawnAtStart") then {
   UniqueVariableForDetectingRespawnAtStart = true;
   <Code that should run on mission start>
} else {
   <Code that shouldn't run on mission start>
};

Edited by SilentSpike

Share this post


Link to post
Share on other sites
Ah, see I thought that at first (I actually added that to the event scripts page - should really remove it now), but it's unreliable. The most reliable way to do it is to have a global variable initialize the first spawn, then check if !isNil to run code on subsequent spawns.

Or this too:

//in initPlayerLocal.sqf

player addEventHandler 
[
"Respawn",
{
	if (side (_this select 1) isEqualTo WEST) then
	{
		_newGrp = createGroup EAST;
		[(_this select 0)] joinSilent _newGrp;
	}
	else
	{
	    if (side (_this select 1) isEqualTo EAST) then
	    {
	    	_newGrp = createGroup WEST;
		    [(_this select 0)] joinSilent _newGrp;
	    };
	};  
}
];

Share this post


Link to post
Share on other sites

Thank for your help, but I have not managed to make it work ... I have try in OnplayerKilled and OnePlayerRespawn but every death the game ends and i'm not auto switch as OPFOR ...

Sorry i'm not very good in scripting :/ (and in english :D)

Share this post


Link to post
Share on other sites

Are you testing this via "preview" in the editor?

Share this post


Link to post
Share on other sites

You may not have your respawn setup all correctly (maybe send a zip of your mission folder), have you tried all the methods mentioned above as well?

Share this post


Link to post
Share on other sites

I have set the repawn to 'Group'. I send you my test mission in MP. Thank you.

Share this post


Link to post
Share on other sites

Based on that, the issue is that with the setup I've shown it needs to be "BASE" respawn, with "respawn_west" and "respawn_east" markers.

Share this post


Link to post
Share on other sites

It's Still doesn't work :confused: On my mission I have 1 unit in OPFOR and 1 unit in BLUEFOR. I have the 2 markers respawn_west and respawn_east and configured sur respawn as BASE.

//in initPlayerLocal.sqf

player addEventHandler 
[
   "Respawn",
   {
       if (side (_this select 1) isEqualTo WEST) then
       {
           _newGrp = createGroup EAST;
           [(_this select 0)] joinSilent _newGrp;
       }
       else
       {
           if (side (_this select 1) isEqualTo EAST) then
           {
               _newGrp = createGroup WEST;
               [(_this select 0)] joinSilent _newGrp;
           };
       };  
   }
];  

Share this post


Link to post
Share on other sites

It's probably because the corpse turns to side civilian on death. Here (_this select 1 should have been _this select 0):

player addEventHandler  
[ 
   "Respawn", 
   { 
       if (side (_this select 0) isEqualTo WEST) then 
       { 
           _newGrp = createGroup EAST; 
           [(_this select 0)] joinSilent _newGrp; 
       } 
       else 
       { 
           if (side (_this select 0) isEqualTo EAST) then 
           { 
               _newGrp = createGroup WEST; 
               [(_this select 0)] joinSilent _newGrp; 
           }; 
       };   
   } 
];  

Share this post


Link to post
Share on other sites

Just as a note, I believe you were going for a complete switch between a BLUFOR soldier and an OPFOR soldier, I don't belive it is possible (at least I don't know a way), so with what I have provided here you simply join the side opposite of the side that you respawned as, so technically speaking you have "switched" over.

Share this post


Link to post
Share on other sites

Oh, I see what you're saying. There's a command to switch to a different unit somewhere, but I don't remember which it is.

Share this post


Link to post
Share on other sites

I think we are confused ^^

The mission start with 1 Infected (OPFOR) and 15 survivor (BLUFOR).

If the infected die, the mission ending and Bluefor win the game. The infected must kill all BLUFOR players. When a BLUFOR player die, he joins the OPFOR team.

So the mission start with 1 slot OPFOR and 15 BLUFOR slots.

Exemple :

Player 1 start as BLUFOR

if Player 1 die, the script create a new OPFORslot.

Player 1 Respawn in the new OPFOR Slot

the Script delete the BLUFOR slot of player 1

Actually one my server I have 15 OPFOR slot and 15 BLUFOR slot. When a blufor die , he need to return to the lobby and switch on a opfor slot manually but I want that be automatic.

PS : Sorry for my English ..

Share this post


Link to post
Share on other sites

Ok makes a bit more sense, try the following, you still need BASE respawn type and "respawn_west" and "respawn_east" markers (where "respawn_east" is where you want the infected to spawn):

//in initPlayerLocal.sqf 

if (side player isEqualTo WEST) then 
{ 
   player setVariable ["hasBeenInfected",false,true]; 
} 
else 
{ 
   if (side player isEqualTo EAST) then 
   { 
       player setVariable ["hasBeenInfected",true,true]; 
   }; 
};  

player addEventHandler 
[
"Killed",
{
	if ((_this select 1) getVariable ["hasBeenInfected",false]) then
	{
		(_this select 0) setVariable ["hasBeenInfected",true,true];
	};
}
];

player addEventHandler  
[ 
   "Respawn", 
   { 
       if ((_this select 0) getVariable ["hasBeenInfected",false]) then 
       { 
           _newGrp = createGroup EAST; 
           [(_this select 0)] joinSilent _newGrp;
		(_this select 0) setPos (getMarkerPos "respawn_east");
       };
   } 
];  

Share this post


Link to post
Share on other sites

I have try rour script but when i'm killed (as BLUFOR) i spawn on the respawn_west as bluefor :/

Share this post


Link to post
Share on other sites

Ok for testing purposes, change the respawn EH to the following, and let me know what pops up:

player addEventHandler  
[ 
   "Respawn", 
   { 
       if ((_this select 0) getVariable ["hasBeenInfected",false]) then 
       { 
           _newGrp = createGroup EAST; 
           [(_this select 0)] joinSilent _newGrp;
           (_this select 0) setPos (getMarkerPos "respawn_east");
       };
	hintSilent format ["Are you infected?: ",(_this select 0) getVariable ["hasBeenInfected",false]];
   } 
]; 

Share this post


Link to post
Share on other sites

JShock: I think it's because you're setting the variable on the dead body, then trying to read it from the new body.

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  

×