Jump to content
Sign in to follow this  
Crymeisbad

Switch-case is causing an error on respawn.

Recommended Posts

So I'm making a simple loadout script that automatically gives units the selected loadout, eitheir based on their variable name, or based on the kind of unit.

Spawnloadout.sqf

private ["_loadout","_man"];

_man = _this select 0;

removeAllAssignedItems _man;
removeallweapons _man;
removeallitems _man;
removeBackpack _man;
removeGoggles _man;
removeUniform _man;
removeHeadgear _man;
removeVest _man;
_man addweapon "ItemMap";

sleep .1;
waitUntil {player == player};
removeallitems _man;

_loadout = switch (true) do {
case (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8, MP9, MP10]) : {"Military Police"};
default {typeof _man};
};

#include "customloadouts.hpp"

customloadouts.hpp is nothing but a long case, saying if unit is Military Police, add such and such gear, no need to post it here.

Init line of units:

loadout = [this] execVM "ammobox\spawnloadout.sqf";this addEventHandler ["Respawn", {_this exec "ammobox\spawnloadout.sqf";}];

With the init line, it just activates the script, and activates it again when I respawn. When a unit respawns, they spawn with no gear at all, and a script error simply saying:

case (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8 ERROR

Any ideas what I'm doing wrong? Please help.

Share this post


Link to post
Share on other sites
So I'm making a simple loadout script that automatically gives units the selected loadout, eitheir based on their variable name, or based on the kind of unit.

Spawnloadout.sqf

private ["_loadout","_man"];

_man = _this select 0;

removeAllAssignedItems _man;
removeallweapons _man;
removeallitems _man;
removeBackpack _man;
removeGoggles _man;
removeUniform _man;
removeHeadgear _man;
removeVest _man;
_man addweapon "ItemMap";

sleep .1;
waitUntil {player == player};
removeallitems _man;

_loadout = switch (true) do {
   case (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8, MP9, MP10]) : {"Military Police"};
   default {typeof _man};
   };

#include "customloadouts.hpp"

customloadouts.hpp is nothing but a long case, saying if unit is Military Police, add such and such gear, no need to post it here.

Init line of units:

loadout = [this] execVM "ammobox\spawnloadout.sqf";this addEventHandler ["Respawn", {_this exec "ammobox\spawnloadout.sqf";}];

With the init line, it just activates the script, and activates it again when I respawn. When a unit respawns, they spawn with no gear at all, and a script error simply saying:

case (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8 ERROR

Any ideas what I'm doing wrong? Please help.

Just a guess but you probably can't assign the _loadout variable to the switch statement. Just assign it in each case statement.

Share this post


Link to post
Share on other sites

Can you please explain further? Also, the _loadout is what's passed to the other switch statement in the .hpp. Its like switch (_loadout) then case "B_Rifleman_F" _man addItem "ItemRadio"; and so on. Im just going just off it by memory

Share this post


Link to post
Share on other sites

_loadout = switch (true) do {
   case (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8, MP9, MP10]) : {"Military Police"};
   default {typeof _man};
   };

I think what you are trying to do is something like

switch (group _man) do 
{
   case "MP1" : {_loadout = "Military Police"};
   case "MP2" : {_loadout = "Military Police"};
   ...etc

but why not just (ugly due to lack of string handling):

_g = group _man;
if (_g=="MP1" or _g=="MP2" or _g=="MP3" or _g=="MP4" or _g=="MP5" or _g=="MP6" or _g=="MP7" or _g=="MP8" or _g=="MP9" or _g=="MP10") then {_loadout = "Military Police"};

Share this post


Link to post
Share on other sites

I think what you are trying to do is something like

switch (group _man) do 
{
   case "MP1" : {_loadout = "Military Police"};
   case "MP2" : {_loadout = "Military Police"};
   ...etc

This is what he wants but not "group _man" in the switch statement, just "_man".

but why not just (ugly due to lack of string handling):

_g = group _man;
if (_g=="MP1" or _g=="MP2" or _g=="MP3" or _g=="MP4" or _g=="MP5" or _g=="MP6" or _g=="MP7" or _g=="MP8" or _g=="MP9" or _g=="MP10") then {_loadout = "Military Police"};

Because as you state this is very ugly and the above is much cleaner and clear.

Or he can just do what I suggested since his switch statement is correct and change where he has "{"Military Police"}" to {_loadout = "Military Police"}.

And just not return anything from the switch statement which probably isn't correct.

Share this post


Link to post
Share on other sites

I don't understand why you would try to evaluate in a case statement instead of switch, this is where I'm lost. :confused:

_loadout = switch (true) do { // <-------- This doesn't make sense
   case (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8, MP9, MP10]) : {"Military Police"};
   default {typeof _man};
   };

I don't know if this would work, but it looks more realistic (this assumes _man can return MPx by itself):

_loadout = switch (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8, MP9, MP10]) do {
   case true : {_loadout = "Military Police"}; 
   default {typeof _man};

But if that would work, then I guess this is probably the simplest way to do it:

if (_man in [MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8, MP9, MP10]) then {_loadout = "Military Police"} else {typeof _man}; 

I thought he was trying to get the group name of _man and compare it against MPx.

Share this post


Link to post
Share on other sites

#include "customloadouts.hpp"


_man addEventHandler ["Respawn", {_man execVM "ammobox\spawnloadout.sqf";}];

So I removed that line basically from the init line of each unit, and added the VM, still nothing, but atleast now I'm not getting an error code I guess.

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  

×