• 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] Correct use of LocalPlayer()

Status
Not open for further replies.
Level 9
Joined
Jul 27, 2006
Messages
652
Could someone please enlighten me on how to correctly use LocalPlayer().
Ive heard alot of people saying that LocalPlayer Desyncs a game but iv never heard when or why.
I'd also like to know how to use LocalPlayer so lets say only certian players can see Floating Text, Multiboards ect.
And could someone maybe list other usefull uses of LocalPlayer().
Thanks in advanced!
 
Using GetLocalPlayer() is actually pretty simple, you just need to know when to use it and when not to use it
To do an action for one player(example showing texttag)
JASS:
if GetLocalPlayer() == WhichPlayer then
call SetTextTagVisibillity(sometexttag, false)
endif
Inside this "if" box, all actions will be done for "WhichPlayer"
another way to use it is like this:
JASS:
call SetTextTagVisibillity(sometexttag,GetLocalPlayer() == WhichPlayer)
Desyncs usually happens when you create an object or change gameplay for one player,
like this:
JASS:
local integer unitid='h000'
if GetLocalPlayer() == WhichPlayer then
set unitid='e000'
endif
call CreateUnit(player,unitid,x,y,180)
this will create the unit 'h000' for all players except WhichPlayer, who will have the unit as 'e000'.
this will cause a desynce = server split.

GetLocalPlayer() is also usefull for showing multiboards, special effects etc. for other players.
 
Level 9
Joined
Jul 27, 2006
Messages
652
I see,

Thanks Diablo, i had the general idea about GetLocalPlayer() = WhichPlayer but i had no idea about the game Desync'ing.

Thanks again!
 
Level 11
Joined
Jul 12, 2005
Messages
764
And what about cameras? Will a function like this cause desync? (It runs every 0.2 seconds... you know, the camera is locked on the player's hero.)
JASS:
function AAA takes nothing returns nothing
local integer a = 0
loop
exitwhen a > 12
if GetLocalPlayer() == Player(a) then
call PanCameraTo(GetUnitX(usg_SomeUnit[a]),GetUnitY(usg_SomeUnit[a]))
endif
set a = a + 1
endloop
endfunction
 
Cameras doesn't desync.
look at "CameraSetTargetNoiseForPlayer"
JASS:
function CameraSetTargetNoiseForPlayer takes player whichPlayer, real magnitude, real velocity returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CameraSetTargetNoise(magnitude, velocity)
    endif
endfunction
 
Level 9
Joined
Jul 27, 2006
Messages
652
So GetLocalPlayer() doesnt Desync on any visual functions. But if the function creates an ingame object it will Desync?
Purple said that it only Desyncs when the unit dies, so when the unit is alive will two different players see different units at the same place doing the same thing untill that unit Casts a spell,attacks,is attacked or plays animation other unit doesnt have. Because all those actions require things that are specific to the unit?
 
Level 9
Joined
Jul 27, 2006
Messages
652
Hmmm maybe thats because cameras are objects? But im not sure...
That reminds me, what other things cause a game to Desync?
[offtopic] He is churning out the posts isnt he? Wasnt he on like 1800 less than a month ago!?!
 
Only use GetLocalPlayer() for visual effects:
showing fade filer, showing multiboards, changing vertex color, showing special effects.
ANY creation of an object is risky with GetLocalPlayer()
also, i'm pretty sure changing time of day will cause a desync.
I never heard anything about cameras being risky with LocalPlayer, Many blizzard.j functions use GetLocalPlayer() in displaying text and changing camera for 1 player, so i dont think you should be afraid to use them.
 
Level 9
Joined
Jul 27, 2006
Messages
652
Ok, but are there any other things that Desync a game that dont include GetLocalPlayer()?
[offtopic] Theres nothing wrong with it, apart from the fact your so helpful you make the rest of us look bad :smile:
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Desynchs without GetLocalPlayer? I'd be surprised, well, except for the things that are different per player. Eg.

JASS:
constant native GetCameraField              takes camerafield whichField returns real
constant native GetCameraTargetPositionX    takes nothing returns real
constant native GetCameraTargetPositionY    takes nothing returns real
constant native GetCameraTargetPositionZ    takes nothing returns real
constant native GetCameraTargetPositionLoc  takes nothing returns location
 
Level 5
Joined
Feb 16, 2006
Messages
151
Er, I think it's way different.
I think GetLocalPlayer would cause a desync if the created effect/scenario/object or what ever for that single player is too much to be unique.
Like, things that are less striking would be floating texts, multiboards, or game texts, but if comes to a real unit or effect, then it's desyncs for sure.
What made me to think this way was that I managed to create a cine-filter for specific players only, a cine-filter such as "White-Mask".
Using CinematicFadeBJ alone with GetLocalPlayer did a desync, so I like, did
JASS:
call CinematicFadeBJ(bj_CINEFADETYPE_FADEOUT,0.00,"ReplaceableTextures\\CameraMasks\\White_mask.blp",250.00,250.00,250.00,0.00)
call DisplayCineFilter(false)
call EnableUserUI(true)
then
JASS:
if (GetLocalPlayer == p) then 
    call DisplayCineFilter(true)
    call EnableUserUI(false)
endif
for affected players only, which worked.
 
Level 5
Joined
Feb 16, 2006
Messages
151
Wow, really? So you can like, create a special effect for only one user? Never thought this was possible, but I bet that special effect has to be nothing big or striking.
Create 10 like those and you get your desync, I guess.
 
Level 11
Joined
Jul 12, 2005
Messages
764
Purple, you said, these things desync only when they are killed/destroyed. What if you create an effect this way:
JASS:
local string path = "<effect path>"
if GetLocalPlayer() != <player> then
    set path = ""
endif
call DestroyEffect(AddSpecialEffect(path,<x>,<y>))
 
I bet the above function will work.
It desyncs when the unit dies(IF it has same hp, dmg blabla)
but if it doesent have the same hp, dmg blabla, then a desync can happen even whenever it takes damage.
Desyncs seem to be easy to avoid, just watch out for things that creates a new object(as this is what usually causes a desync)

The best place to learn more about desyncs and usage of GetLocalPlayer() would be www.wc3jass.com.
 
Level 4
Joined
Dec 14, 2004
Messages
85
You can read the last line if you don't wanna read.

I had a bug once in one of my maps that desynced people, It had to do with making sounds quieter if the players camera was further away. So what I did was run a pick every player loop and if picked player equals LocalPlayer then it set the volume of the sound(Yes unnecessary) according to the distance of the camera.

Now this caused desyncs and the reason I think is why is because I heard that if you call GetLocalPlayer() inside of something that is being ran for a local player it causes a desync. This could be for timing issues? I dunno. but GetCameraPosition() calls for local player.

So in conclusion I'm pretty certain calling GetLocalPlayer() or camera natives that run for a local player can not be ran for a local player.(Like calling GetLocalPlayer for a Local player) and yes, taking this out of the function fixed it.
 
Level 7
Joined
Apr 5, 2006
Messages
128
Pan Camera As Necessary desynchs for some weird reason (it's local)

The other ones are fine

Blizzard explains it efficiently in the blizzard.j

JASS:
function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, GetCameraTargetPositionLoc())
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
endfunction

> // Use only local code (no net traffic) within this block to avoid desyncs.

Problem is, they don't only use local code in the whole function >_<

Notice the global variables.
 
Level 6
Joined
Mar 2, 2006
Messages
306
Problem is, they don't only use local code in the whole function >_<
Notice the global variables.
er, what global variables? all i see are two bj constants and reading constants doesn't split maps. i'm pretty sure that reading gloval variables wouldn't split - only writing would.

does anyone know for fact what's wrong with SmartCameraPanBJ?

-------------

also, i had a sure split (100% of the time) in my map once. it turned out that
  • Selection - Select TempUnitGroup for CLPlayer
action (that is, SelectGroupForPlayerBJ call) caused desync every time i clicked a button of my custom spell.
 
Level 7
Joined
Apr 5, 2006
Messages
128
edge[d1];273115 said:
er, what global variables? all i see are two bj constants and reading constants doesn't split maps. i'm pretty sure that reading gloval variables wouldn't split - only writing would.

does anyone know for fact what's wrong with SmartCameraPanBJ?

-------------

also, i had a sure split (100% of the time) in my map once. it turned out that
  • Selection - Select TempUnitGroup for CLPlayer
action (that is, SelectGroupForPlayerBJ call) caused desync every time i clicked a button of my custom spell.

GetCameraTargetPositionLoc() creates a location.
 
Status
Not open for further replies.
Top