Returns reference to local player, as such it always points to yourself.
Every other player in the game gets their player respectively.
Do not use this function until you understand it fully and know how to avoid desyncs!
Always test your map in LAN multiplayer after changing code around it.
Warcraft 3 has the lock-step network/execution model.
This means the game simulation and code run on all players' computers with the exact same data at any point in time.
Look at this example (Lua):
functionwhoami_command() -- all players know who entered this command, equal value on every computer localplayer_who_entered_command = GetTriggerPlayer() -- this always points to you! localmyself = GetLocalPlayer() localcommand_player_name = GetPlayerName(player_who_entered_command) localmy_player_name = GetPlayerName(myself) -- everybody will see this player's name DisplayTextToForce(GetPlayersAll(), "Player ".. command_player_name .." entered the whoami command!") -- everybody will see their own name! DisplayTextToForce(GetPlayersAll(), "But my name is: ".. my_player_name) end
This function is always used when you want something only to happen to a certain player.
However if you aren't careful, you will cause a desync: where one player's game state is different from everybody else!
For example, you can apply camera position locally, this is how SetCameraPositionForPlayer works (Jass):
if (GetLocalPlayer() == whichPlayer) then // Use only local code (no net traffic) within this block to avoid desyncs. callSetCameraPosition(x, y) endif
Basic rule: anything that's only visual (like unit color) will not desync... unless your code relies on the exact value later in the game:
if cameraX is 123 then ... different players will have different camera positions here.
On the other hand, manipulating handles or creating units locally,
changing their health, attack, invisibility etc. - anything that changes the game will desync:
if (GetLocalPlayer() == whichPlayer) then // INSTANTLY DESYNCS! The unit was only killed on one player's screen! Others think it's alive callKillUnit(someUnit) endif
Returns reference to local player, as such it always points to yourself. Every other player in the game gets their player respectively.
Do not use this function until you understand it fully and know how to avoid desyncs! Always test your map in LAN multiplayer after changing code around it.
Warcraft 3 has the lock-step network/execution model. This means the game simulation and code run on all players' computers with the exact same data at any point in time. Look at this example (Lua):
This function is always used when you want something only to happen to a certain player. However if you aren't careful, you will cause a desync: where one player's game state is different from everybody else! For example, you can apply camera position locally, this is how
SetCameraPositionForPlayer
works (Jass):Basic rule: anything that's only visual (like unit color) will not desync... unless your code relies on the exact value later in the game: if cameraX is 123 then ... different players will have different camera positions here.
On the other hand, manipulating handles or creating units locally, changing their health, attack, invisibility etc. - anything that changes the game will desync: