• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[JASS] Newbie to JASS, any help?

Status
Not open for further replies.

UltimaaDragoon

U

UltimaaDragoon

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
 
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!
 
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.
 
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.
Back
Top