HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

GetLocalPlayer()

12-30-2006, 11:21 PM#1
Joker
What is this? I see it a lot under the BJ triggers in jasscraft
12-30-2006, 11:31 PM#2
Vexorian
There are no BJ triggers

It returns the local player it is kind of hard to explain.

The code you make is run simultaneously by every player in the game.

So if you do this
Collapse JASS:
if (GetLocalPlayer()==Player(0)) then
    //...
endif

The stuff inside that block is going to run only for Player(0) and not for the rest.

This is an easy way to cause desyncs, but if used correctly (most likelly on things that don't effect memory management or gameplay in any way) You can use it to do things for the local player...

If you check it it is almost always used for Selection and camera, you can use it to change a vertex color for only a player or even to play a sound for that one player.
12-30-2006, 11:34 PM#3
Anitarf
The function returns the local player. During a multiplayer game, triggers get executed on all player's machines simultaneously - GetLocalPlayer() will return the player on who's machine the trigger is running. So, once a trigger runs, when it gets to a GetLocalPlayer() call, it will get a different value on different computers, allowing you to do things for one player and not another. Note that there are only a few things you can do this way that won't cause a game desync and therefore a server split.
12-30-2006, 11:49 PM#4
illidan92
It's a great way to do something only to 1 player when otherwise is impossible, like playing sounds, fade filters etc..
12-31-2006, 01:57 AM#5
Chuckle_Brother
Yeah, stuff that is definately safe with this:

-Vertex Shading
-Animations
-Special Effect Creation
-Sounds
-Fade Filters
-Text Displays
-Text Tag Creation
-Text Tag Visibility/Text Display
-Multiboard Display/Values

There are more, no doubt, but thats what comes to mind.
12-31-2006, 02:20 AM#6
Joker
so would it be alright if i used it with EnumPlayers?

also what are desyncs?
12-31-2006, 02:57 AM#7
darkwulfv
a desync is when a player is ripped from the game on Bnet, can also cause everyone else to drop (server split)
12-31-2006, 04:47 AM#8
Chuckle_Brother
Well if you want to be technical, it is when a player fails to match to the host(they desync, so the game isn't synched). This can happen if you use do something like:
Collapse JASS:
udg_MyVar = GetPlayerId(GetLocalPlayer())
or if you create a unit for a single player.

Anything not on that list or that others mention is likely to desync the game.
12-31-2006, 10:41 AM#9
Anitarf
Quote:
Originally Posted by Chuckle_Brother
Yeah, stuff that is definately safe with this:
...
-Special Effect Creation
...
-Text Tag Creation
...
Yes, good luck doing that and not desyncing. Text tags and special effects are handles, creating them for a single player will split the game faster than you can say "omg I sux".
12-31-2006, 10:50 AM#10
Captain Griffen
With handles, you cannot create the handle for only one player. You can, however, make some settings different - for example for special effects you can have one player have a model's string, and the other players have "". Make sure you don't create new strings locally, though, or that can cause a desync.
12-31-2006, 11:05 AM#11
BlinkBoy
Even though you can store player only values using a global multibourd. This won't happen to cause desyncs, unless you alter the number of colums or rows for a single player.

Collapse JASS:

local integer i
    call CreateMultiboardBJ( 1, 3, "Player Values" )
    loop
        exitwhen i > 11
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER ) then
            if GetLocalPlayer() == Player(i) then
               call MultiboardSetItemValueBJ( GetLastCreatedMultiboard(), 1, 1, I2S(GetPlayerID(Player(i)) )
               call MultiboardSetItemValueBJ( GetLastCreatedMultiboard(), 1, 2, R2S(GetCameraTargetPositionX()) )
               call MultiboardSetItemValueBJ( GetLastCreatedMultiboard(), 1, 3, R2S(GetCameraTargetPositionY()) )
            endif
        else
        endif
        set i = i + 1
    endloop
12-31-2006, 03:37 PM#12
Jacek
Quote:
Originally Posted by Anitarf
Yes, good luck doing that and not desyncing. Text tags and special effects are handles, creating them for a single player will split the game faster than you can say "omg I sux".
Isn't it something like you create invisible text tag for ALL players and you reveal it for one player only
12-31-2006, 04:09 PM#13
The)TideHunter(
No.
Hiding/Showing for in a GetLocalPlayer block can also Desync, although i have never experienced that, that is what people say.
Just do:
Collapse JASS:
local string s = ""
    if(GetLocalPlayer()==YourShowingPlayer) then
        set s = "Text to put on the textag"
    endif
    call CreateTextTag(s, ...)

Show it only has text for the one player, the other wont see it.
12-31-2006, 04:32 PM#14
Captain Griffen
Hiding/showing units is a very different thing to texttags, as it has a gameplay effect.
12-31-2006, 05:01 PM#15
Daelin
Quote:
Originally Posted by The)TideHunter(
Collapse JASS:
local string s = ""
    if(GetLocalPlayer()==YourShowingPlayer) then
        set s = "Text to put on the textag"
    endif
    call CreateTextTag(s, ...)

Don't you actually create the string for the local player?

Collapse JASS:
    local string s = "Text to put on the texttag"
    local string s1 =""
    if (GetLocalPlayer()==YourShowingPlayer) then
         set s1 = s
    endif
         call CreateTextTag(s1,...)

~Daelin