• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

GetLocalPlayer() question

Status
Not open for further replies.
Level 3
Joined
Nov 14, 2010
Messages
47
does these legal, creates a unit for a player only via GetLocalPlayer() function, i mean, does it make crash?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
You've got to look at it like this:

GetLocalPlayer() calls your computer.
So if you say "if GetLocalPlayer() == Player(0)", it is actually checking whether the computer you're playing on is playing with Red.

If you create a unit like that, it will only create the unit for that player (other players simple 'don't exist' within that function).
That means the unit will only be created on 1 game, the other games don't even know that unit exists.
E.g.: if you say "All Players" within that function, it will still only call 1 player (because, as said before, other players simply don't exist).

No, it will not crash: it will desync.
The player for whom you created the unit will not be playing the same game as the others anymore.

Never, ever do anything like that. It's dangerous.
 
Level 15
Joined
Oct 16, 2010
Messages
941
You've got to look at it like this:

GetLocalPlayer() calls your computer.
So if you say "if GetLocalPlayer() == Player(0)", it is actually checking whether the computer you're playing on is playing with Red.

If you create a unit like that, it will only create the unit for that player (other players simple 'don't exist' within that function).
That means the unit will only be created on 1 game, the other games don't even know that unit exists.
E.g.: if you say "All Players" within that function, it will still only call 1 player (because, as said before, other players simply don't exist).

No, it will not crash: it will desync.
The player for whom you created the unit will not be playing the same game as the others anymore.

Never, ever do anything like that. It's dangerous.

What he said. GetLocalPlayer() is useful for things like floating text and screen masks that don't return handles. I.E. if you only wanted floating text to be seen by 1 person.
 
Level 3
Joined
Nov 14, 2010
Messages
47
What he said. GetLocalPlayer() is useful for things like floating text and screen masks that don't return handles. I.E. if you only wanted floating text to be seen by 1 person.

don't return handles, gotcha, thx for help
anyway, does this legal?
JASS:
function whatever takes nothing returns nothing
    local integer q=0
    if GetLocalPlayer()==Player(0) then
        set q='h001'
    endif
    call CreateUnit(q, nevermindotherparameters)
endfunction
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
don't return handles, gotcha, thx for help
anyway, does this legal?
JASS:
function whatever takes nothing returns nothing
    local integer q=0
    if GetLocalPlayer()==Player(0) then
        set q='h001'
    endif
    call CreateUnit(q, nevermindotherparameters)
endfunction

is this legal?*

Of course may it cause a desync. Each player gets a unit of another type, more precisely one unit won't even be created as 0 is not a valid unitTypeId. So you desync the id stack for agent objects, and the next object would get different ids on different clients.

Even if it would create a unit, units are interactive objects, this would disconnect the game as soon as there is divergence between the clients originating from different values such as the unit's hitpoints leading to different death times and thereby creating whole different gameplay scenarios.
 
Tbh this is the best you can do:
JASS:
function showUnitForPlayer takes unit u, player p returns nothing
    if  GetLocalPlayer() != p then
        call SetUnitScale(u,0.01,0.01,0.01)
    endif
endfunction

Although, I am not sure exactly what scaling does to affect the unit. If it affects collision, it might desync. You can probably still select it with drag select, so maybe you can add locust locally, but I never bothered to check if it works without desyncs. :\

Generally, locally messing with units are the most prone to desyncs, so try to find workarounds.
 
Level 3
Joined
Nov 14, 2010
Messages
47
i try to creates one units that just visible for a player only, not sure how to works with
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
It's not only "not visible" for the other players, it just doesn't exist for them.
So a unit exists for one player, while it doesn't for the others.
That results in warcraft thinking "wtf is that computer doing? Trying to move a unit that doesn't exist... Lemme fix that" and thus the server will split.

I don't know if this works, DSG might want to check it out, but at least it's a better option than creating a unit locally:
JASS:
call ShowUnit(Unit, false)
if GetLocalPlayer() == Player(...) then
    call ShowUnit(Unit, true)
endif
It shows the unit for Player(...).


PurgeandFire already gave a solution though, scaling the unit will also render him 'invisible' to others.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,217
It is clear why it causes a desync if you think of this.

2 units belonging to players which are hostile to each other (1 unit each fight). For some reason 1 of them is hidden on one players machine while none are hidden on the other. As such the units automatically target an enemy and fight on one of the players machines while on the other, one unit is forced to stand while the hidden unit attacks normally as you can not attack hidden units. Thus why it should desync when done.

The actual reason behind the desync is probably because hidden units are removed from something perodic which causes a split when it gets to the hidden unit.
 
Status
Not open for further replies.
Top