GetLocalPlayer
From WarCraft3
Template:common.j article series
Returns the player at the local computer. This native will return a different value for each human player, useful to run local code. The most common use are to change the camera or display text for only one player but it can be used with more advanced actions than that, with caution. However, using this native in ways that alters the game in game-play or internal engine ways will cause desyncs between players.
Contents |
Common Usage of GetLocalPlayer
Player Comparison
if GetLocalPlayer() == Player(0) then
//Code here is run only on Player(0)'s computer
endif
This is the most common usage of GetLocalPlayer.
IsPlayerInForce
if IsPlayerInForce(GetLocalPlayer(),someForce) then
//Code here is run only for players that are in someForce.
endif
This is an easy way to run local code for multiple players.
Direct Boolean Usage
call MultiboardDisplay(someMultiboard,GetLocalPlayer() == Player(0))
//someMultiboard is displayed only for Player(0)
//OR
call MultiboardDisplay(someMultiboard,IsPlayerInForce(GetLocalPlayer(),someForce))
//someMultiboad is displayed only for players in someForce
This is a very easy way to show a multiboard for a single player/force As you can see, both of the first two common uses can easily be used for any boolean argument.
Showing Special Effects For Player
function CreateSpecialEffectForPlayer takes real x, real y, player p, string s returns effect
if GetLocalPlayer() != p then // Check if the local player is not the passed player
set s = "" // Set s to nothing
endif
return AddSpecialEffect(s, x, y) // Add the special effect. The effect will only have a visible model on the passed player's
// computer, because it was changed locally.
endfunction
Keep in mind that this method does in fact create the special effect for all computers, it simply changes the model string locally. This does not result in a different handle stack for each player, so it does not desync.
It should be noted that when a string is first used, it is added to WC3's string table. If a string is first used locally, the string table could be different for each player, and therefore could cause a desync.
The empty string ("") is always in the string table, so there are no worries about changing the string table with "".