- Joined
- Jan 5, 2005
- Messages
- 3,515
Using Chat Commands
This tutorial will contain three tutorials when finished, all relating to doing stuff using chat commands. You may have seen on maps people being able to type –help to bring up a help menu or –kick (player colour) to kick a player. This tutorial will tell you how to do all those things you have seen and possibly more. I decided to make this tutorial after discovering how to do what is described in Part 1, which I think is very important and useful to know, so I thought I would share the knowledge. I’ve done my best to explain it and I hope it’s understandable, any things I should add, change or reword, please tell me. Important things and Key Terms are underlined; there is also a list of Key Terms relevant to that tutorial at the end of each one.
Contents:
Part 1 - Using Substrings With an Unknown Value
Part 2 - Using Substrings With a Known Value (Coming Soon)
Part 3 – Chat Commands To Do Common Functions (Coming Soon)
Part 1 - Using Substrings With an Unknown Value
This tutorial is concerned with using unknown substrings within a chat string, and using these substrings to set variables, run processes or do just about anything you can in GUI.
First Things First - What is a substring?
A substring is a word, string of words or a value within a string which has been isolated because it is relevant to a specific process. For example you may have seen maps where the players can enter “–Gold X” into chat to receive X amount of gold (I wish ) or something similar. In that example the activator is the command “–Gold” which means the system looks for a player typing –gold as an event. The substring of interest is the value entered for X, and this is what needs to be isolated and manipulated to give the player the gold they want.
Next Up – Putting it to use:
This kind of substring manipulation is useful specifically when dealing with numbers or a value that cannot be from a known set of value. What this means is that you wouldn’t use this to kick players because you already know that you are only going to have 12 possible players and you know their colours and numbers. You would however, use this to deal with numbers; this is because a user can enter any number from 0 to the memory limit of wc3, to have that many logical comparisons would be just silly! So we have to isolate the number entered. This can also be used for saved games if you have one of those crazy systems where you enter a code and this loads up a character based on that code. I don’t know how they do it, but I’m guessing it starts like this.
The Event – Learn By Example:
I’m going to explain how substrings like this work by taking you through an example, the exact same one described above, to give a player a certain amount of gold when they enter –Gold followed by a value.
To start of, all you do is make a normal event using the activator you want with a space after the word used for your activator. So for gold the activator will be “-Gold ”. Notice how there is a space after Gold? This space is very important and must be included to work! The entered chat message should be set as a string. So you should have something like this, just with your preferred activator:
Things Get Tricky - Isolating The Substring:
Right, it was easy so far, just a little reading and some easy event; well this is where things get confusing, so I’m going to do my best to simplify this. The command used to isolate the integer from the string is this:
(Integer((Substring((Entered chat string), 7, 11))))
This command is repeated for pretty much everything so you better get used to it This command will find the (sub)string written after –Gold in the message entered by the user and convert it into a number. The first thing that to note here is that this is function results in getting a number, which it extracts from a string. The function “Convert String to Integer” is used here as the first part which can be seen by the first bracket containing the word “Integer”, I stress once again this function gets an integer from a string! The next part depicted by the “Substring” bracket tells us we are interested in isolating a substring, i.e. we are interested in isolating part of a string. The next part “Entered chat string” tells us we are looking for a substring within the entered chat string. Still with me? I hope so. The next two numbers tell us where to look in the string by showing which place the string will be read from and which place it will finish reading at. For example:
“-Gold ” contains 6 characters, including all the letters, the dash and the space (always count the space!). In the example command I have just shown the string is read from place 7 to place 11. This means anything that is entered after the “-Gold ” is read without the “-Gold ” bit. So if a person entered “-Gold 12345” the system will have isolated 12345 as an integer, because that number was from place 7 to 11 in the chat string.
As you can see in the example command I have used the places ranging from 7 to 11; it would be possible to use places ranging from 7 to anything depending on how big the number you want. If someone has got the place range of 7-11 and a person types in less than 5 digits (5 being the difference between 7 and 11) the system will still only register the digits entered, so it would read 123 as 123, not some crazy 000123 number or something. Basically you can set the second number to whatever you want so long as the first number is relevant to the place after the activator and, importantly, the space after it. It is possible to make the length of the string effectively limitless by modifying the command to look like this:
(Integer(Substring((Entered chat string), 7, (Length of (Entered chat string)))))
By changing the number (was 11) to the string length of the typed in chat message you can make the substring limitless. This is useful when dealing with substrings which could be potentially any length.
If you have understood this you should now know how to get an integer from the substring of interest that was entered with the chat string. Using the same method it is also possible to get words from a substring, in which case you would not need the initial “(Integer” part as you will be extracting a string from a string, not an integer from a string. The main thing to remember is that the two numbers read the chat message from the place where the substring of interest starts to where it finishes. That’s the bulk of this over and the hardest part (to understand and explain) behind us, now we can do something with it!
Action – Putting it to use:
Hopefully now you understand how this command works, but if not this example of how you would use the command will explain it better than I can:
Condition – Making sure the Activator is right!
One thing that’s flawed in this (so far) is that is uses the “as A substring” event which means if a person types –Gold anywhere in a chat message it will try to give the person the value written from places 7-11, even if that were a word instead of a number. This isn’t such a problem here, but in other situations it can be. To counter this a condition is used that checks that the activator is written at the start of the chat string and not in the middle somewhere:
Conclusion
The final, completed trigger looks like this:
Using substrings like this you can do many things, hopefully now you have the basics you can do anything you want with substrings, Good Luck!
Key terms:
(Note: most of these I made up, but it helps me explain it so they are useful to know)
Activator – the word or command at the start of the chat message that the system looks for as an event for the trigger.
Substring of Interest – the value or word within the entered chat message, usually straight after the activator, that needs to be isolated and manipulated.
Place Range – the range between which the substring of interest is read.
This tutorial will contain three tutorials when finished, all relating to doing stuff using chat commands. You may have seen on maps people being able to type –help to bring up a help menu or –kick (player colour) to kick a player. This tutorial will tell you how to do all those things you have seen and possibly more. I decided to make this tutorial after discovering how to do what is described in Part 1, which I think is very important and useful to know, so I thought I would share the knowledge. I’ve done my best to explain it and I hope it’s understandable, any things I should add, change or reword, please tell me. Important things and Key Terms are underlined; there is also a list of Key Terms relevant to that tutorial at the end of each one.
Contents:
Part 1 - Using Substrings With an Unknown Value
Part 2 - Using Substrings With a Known Value (Coming Soon)
Part 3 – Chat Commands To Do Common Functions (Coming Soon)
Part 1 - Using Substrings With an Unknown Value
This tutorial is concerned with using unknown substrings within a chat string, and using these substrings to set variables, run processes or do just about anything you can in GUI.
First Things First - What is a substring?
A substring is a word, string of words or a value within a string which has been isolated because it is relevant to a specific process. For example you may have seen maps where the players can enter “–Gold X” into chat to receive X amount of gold (I wish ) or something similar. In that example the activator is the command “–Gold” which means the system looks for a player typing –gold as an event. The substring of interest is the value entered for X, and this is what needs to be isolated and manipulated to give the player the gold they want.
Next Up – Putting it to use:
This kind of substring manipulation is useful specifically when dealing with numbers or a value that cannot be from a known set of value. What this means is that you wouldn’t use this to kick players because you already know that you are only going to have 12 possible players and you know their colours and numbers. You would however, use this to deal with numbers; this is because a user can enter any number from 0 to the memory limit of wc3, to have that many logical comparisons would be just silly! So we have to isolate the number entered. This can also be used for saved games if you have one of those crazy systems where you enter a code and this loads up a character based on that code. I don’t know how they do it, but I’m guessing it starts like this.
The Event – Learn By Example:
I’m going to explain how substrings like this work by taking you through an example, the exact same one described above, to give a player a certain amount of gold when they enter –Gold followed by a value.
To start of, all you do is make a normal event using the activator you want with a space after the word used for your activator. So for gold the activator will be “-Gold ”. Notice how there is a space after Gold? This space is very important and must be included to work! The entered chat message should be set as a string. So you should have something like this, just with your preferred activator:
-
Events
- Player - Player 1 (Red) types a chat message containing -Gold as A substring
Things Get Tricky - Isolating The Substring:
Right, it was easy so far, just a little reading and some easy event; well this is where things get confusing, so I’m going to do my best to simplify this. The command used to isolate the integer from the string is this:
(Integer((Substring((Entered chat string), 7, 11))))
This command is repeated for pretty much everything so you better get used to it This command will find the (sub)string written after –Gold in the message entered by the user and convert it into a number. The first thing that to note here is that this is function results in getting a number, which it extracts from a string. The function “Convert String to Integer” is used here as the first part which can be seen by the first bracket containing the word “Integer”, I stress once again this function gets an integer from a string! The next part depicted by the “Substring” bracket tells us we are interested in isolating a substring, i.e. we are interested in isolating part of a string. The next part “Entered chat string” tells us we are looking for a substring within the entered chat string. Still with me? I hope so. The next two numbers tell us where to look in the string by showing which place the string will be read from and which place it will finish reading at. For example:
“-Gold ” contains 6 characters, including all the letters, the dash and the space (always count the space!). In the example command I have just shown the string is read from place 7 to place 11. This means anything that is entered after the “-Gold ” is read without the “-Gold ” bit. So if a person entered “-Gold 12345” the system will have isolated 12345 as an integer, because that number was from place 7 to 11 in the chat string.
As you can see in the example command I have used the places ranging from 7 to 11; it would be possible to use places ranging from 7 to anything depending on how big the number you want. If someone has got the place range of 7-11 and a person types in less than 5 digits (5 being the difference between 7 and 11) the system will still only register the digits entered, so it would read 123 as 123, not some crazy 000123 number or something. Basically you can set the second number to whatever you want so long as the first number is relevant to the place after the activator and, importantly, the space after it. It is possible to make the length of the string effectively limitless by modifying the command to look like this:
(Integer(Substring((Entered chat string), 7, (Length of (Entered chat string)))))
By changing the number (was 11) to the string length of the typed in chat message you can make the substring limitless. This is useful when dealing with substrings which could be potentially any length.
If you have understood this you should now know how to get an integer from the substring of interest that was entered with the chat string. Using the same method it is also possible to get words from a substring, in which case you would not need the initial “(Integer” part as you will be extracting a string from a string, not an integer from a string. The main thing to remember is that the two numbers read the chat message from the place where the substring of interest starts to where it finishes. That’s the bulk of this over and the hardest part (to understand and explain) behind us, now we can do something with it!
Action – Putting it to use:
Hopefully now you understand how this command works, but if not this example of how you would use the command will explain it better than I can:
-
Oh Noes
-
Events
- Player - Player 1 (Red) types a chat message containing -Gold as A substring
- Conditions
-
Actions
- Player - Add (Integer((Substring((Entered chat string), 7, 11)))) to (Player((Player number of (Triggering player)))) Current gold
-
Events
Condition – Making sure the Activator is right!
One thing that’s flawed in this (so far) is that is uses the “as A substring” event which means if a person types –Gold anywhere in a chat message it will try to give the person the value written from places 7-11, even if that were a word instead of a number. This isn’t such a problem here, but in other situations it can be. To counter this a condition is used that checks that the activator is written at the start of the chat string and not in the middle somewhere:
-
Conditions
- (Substring((Entered chat string), 1, 6)) Equal to –Gold
Conclusion
The final, completed trigger looks like this:
-
Oh Noes
-
Events
- Player - Player 1 (Red) types a chat message containing -Gold as A substring
-
Conditions
- (Substring((Entered chat string), 1, 6)) Equal to -Gold
-
Actions
- Player - Add (Integer((Substring((Entered chat string), 7, 11)))) to (Player((Player number of (Triggering player)))) Current gold
-
Events
Using substrings like this you can do many things, hopefully now you have the basics you can do anything you want with substrings, Good Luck!
Key terms:
(Note: most of these I made up, but it helps me explain it so they are useful to know)
Activator – the word or command at the start of the chat message that the system looks for as an event for the trigger.
Substring of Interest – the value or word within the entered chat message, usually straight after the activator, that needs to be isolated and manipulated.
Place Range – the range between which the substring of interest is read.
Last edited by a moderator: