[Solved]Local Player

This is a forum where you can ask our code monkeys for assistance. Questions on technical help belong here.
User avatar
Posts: 436
Joined: Mon Oct 12, 2009 12:00 am
Location: Dominion of Canada

[Solved]Local Player

Postby Slayer4000X2008 » Sun Feb 07, 2010 6:36 pm

First poster on this board :P

<hr />
Now to the point, I need to use local player for a few things but have so far not been able to figure it out. I need local player to: 1. Show this message "You have choosen the mighty Hardel, good for melee combat and magic use." and similar message's when a hero is chosen, 2. I want to give the option to play some music other then WC3 music that I personally think would be rather cool, I.E. Eye of the Tiger :D The music one will be activated by a chat message and will play once before returning to default unless they put in the loop command kind of like (not official) -[command]loop (the [command] is the command used for playing it once).
Posts: 25
Joined: Tue Nov 10, 2009 12:00 am
Location: GMT

[Solved]Local Player

Postby Romek » Sun Feb 07, 2010 7:04 pm

Since you're talking about Local Player, which isn't available in GUI, I'll assume you're coding in JASS.

There is a native which shows a message for a single player already, so GetLocalPlayer isn't needed for that.

Code: Select all

call DisplayTimedTextToPlayer(<player>, 0., 0., <duration>, "You have choosen the mighty Hardel, good for melee combat and magic use.")

In case you're using GUI, there's a simple action which does the same thing, I believe.

Local Player returns the player the 'actions' are currently running for. Using a simple player comparison, it can be used to execute code for only one player:

Code: Select all

if GetLocalPlayer() == <player> then
    < Actions to execute >

This can be used to play music for a player.

Code: Select all

if GetLocalPlayer() == <player> then
    call PlayMusic(<Music Path>)

The music path is simply "gg_snd_" + the name of the music variable in the Sound Editor; for example: gg_snd_PersuitTheme.
If you're using GUI, you'll need to use a Custom Script action to do the 'if' block.

Code: Select all

    Set Player = <the player the music should be played for>
    Custom script:   if GetLocalPlayer() == udg_Player then
    Sound - Play PursuitTheme <gen>
    Custom script:   endif

Note that GetLocalPlayer blocks often result in desyncs if incorrectly used (doing things such as killing units, creating units, or even creating timers).

There is an event for players typing messages which you can use to activate the music. In JASS, GetTriggerPlayer() is used to get the player which typed the message (you'll want to use this to ensure the music is only played for the player which typed the message).

As for looping the music, (assuming it doesn't do so automagically), you'll simply need to replay it once it finishes (use a timer which expires when the music ends).
Last edited by Romek on Sun Feb 07, 2010 7:26 pm, edited 1 time in total.