Jump to content
Jaden Vance

Local playmusic from a trigger.

Recommended Posts

Hello. I am creating a 2 player scenario and I wanted to include a certain feature.

I have created and attatched two triggers with 60m range, one for P1 and one for P2, and when either player is near an enemy (east), an ambient music is playing, and when either moves away, the music fades out.
 Problem is, when either of them is near an enemy, the music starts for both players, and ends when one moves away, even if the other is near the enemy.

I have them setup like this:


-Trigger for P1 (The same as P2, only the variable name changes):

  Activation: OPFOR (Present)

  Condition:

    this
  On activation:

    [] execVM "Scripts\P1_DangerON.sqf"

  On deactivation:

    [] execVM "Scripts\P1_DangerOFF.sqf"

 

-In the dangerOn.sqf:

  3 fadeMusic 0.3;
  playMusic "AmbientTrack01_F_Tank";

 

-In the dangerOff.sqf:
4 FadeMusic 0;

 

But I guess since the scripts are activated from the trigger, this is made global. Can I somehow limit them to each player only? Thanks in advance. 🙂

 

EDIT: Forgot to mention, the mission will be run in dedicated server enviroment.

Share this post


Link to post
Share on other sites
1 hour ago, Jaden Vance said:

Can I somehow limit them to each player only?

Yes, Just create a local trigger for each player in initPlayerLocal.sqf.

Something like...

Spoiler

//initPlayerLocal.sqf

params[ "_player" ];

waitUntil{ getClientStateNumber >= 10 /*"BRIEFING READ"*/  };

_trg = createTrigger[ "EmptyDetector", getPosATL player, false ]; //<< false,  create local trigger for this client
_trg setTriggerArea[ 60, 60, getDir _player, false ];
_trg attachTo[ _player, [0,0,0] ];
_trg setTriggerActivation[ "EAST", "PRESENT", true ];
_trg setTriggerStatements[
	"this",
	"[] execVM 'Scripts\P1_DangerON.sqf'",
	"[] execVM 'Scripts\P1_DangerOFF.sqf'"
];
player setVariable[ "battleAmbienceTrigger", _trg ];

 

 

 

  • Thanks 1

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

×