Jump to content
Sign in to follow this  
iceman77

Side Foreach

Recommended Posts

How come

{If (Side _x == West) Then {PlaySound "Captured";}} ForEach PlayableUnits; 
{If (Side _x == East) Then {PlaySound "LostZone";}} ForEach PlayableUnits;

Both sounds play. For example, if I'm a blufor playable unit, and there are other opfor playable units, then it plays both for me.

Edited by Iceman77

Share this post


Link to post
Share on other sites

See my comments within the code

{
         If (Side _x == West) Then {                     //you have specified that if _x == west
                           PlaySound "Captured";         //but here you have not alluded to _x at all so it will play the sound forEach PlayableUnits[sUB][/sUB]
                           }
} ForEach PlayableUnits; 

What you would need is something like _x playSound "Captured"; (this is not a correct syntax but hopefully you get the idea of what I'm getting at)

Perhaps this might work better (not tested) or something along those lines.

{
         If (Side _x == West) Then { 
                           _soundSource = createSoundSource ["Captured", position _x, [], 0]; 
                           }
} ForEach PlayableUnits; 

Share this post


Link to post
Share on other sites

Okay so I ended up just using PVEH, broadcasted the variable from the server. I use a simple If (Side Player == .... in the PVEH.

Share this post


Link to post
Share on other sites

Another possible explanation could be that PlayableUnits takes into account all playable units, regardless of which side the player's on.

if (side player == WEST) then {
playSound "Captured";
};

would also be a possible solution, although I'm not entirely sure if player is also accounting for other players in an MP environment (which is what you're aiming for I suppose).

Share this post


Link to post
Share on other sites

Yeah that's exactly what i did. Though I used PVEH since everything I'm doing is on the server, so good old "player" wont work. But it does work inside the pveh :)

Share this post


Link to post
Share on other sites

Don't count on side player though. It can change if you TK as well as by some other things. You can try to compensate for those (in fact, you probably want to add a little script that cancels the "side enemy" thing on TKs), but generally you just want to just have waitUntil {!isNull player}; sidePlayer = side player; in init.sqf or something that runs right as the mission loads, then you can use your sidePlayer variable instead. The playerSide command might work too, but I never investigated it too much to make sure it does what we might expect.

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  

×