UpperM 14 Posted January 27, 2015 (edited) 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 January 27, 2015 by LeXpLoSiF Share this post Link to post Share on other sites
jshock 512 Posted January 27, 2015 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
SilentSpike 84 Posted January 27, 2015 Be careful with onPlayerRespawn as it actually fires at mission start too. Share this post Link to post Share on other sites
jshock 512 Posted January 27, 2015 (edited) Easy fix with it all in an: if !(isNull (_this select 1)) then {stuff}; Edited January 27, 2015 by JShock Share this post Link to post Share on other sites
SilentSpike 84 Posted January 27, 2015 (edited) 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 January 27, 2015 by SilentSpike Share this post Link to post Share on other sites
jshock 512 Posted January 27, 2015 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
SilentSpike 84 Posted January 27, 2015 That works too :) Share this post Link to post Share on other sites
UpperM 14 Posted January 27, 2015 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
jshock 512 Posted January 27, 2015 Are you testing this via "preview" in the editor? Share this post Link to post Share on other sites
UpperM 14 Posted January 27, 2015 Nop on my dedicated server Share this post Link to post Share on other sites
jshock 512 Posted January 28, 2015 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
UpperM 14 Posted January 28, 2015 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
jshock 512 Posted January 28, 2015 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
UpperM 14 Posted January 28, 2015 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
SilentSpike 84 Posted January 28, 2015 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
UpperM 14 Posted January 28, 2015 Still doesn't work :/ Share this post Link to post Share on other sites
jshock 512 Posted January 28, 2015 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
SilentSpike 84 Posted January 28, 2015 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
UpperM 14 Posted January 28, 2015 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
jshock 512 Posted January 28, 2015 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
UpperM 14 Posted January 28, 2015 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
jshock 512 Posted January 28, 2015 Were you killed by blufor or opfor? Share this post Link to post Share on other sites
jshock 512 Posted January 28, 2015 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
SilentSpike 84 Posted January 28, 2015 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