Jump to content
Sign in to follow this  
RonnieJ

Problem with switch and multiplayer

Recommended Posts

Hey guys im trying this:

if (playerSide == west) then {

execVM "scripts\stand_weap_all.sqf";

switch (player) do {

case s1: { execVM "scripts\stand_weap_gf.sqf"; };

case s2: { execVM "scripts\stand_weap_at.sqf"; };

case s3: { execVM "scripts\stand_weap_san.sqf"; };

case s4: { execVM "scripts\stand_weap_lmg.sqf"; };

case s5: { execVM "scripts\stand_weap_rifle.sqf"; };

case s6: { execVM "scripts\stand_weap_smaw.sqf"; };

case s7: { execVM "scripts\stand_weap_gf.sqf"; };

case s8: { execVM "scripts\stand_weap_at.sqf"; };

case s9: { execVM "scripts\stand_weap_san.sqf"; };

case s10: { execVM "scripts\stand_weap_lmg.sqf"; };

case s11: { execVM "scripts\stand_weap_rifle.sqf"; };

case s12: { execVM "scripts\stand_weap_smaw.sqf"; };

};

};

But not all players are there so the switch crashed cause its trying to ask on an object that dosent exist... any ideas? :confused:

Share this post


Link to post
Share on other sites

Could just use command typeof to check player units class and make it give weapons based on classes instead of nonflexible unit names.

Share this post


Link to post
Share on other sites

But if im not interestet in using typeof since I allready know which players is what... then what would you surgest shk... the script fails because the players dosent exist... if im trying s11 it tries s1 first and fails... I think its because s1 isent an object

Share this post


Link to post
Share on other sites

Then you will need to sort out which units exist prior to processing them. Use a loop using isNull as I showed before to weed out the non-objects, placing the remaining objects into an array or something. Then process everything in the array.

Edited by DMarkwick

Share this post


Link to post
Share on other sites

Change it to a string?

_str = str player;

switch _str do {

case "s1" :{};

case "s2" :{};

Share this post


Link to post
Share on other sites

strange im still having some issues... it looks like it helped:

if (playerSide == west) then {

_str = str player;

execVM "scripts\stand_weap_all.sqf";

switch (_str) do {

case "s1": { hint "1"; execVM "scripts\stand_weap_gf.sqf"; };

case "s2": { hint "2"; execVM "scripts\stand_weap_at.sqf"; };

case "s3": { hint "3"; execVM "scripts\stand_weap_san.sqf"; };

case "s4": { hint "4"; execVM "scripts\stand_weap_lmg.sqf"; };

case "s5": { hint "5"; execVM "scripts\stand_weap_rifle.sqf"; };

case "s6": { hint "6"; execVM "scripts\stand_weap_smaw.sqf"; };

case "s7": { hint "7"; execVM "scripts\stand_weap_gf.sqf"; };

case "s8": { hint "8"; execVM "scripts\stand_weap_at.sqf"; };

case "s9": { hint "9"; execVM "scripts\stand_weap_san.sqf"; };

case "s10": { hint "10"; execVM "scripts\stand_weap_lmg.sqf"; };

case "s11": { hint "11"; execVM "scripts\stand_weap_rifle.sqf"; };

case "s12": { hint "12"; execVM "scripts\stand_weap_smaw.sqf"; };

};

};

now I get the "10" hint and the player name is "s10"... running the mission in editor mode gives me all the weapons and items that the script should... but as hosted server I dont...

the script is:

hint "running";

player addWeapon "DDAM_MG62_optic";

player addMagazine "100Rnd_762x51_M240";

player addMagazine "100Rnd_762x51_M240";

player addMagazine "100Rnd_762x51_M240";

player addMagazine "100Rnd_762x51_M240";

player addWeapon "ACE_GLOCK18";

player addMagazine "ACE_33RND_9X19_G18";

player addMagazine "ACE_33RND_9X19_G18";

player addMagazine "ACE_33RND_9X19_G18";

player addMagazine "ACE_33RND_9X19_G18";

player addMagazine "ACE_BANDAGE";

player addMagazine "ACE_MORPHINE";

hint "done";

now I get the hint "done" så the file is run but the items dosent get added... does it need a sleep or something?

---------- Post added at 10:36 PM ---------- Previous post was at 10:16 PM ----------

Hmm tried with

waitUntil { alive player };

but that still didnt work but the sleep 1; did :S

Share this post


Link to post
Share on other sites

When switching weapons, it always needs to be done "in the game", not in briefing. Thus sleep 1 or waituntil {time>0} is needed.

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  

×