Jump to content
Darce

switch (player) do?

Recommended Posts

I am attempting a custom loadout for a MP mission where each playable unit has a defined name (infcom, aircom, mechcom etc) in the mission.sqm.
 

What I have so far works fine in the editor, but fails on the server;

_load = player;
//remove everything routine snipped
switch (player) do {
case infcom;
case aircom;
case mechcom:{
        _load addHeadgear "rhsusf_opscore_03_ocp";
        _load forceAddUniform "rhs_uniform_cu_ocp";
        _load addVest "rhsusf_iotv_ocp_Squadleader";
        _load addBackpack "tf_rt1523g_big_rhs";
        clearallcargo;
        // add weapons etc etc etc

In the snippet above, I want the same loadout for all three (infcom, aircom and mechcom) so, as i understand it, case infcom true would drop through to execute the code block at mechcom.  But, in MP environment, as soon as it hits 'case infcom;' it errors out for an undefined variable if I load in in another position.  I've tried using an if statement as well, but it also errors out on undefined variable.

 

The only way I have succeeded is to use a masking 'if (!isNil "infcom") then' prior to an 'if (player == infcom) exitwith' statement, but then I have to repeat the loadout routine for each position.  As we have several squads with the same loadout this results in a lot of repeats. (sad face)

 

Anyone solve this problem and willing to help me out?

Share this post


Link to post
Share on other sites

if I load in as infcom it works fine, but if I load in as any other position it fails for infcom being undefined

Share this post


Link to post
Share on other sites

Could use vehicleVarName instead. Then you can switch all the case statements to strings and it will not error out on undefined if there is no player in that slot.

switch (vehicleVarName player) do {
    case "infcom";
    case "aircom";
    case "mechcom":{
        _load addHeadgear "rhsusf_opscore_03_ocp";
        _load forceAddUniform "rhs_uniform_cu_ocp";
        _load addVest "rhsusf_iotv_ocp_Squadleader";
        _load addBackpack "tf_rt1523g_big_rhs";
        clearallcargo;
    }
  • Like 1

Share this post


Link to post
Share on other sites

 

Could use vehicleVarName instead. Then you can switch all the case statements to strings and it will not error out on undefined if there is no player in that slot.

switch (vehicleVarName player) do {
    case "infcom";
    case "aircom";
    case "mechcom":{
        _load addHeadgear "rhsusf_opscore_03_ocp";
        _load forceAddUniform "rhs_uniform_cu_ocp";
        _load addVest "rhsusf_iotv_ocp_Squadleader";
        _load addBackpack "tf_rt1523g_big_rhs";
        clearallcargo;
    }

Thank you, that did the trick :)

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

×