• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Newbie to JASS, any help?

Status
Not open for further replies.
Level 2
Joined
Aug 16, 2004
Messages
6
I am new not only to this forum but also to JASS, so I wills tart off by saying howdy to you all. What I am trying to accomplish is setting msuic upon rentering a new region for specific players. For example, Say Player 2 enters Stone Hills, but Player 3 is in Marsh Pits, I would want Player 2 to hear Stone Hills music, and Player 3 to hear Marsh Pits music. I found a JASS script thing for this but I don't quite understand it.

function PlaySoundForPlayer takes player whichPlayer, sound whichSound returns nothing
if ( whichPlayer == GetLocalPlayer() ) then
call PlaySoundBJ( whichSound )
endif
endfunction
 
Level 6
Joined
Jun 16, 2004
Messages
237
The trick is that GetLocalPlayer() returns a different player for each client (player). Now if you want to play a sound to player 1 (Player(0) in JASS) you can check if GetLocalPlayer() == Player(0) equals to true. This statement will be true only for player 1, whose GetLocalPlayer() function will return Player(0). For other players, GetLocalPlayer() will return Player(1), Player(2), etc.

However, you must be very careful when using GetLocalPlayer(). If you do anything that will set the common world of the players to different states, the game will immediately disconnect the players. Note that sounds and texts on the screen are not part of the common world, but, for example, global variables typically are.

A good trick with GetLocalPlayer() is to make a variable in the variable editor (called "LocalPlayer") and put the following custom script line to the map initialization:

Code:
custom script: set udg_LocalPlayer = GetLocalPlayer()
Now each player has his or her player handle stored in LocalPlayer variable. If you do this in the map initialization, the game will not disconnect players, although there is a global variable that has a different value in each client.

Hope it helped!
 
Level 2
Joined
Aug 16, 2004
Messages
6
Ok, So could you give me an example please, of a trigger thats done? I will give you the correct names.

Music: Qeynos
Player 1-10

If you could setup a trigger maybe it would help me alot, I can't even get mine to fire off let alone test it lol.
 
Level 6
Joined
Jun 16, 2004
Messages
237
You call the function as follows, for example:

Code:
call PlaySoundForPlayer( Player(0), udg_Sound )
This plays the global variable Sound for Player 1 (Red). The code is placed in a custom script action. The function itself needs to be copied to the custom script area in the root node of the trigger tree.

If you want to play a sound for players 1-10, I'd suggest that you code the whole block into the trigger as follows:
Code:
if GetPlayerId( GetLocalPlayer() ) < 10 then
  call PlaySoundBJ( udg_Sound )
endif
Here change udg_Sound to whatever sound you want to play (or you may use the Sound variable, which is a bit clumsy).
 
Status
Not open for further replies.
Top