Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation
This topic is the discussión abut the function GetLocalPlayer. You can see all the information about this function keyword HERE.

[functions] GetLocalPlayer No New Posts Jassdoc

Started by
City17

0 Members and 1 Guest are viewing this topic.

[functions] GetLocalPlayer
on: April 07, 2022, 06:34:13 PM

returns reference to local player, as such it always points to yourself. Every other player in the game gets his 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:
Code: Lua
  1. function whoami_command()
  2. -- all players know who entered this command, equal value on every computer
  3. local player_who_entered_command = GetTriggerPlayer()
  4. -- this always points to you!
  5. local myself = GetLocalPlayer()
  6.  
  7. local command_player_name = GetPlayerName(player_who_entered_command)
  8. local my_player_name = GetPlayerName(myself)
  9.  -- everybody will see this player's name
  10. DisplayTextToForce(GetPlayersAll(), "Player ".. command_player_name .." entered the whoami command!")
  11. -- everybody will see their own name!
  12. DisplayTextToForce(GetPlayersAll(), "But my name is: ".. my_player_name)
  13. 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:
Code: jass
  1. if (GetLocalPlayer() == whichPlayer) then
  2.    // Use only local code (no net traffic) within this block to avoid desyncs.
  3.    call SetCameraPosition(x, y)
  4. 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:
Code: jass
  1. if (GetLocalPlayer() == whichPlayer) then
  2.    // INSTANTLY DESYNCS! The unit was only killed on one player's screen! Others think it's alive
  3.    KillUnit(someUnit)
  4. endif
« Last Edit: April 17, 2022, 04:00:37 AM by City17 »



 

Started by moyack

Replies: 3
Views: 3637
Jassdoc

Started by Jedi

Replies: 5
Views: 14206
General Jass Discussion

Started by Chaosy

Replies: 8
Views: 12290
Tutorial Zone

Started by moyack

Replies: 40
Views: 56816
Jass Theory & Questions

Started by moyack

Replies: 0
Views: 261
Jassdoc
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...