ange1u5 11 Posted November 12, 2014 Hi there. I'm currently trying to have two different loadouts depending on which side you select (Blufor or Civ). I've created two seperate loadout scripts, both work fine, however I can't seem to get them to seperate based on which side you're playing. When I exec the two scripts, it seems to only execute the 2nd script for BOTH sides so for example: [] spawn { { if (isPlayer _x) then { null = [] execVM "player_markers.sqf"; //Executes player markers script so players can see their relative real time positions on the map null = [player] execVM "civLoadout.sqf"; //Executes Civilian Observser loadout script null = [player] execVM "respawnLoadout.sqf"; //Executes Competitor loadout script }; }forEach allUnits; }; So instead of the civilians having the civLoadout as they should, they instead end up with respawnLoadout. This is reversed if I change the order of execution. I have this code in the init fields of each playable unit. Blufor: BIS_fnc_initRespawn = {true}; 0 = [this] execVM 'respawnloadout.sqf'; this addeventhandler ["respawn","0 = _this execVM 'respawnloadout.sqf'"]; Civ: BIS_fnc_initRespawn = {true}; 0 = [this] execVM 'civLoadout.sqf'; this addeventhandler ["respawn","0 = _this execVM 'civLoadout.sqf'"]; So why is it ignoring one script and only choosing to execute one to all players? Any help appreciated :) Share this post Link to post Share on other sites
badluckburt 78 Posted November 12, 2014 If you run both scripts after each other (as you are atm), it's logical that only the last script is registered for BIS_fnc_initRespawn. You need to check which side (BIKI) the player is on and only run the corresponding script. Something like this should work: [] spawn { { if (isPlayer _x) then { null = [] execVM "player_markers.sqf"; //Executes player markers script so players can see their relative real time positions on the map if(side _x == 'CIV') then { null = [player] execVM "civLoadout.sqf"; //Executes Civilian Observser loadout script } else { null = [player] execVM "respawnLoadout.sqf"; //Executes Competitor loadout script } }; }forEach allUnits; }; Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted November 12, 2014 if(side _x isEqualTo blufor) exitWith { //init blufor loadout here }; if(side _x isEqualTo civilian) exitWith { //init civilian loadout here }; Be aware that using "exitWith" will prevent any further code from being executed after the code block following the "exitWith" which can speed up the script as in this example, but might be problematic if you have further needed code after the "exitWith" block. Share this post Link to post Share on other sites
ange1u5 11 Posted November 12, 2014 Thanks BadLuckBurt, thats done the trick! Share this post Link to post Share on other sites
badluckburt 78 Posted November 12, 2014 You're welcome. Heeeere's Johnny has a point though, once you've found the player when looping through all those units, you don't have to continue the loop so you may want to see about using the exitWith as he suggests. Share this post Link to post Share on other sites
ange1u5 11 Posted November 13, 2014 (edited) Well I did find a problem. When testing with 2 players, the loadout does not work correctly on a 2nd player. So I load in, my loadout is fine as is any additional context menu stuff running in my mission. However the 2nd player comes in with only the default loadout of the unit thats in the editor when placed and no extra options in his/her context menu. Respawning worked to reload it (but not on a dedicated I think), but then other code did not run correctly afterwards either. I suppose I should explain my mission has 3 init files (init.sqf, initplayer.sqf, initdedi.sqf) to ensure all features of the mission run properly on both local MP and dedicated server hosting. So the orignal code I use for both is the following (This is without the new civLoadout.sqf being called). Both bits of code are they very start of both files. initplayer.sqf waitUntil {!isNull player}; [] execVM "player_markers.sqf"; //Executes player markers script so players can see their relative real time positions on the map null = [player] execVM "RespawnLoadout.sqf"; //Executes player loadout script initdedi.sqf if (!isDedicated) exitWith {}; [] spawn { { if (isPlayer _x) then { null = [] execVM "player_markers.sqf"; //Executes player markers script so players can see their relative real time positions on the map null = [player] execVM "RespawnLoadout.sqf"; //Executes player loadout script }; }forEach allUnits; }; }; Hope I've explained the problem I'm having sufficiently anyway =P I need civLoadout to be called OR I need a single SQF which will set the different loadouts for both Blufor and Civ. I'm assuming something like a 'if (side player == west)' kind of statement? Edited November 13, 2014 by ange1u5 Share this post Link to post Share on other sites
ange1u5 11 Posted November 14, 2014 So would something like this work? if(side player == West) then { null = [] execVM "competitorLoadout.sqf"; }; if(side player == Civilian) then { null = [] execVM "civLoadout.sqf"; }; I have tried it but nothing happens so I assume I just got it wrong somewhere. The eventhandler is still respawnLoadout.sqf in the units INIT field. Share this post Link to post Share on other sites
MrPineapple 11 Posted November 14, 2014 if your trying to execute code depending on the side of the player, you can use a switch statement. switch (side player) do { case west: {}; case east: {}; case resistance: {}; default {}; }; Only the case block that is the same as the condition will process. Share this post Link to post Share on other sites
badluckburt 78 Posted November 15, 2014 I sadly have little to no experience with multiplayers scripting apart from butchering some missions to add some extra features but I plan to brush up those skills sometime next year. However, try reading Killzone Kid's blog: http://killzonekid.com/arma-scripting-tutorials-basic-multiplayer-coding/ You may be able to figure out what you need to do from there. Share this post Link to post Share on other sites