• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Weather Snow

Status
Not open for further replies.
Here are some triggers to get you started:
  • Map Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Environment - Create at (Playable map area) the weather effect <Snow>
      • Set GlobalSnow = (Last created weather effect)
      • Environment - Turn GlobalSnow on
  • Chat Command
    • Events
      • Player - Player 1 (Red) types a chat message containing -weather snow as A substring
      • Player - Player 2 (Blue) types a chat message containing -weather snow as A substring
      • Player - Player 3 (Teal) types a chat message containing -weather snow as A substring
      • ... etc... for all players
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) Else do (Else actions)
        • If - Conditions
          • (Substring((Entered Chat String), 15, 17)) Equal to on
        • Then - Actions
          • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
          • Environment - Turn GlobalSnow on
          • Custom script: endif
        • Else - Actions
          • If (All conditions are true) then do (Then Actions) Else do (Else Actions)
            • If - Conditions
              • (Substring((Entered Chat String), 15, 18)) Equal to off
            • Then - Actions
              • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
              • Environment - Turn GlobalSnow off
              • Custom script: endif
            • Else - Actions
Something like that. First, I setup the snow weather effect when the game starts, and I assign it to a weather effect variable "GlobalSnow". In the command trigger, I register when the player types "-weather snow" somewhere in their chat string. To check the follow-up command, I use the Substring function to grab the part of the command I care about. I only care to handle "-weather snow on" or "-weather snow off", so I can directly check if the part after "snow" is equal to "on" or "off" (index 15 to 17 for "on" or index 15 to 18 for "off").

The custom script is used so that only the player who typed the chat message will have the weather turned on or off. If you are interested in using this function for other things, check out the link in my signature. GetLocalPlayer() can lead to disconnects when used improperly, but it is fine in this case since you are just showing/hiding a visual effect.
 
Level 11
Joined
Jan 23, 2015
Messages
788
Here are some triggers to get you started:
  • Map Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Environment - Create at (Playable map area) the weather effect <Snow>
      • Set GlobalSnow = (Last created weather effect)
      • Environment - Turn GlobalSnow on
  • Chat Command
    • Events
      • Player - Player 1 (Red) types a chat message containing -weather snow as A substring
      • Player - Player 2 (Blue) types a chat message containing -weather snow as A substring
      • Player - Player 3 (Teal) types a chat message containing -weather snow as A substring
      • ... etc... for all players
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) Else do (Else actions)
        • If - Conditions
          • (Substring((Entered Chat String), 15, 17)) Equal to on
        • Then - Actions
          • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
          • Environment - Turn GlobalSnow on
          • Custom script: endif
        • Else - Actions
          • If (All conditions are true) then do (Then Actions) Else do (Else Actions)
            • If - Conditions
              • (Substring((Entered Chat String), 15, 18)) Equal to off
            • Then - Actions
              • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
              • Environment - Turn GlobalSnow off
              • Custom script: endif
            • Else - Actions
Something like that. First, I setup the snow weather effect when the game starts, and I assign it to a weather effect variable "GlobalSnow". In the command trigger, I register when the player types "-weather snow" somewhere in their chat string. To check the follow-up command, I use the Substring function to grab the part of the command I care about. I only care to handle "-weather snow on" or "-weather snow off", so I can directly check if the part after "snow" is equal to "on" or "off" (index 15 to 17 for "on" or index 15 to 18 for "off").

The custom script is used so that only the player who typed the chat message will have the weather turned on or off. If you are interested in using this function for other things, check out the link in my signature. GetLocalPlayer() can lead to disconnects when used improperly, but it is fine in this case since you are just showing/hiding a visual effect.

Isn't this just the same? It turns off the weather for all players, he wants to turn off the weather only for 1 player, if he uses the command.
 
@RobertMKD: The custom script ensures that only the player who typed the command will have the weather effect turned on/off.

GetLocalPlayer() returns the current player executing the line of code. GetTriggerPlayer() corresponds to the person who input the chat message.

Let's say Player 1 (Red) types the command. All players will run the trigger (to keep everything in sync), but when it hits the if/then block, it compares the local player to GetTriggerPlayer() (which is Player 1 (Red)) in this case. For each individual player, the local player will return themselves. Here is an easy way to visualize it:

Player 1 (Red) == GetTriggerPlayer() (true)
Player 2 (Blue) == GetTriggerPlayer() (false)
Player 3 (Teal) == GetTriggerPlayer() (false)
... etc ...

Since only Player 1 (Red)'s code returns true, they are the only ones who evaluate the code within the block. Thus, the code is ran only for one player.
 
Level 17
Joined
Dec 11, 2014
Messages
2,004
Isn't this just the same? It turns off the weather for all players, he wants to turn off the weather only for 1 player, if he uses the command.

Purge's Solution is correct. Do you know GetLocalPlaye()? It shows only for 1 player.


@Purge: I Think the First trigger should be deleted, because n00bs think it SHOULD Be there and mistakenly Use it. Feh.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
Isn't this just the same?
No it is different, look at the JASS flow control statement added.
JASS:
if GetLocalPlayer() == GetTriggerPlayer() then
This means that the code in the block will only run when the player returned by "GetLocalPlayer" (the player for the client running it) is equal to GetTriggerPlayer (the player which triggered the event). Since only 1 human player can trigger the event it will only run for that player.

GetLocalPlayer is a special native in that the result it returns is not synchronous, but rather based on the client which is running it. As such the return value is not synchronous across clients so can be used to execute code only for one client. Note that this can only be done with stuff that does not alter game state, since otherwise the game will drop players for being "Out of Sync" due to the mechanics of RTS multiplayer synchronization.

GetLocalPlayer will only ever return players which are both human and currently playing. It is also different (usually) for each client in a multiplayer session (if two people play the same client it will work for both of them, this however is not possible with standard WC3 hosting). Computer, not playing and neutral slots cannot ever be returned by it since they are never run by a client (they are just part of the game).
 
Status
Not open for further replies.
Top