• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How do I set the value of a variable by typing something?

Status
Not open for further replies.
Level 4
Joined
Nov 6, 2011
Messages
44
For example if I type "-value 300" it'll set the value of a variable(Let's call the value "Damage" in this case). So if I type "-value 2" it'll set "Damage" to 2. I've never been good with triggering commands. Help would be appreciated.
 
Level 7
Joined
Mar 5, 2009
Messages
254
You mean this ?
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) types a chat message containing -value as A substring
    • Conditions
    • Actions
      • Set Damage = (Integer((Substring((Entered chat string), 7, (Length of (Entered chat string))))))
      • Game - Display to (All players) the text: (String(Damage))
 
Level 12
Joined
Mar 24, 2011
Messages
1,082
Um try yourself before looking in this... its prety easy...

Damage is integer variable
Conversion - Convert string to integer > Substring > Event response - Entered chat string / 7 / String lenght > Event response - Entered chat string
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
You mean this ?
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) types a chat message containing -value as A substring
    • Conditions
    • Actions
      • Set Damage = (Integer((Substring((Entered chat string), 7, (Length of (Entered chat string))))))
      • Game - Display to (All players) the text: (String(Damage))

You should at least explain to him what's the use of that Action here and there



Ok, here's the thing
By using Substring function, you will have to put 2 values inside it

Example: Player - Add (Integer((Substring((Entered chat string), 1, 5)))) to Player 1 (Red) Current gold

What is meant by numbers 1 and 5 in there, is their position of letters for the words

Okay, let's say we follow the example of 1, 5

When I type "-gold 300", it will only take the value starts from first letter (1) until 5th letter (5)

So, if you set a variable, the variable will set a "-gold <space>"

Spaces also count as a letter, so if you want a -gold 300, to add 300 gold to your player, just

Player - Add (Integer((Substring((Entered chat string), 7, 9)))) to Player 1 (Red) Current gold

So, it will take the 7th letter until 9th letter, which in this case is 300

This include limit inside your function, if for example a player types "-gold 30000000", the trigger will only read 30000000

If you don't want a limitation to your trigger, just change the final value to
Player - Add (Integer((Substring((Entered chat string), 7, (Length of (Entered chat string)))))) to Player 1 (Red) Current gold


This will give you a no-limit addition of gold to the player (but you will still have limit for hard-coded maximum gold per player in Warcraft III Game Engine)
 
Status
Not open for further replies.
Top