HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

The "-water r g b" command

05-26-2009, 03:30 AM#1
Hyperbolex
I have recently implemented a command "-water r g b" similar to DotA's "-water [color]" command. However, I have no idea how DotA's version is local. Which means only the player that types "-water [color]" command sees the changed color water. My version is a universal change. How can I make it so that it's local only?

Thanks in advance.
05-26-2009, 05:05 AM#2
DioD
use getlocalplayer() blocks
05-26-2009, 05:29 AM#3
Hyperbolex
What does that mean? It returns a player?
05-26-2009, 08:27 AM#4
Ammorth
GetLocalPlayer() returns the player at that current computer that called the function (aka, each player returns theirself when they call it). Therefore, you can do stuff for only 1 play by checking if the computer belongs to a certain player, for example:

Collapse JASS:
 if GetLocalPlayer == Player(0) then

This will only be true on player red's computer while false on all of the other players. Therefore, you can change the water color inside the if/then/else block and it would only affect Player(0). In your case though, you would replace Player(0) with GetTriggerPlayer().

Keep in mind, the stuff done inside a GetLocalPlayer block is local, and if you change part of the game for one player, it may cause him to desync. Therefore, a good rule of thumb is to do as much as you can outside of the block, and then only change the final visual elements on the inside.
05-26-2009, 08:41 AM#5
Hyperbolex
Thank you.

So I would need 10 of those if/endif statements for 10 players right?

It's kind of strange to me since the "SetWaterBaseColor(r, g, b, a)" does not take a player parameter and I'd call this for all players with the condition GetLocalPlayer() == TriggeringPlayer(). @@"
05-26-2009, 02:50 PM#6
snowtiger
What they mean is like this:

Collapse JASS:
If GetLocalPlayer() == GetTriggerPlayer() then
     call SetWaterBaseColor(r, g, b, a)
endif

GetLocalPlayer is different for each computer, so only one computer will have the if then block return true. Script isn't executed on the host, but on every players machine.
05-26-2009, 08:35 PM#7
Hyperbolex
But the function "SetWaterBaseColor(r , g, b, a)" doesn't take a player parameter, how does it know? Script being executed in local player's machine makes sense that's why everyone has a local copy of the map. If I were to just call SetWaterBaseColor(r, g, b, a) WC3 would loop through all player's map and call the same script?
05-26-2009, 09:35 PM#8
Anitarf
There's no looping involved, code is executed simultaneously on all computers that are in the game. Each player has a copy of the game running, so your entire's map code, including the call SetWaterBaseColor(r, g, b, a) will run on all computers. If, however, you have a GetLocalPlayer() if block, then the content of that block will only run on one player's machine. The code in the if block doesn't need to take a player parameter, because if the player isn't right it never runs in the first place.