Login
Register
Menu
Home
Forum
JassDoc
Types
Functions
Variables
Help
Chat
Media
Search
Search posts
WC3 JASS.com
"The Jass Vault" plus vJASS and Zinc
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Triggers & Scripting
WC3JASS.com
Jassdoc
[functions] GetLocalPlayer
Warcraft III:
Maps
Models
Skins
Icons
Spells / Systems
Tools
Tutorials
Snippets
JASS vJASS Spells and Systems
Tutorials
Chat @Discord
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
Jassdoc
Started by
City17
Views
381
Replies
0
Users
1
1
Pages:
1
Go Down
0 Members and 1 Guest are viewing this topic.
City17
Starter - level 2
Posts:
450
WC3 Models: 0
WC3 Tutorials: 0
WC3 Tools: 0
WC3 Maps: 0
WC3 Skins: 0
WC3 Icons: 0
WC3 Spells: 0
Reputation:
0
User
[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
function
whoami_command
(
)
-- all players know who entered this command, equal value on every computer
local
player_who_entered_command
=
GetTriggerPlayer
(
)
-- this always points to you!
local
myself
=
GetLocalPlayer
(
)
local
command_player_name
=
GetPlayerName
(
player_who_entered_command
)
local
my_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:
Code: jass
if
(
GetLocalPlayer
() == whichPlayer)
then
// Use only local code (no net traffic) within this block to avoid desyncs.
call
SetCameraPosition
(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:
Code: jass
if
(
GetLocalPlayer
() == whichPlayer)
then
// INSTANTLY DESYNCS! The unit was only killed on one player's screen! Others think it's alive
KillUnit
(someUnit)
endif
«
Last Edit: April 17, 2022, 04:00:37 AM by City17
»
Print
Pages:
1
Go Up
« previous
next »
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Triggers & Scripting
WC3JASS.com
Jassdoc
[functions] GetLocalPlayer
Suggested Topics
Jassdoc introduction
Started by
moyack
Replies: 3
Views: 4229
Jassdoc
Old Jass Functions
Started by
Jedi
Replies: 5
Views: 14817
General Jass Discussion
[GUI] GetLocalPlayer
Started by
Chaosy
Replies: 8
Views: 13164
Tutorial Zone
[reference] common.j
Started by
moyack
Replies: 40
Views: 58650
Jass Theory & Questions
[functions] BlzGetTriggerPlayerMouseX
Started by
moyack
Replies: 0
Views: 656
Jassdoc
PortaMx-SEF 1.54
|
PortaMx © 2008-2015
,
PortaMx corp.
Search
Username
Password
Always stay logged in
Forgot your password?