• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] How do I set PERSONAL music with JASS?

Status
Not open for further replies.
Level 2
Joined
Jun 17, 2004
Messages
10
All I want is for players to be able to choose their own music, regardless of race. So an Orc player could listen to Human, NE, or
Undead music (or maybe some campaign music).

Now, I set up a LocalPlayer variable at initialization with this line of code:

set udg_LocalPlayer = GetLocalPlayer()

With an if-then-else function, LocalPlayer works perfectly. My friend and I tested this online, and I couldn't hear his "personal"
sound effects, and he couldn't hear mine. So it definitely works.

But...as soon as he tried to set his music to something else, he was disconnected. He tried again twice, and the same thing
happened twice. Here's the trigger involved:

EVENTS:
+ A button is clicked for Music

CONDITIONS:
+ (Clicked dialog button) Equal to HumanButton

ACTIONS:
+ If/Then/Else, Multiple Functions
[IF:]
+ (Triggering player) Equal to LocalPlayer
[THEN:]
+ Sound - Clear the music list
+ Set DICE = (Random integer number between 1 and 4)
+ If (DICE Equal to 1) then do (Sound - Play Human1) else do (Do nothing)
+ If (DICE Equal to 2) then do (Sound - Play Human2) else do (Do nothing)
+ If (DICE Equal to 3) then do (Sound - Play Human3) else do (Do nothing)
+ If (DICE Equal to 4) then do (Sound - Play HumanX1) else do (Do nothing)
+ Custom script: call SetMapMusicRandomBJ( "Sound\\Music\\mp3Music\\Human1.mp3;Sound\\Music\\mp3Music\\Human2.mp3;Sound\\Music\\mp3Music\\Human3.mp3;Sound\\Music\\mp3Music\\HumanX1.mp3" )
(This is a Sound - Set Music List action, but I replaced "music" with that big mess of filenames.)

As you can imagine, there are similar triggers for Orc, NE, Undead, and some other music. When we tested it, my friend tried
different ones, and they all disconnected him. BUT--it never disconnected me.

In fact, it worked perfectly for me; the music changed to whatever, and from then on it played a random song from the list.
So why on earth does this trigger disconnect other people when LocalPlayer works just fine for sound effects?
 
Level 6
Joined
Jun 16, 2004
Messages
237
It may have something to do with the global variables you are using. Try to get rid of DICE by custom scripting the whole function. May be use a local variable, or use a function to return the right music piece.

In my experience, setting global variables in a local player block may disconnect players.
 
Level 1
Joined
Dec 24, 2003
Messages
7
I'm not sure which idiot suggested this but whoever he is,(elil cough) should probably be shot through a cannon.

DO NOT EVER DO THIS:
custom script:set udg_GlobalPlayerVar=GetLocalPlayer()

This is just asking for a desync.

However its very fixable, at the start of the map define it as such:

custom script: local udg_GlobalPlayerVar=GetLocalPlayer()

Now you can use it without fear as it is only local to that instance (if you use it right ofcourse).

The next problem is you are destroying a handle for one player. This is a very very bad practice. Get rid of the clear music list and it should be okay. Also set a local string var to "". (LocalString) Then inside the localplayer block set LocalString to "Sound\\Music\\mp3Music\\Human1.mp3;Sound\\Music\\mp3Music\\Human2.mp3;Sound\\Music\\mp3Music\\Human3.mp3;Sound\\Music\\mp3Music\\HumanX1.mp3"
Now, outside the block set it to play LocalString.
 
Level 6
Joined
Jun 16, 2004
Messages
237
I have used

Code:
custom script:set udg_GlobalPlayerVar=GetLocalPlayer()
in the Map Initialization event without any problems later on, and thus it definitely works. However, setting global variables to local values in other triggers have caused instantaneous desyncs.

Well, following your advice, you define the "global" variables as local. A few questons:

Q1) Can you use them like global variables now? Or did you mean to put the custom script at the start of every trigger where you need it?

Q2) If you meant to "the start of the map," where do you put these declarations? I would guess to the start of the custom script area, but why then "custom script:" in your example?

Cheers!
 
Status
Not open for further replies.
Top