• 🏆 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!

Chat Commands: -set VALUE action: change variable to VALUE

Status
Not open for further replies.
Level 5
Joined
Jun 5, 2009
Messages
121
Hi guys,

I have a problem with a Chat Command i try this now for like 2 hours ._.

How in the hell is it possible to do this in a trigger like:

Event: Player - Player 1 (Red) types a chat message containing (-set + X)
Action: set integer-variable to entered number

X should be any number i want

+rep for help

Greetings, Chris
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Try this:

  • Test
    • Events
      • Player - Player 1 (Red) types a chat message containing -set as A substring
    • Conditions
      • (Substring((Entered chat string), 1, 5)) Equal to (==) -set
    • Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Equal to (==) 0
        • Then - Actions
          • Set integer = 0
          • Game - Display to (All players) the text: (Integer variable is set to: + 0)
          • -------- This if is just to make sure that the entered chat string is actually 0 instead of some text (explained in the next if) --------
        • Else - Actions
          • Set string = (Substring((Entered chat string), 6, (Length of (Entered chat string))))
          • Set integer = (Integer(string))
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • integer Equal to (==) 0
              • Then - Actions
                • Game - Display to (All players) the text: The entered value is not an integer number. Integer variable is set to 0.
                • -------- This is because whenever you convert a string that's not an integer to an integer it becomes 0... --------
              • Else - Actions
                • -------- Don't forget that if the entered chat message contains a real, it will be rounded down to an integer. --------
                • -------- So 10.9 will become 10, 10.3 will also become 10 etc... --------
                • Game - Display to (All players) the text: (Integer variable is set to: + (String(integer)))
The variable integer will be set to the integer that has been typed in.

Basically what you do here is: set variable string to the string that has been typed in after -set , then set the integer variable to a conversion of the variable string to an integer.
Then display a text message to all players by converting the integer variable back to a string.

Also: Don't forget that in the condition (Substring((Entered chat string), 1, 5)) Equal to (==) -set contains a spacebar after -set since it checks for 5 characters, not 4 :)

I also added a few conditions to check wether the entered chat string contains a integer number or text. Check the comments, it should be quite self-explenatory...
 
Last edited:
Level 33
Joined
Mar 27, 2008
Messages
8,035
Simple Understanding of Substring((Entered chat string) , x , y )
Okay, for example you type "-379564837" (without the quotes), and you have this Substring((Entered chat string) , 3 , 7 ), this means that the trigger will read a value from the 3rd digit to the 7th digit, so the output display would be 795648 since it takes the digit 3 to 7.

Take a look at my test map and see for yourself how this things work.

If you don't understand how the test map works, do question me.
 

Attachments

  • Simple Changing Max HP System.w3x
    13.9 KB · Views: 71
Status
Not open for further replies.
Top