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

Name Changing Tutorial (Strings Explained) [Reviewed: Ralle]

Level 5
Joined
Dec 10, 2007
Messages
65
first of all, you need a prompt for the user.

  • prompt
    • Events:
      • Time - Elapsed game time is 5 seconds
    • Conditions:
    • Actions:
      • Game - Display to (All players) the text: Type "-name " + what you would like to change your name to.
This just tells the user how to use the name changer.

Next thing to do is to store some variables of type STRING, now you could use an STRING ARRAY to hold all the names of each player. Depending on the max players in your map, you would set the string variable to that number, lets say for our case we have 8 players in our map.

So, click on the X variables and add a new variable Called NameStore and pick the variable type of STRING. Select the Array checkbox and make it size 8.

We also need a variable to store the size of the string that the user enters into the name changer, so make a variable called NameStore and pick type Integer and select Array size 8.

Now we got the prompt and a variable to store the names, now all we do is create the name changer trigger. I will first write the entire code, then explain what each part does afterwards. This is for the example for just player 1 (red), you could just copy and paste for each player and change the nessesary parts to it or you can get tricky and use for loops ect, but for this tutorial i will only do it for player 1:

  • nameChanger
    • Events:
      • Player 1 (Red) types a chat message containing -name as A substring
    • Conditions:
    • Actions:
      • Set NameSize[1] = (Length of (Entered chat string))
      • Set NameStore[1] = (Entered chat string)
      • Set NameStore[1] = (Substring(NameStore[1],7,NameSize[1]))
      • Player - Set name of Player 1 (Red) to NameStore[1]
So for our event, player 1 types "-name ........." , so this ignores the rest of the text of what the player typed and fires this trigger. This is called a substring of a String, its just a small piece of the String that was typed.

Our actions were to get the Length of the string typed. This just returns a integer value of how many characters (including spaces) in the chat message typed. The nameStore just stores the whole string, then we use nameStore again to get the substring that we want, in our case the stuff after "-name ". To do this, we just use substring(STRING,startingCharNumber,SizeOfString).
In our case "-name " takes up 6 chars (including the last space too). So we use 7 for the startingCharNumber then just put in our variable for the size of string.

Now we have our string all we need to do is set the players name to that string.

Its as simple as that, hope this helps understanding strings. If you have any more questions just post it up and il try to answer it. :wthumbsup:
 
Level 5
Joined
May 23, 2008
Messages
148
Arrays start to count at 0, not at 1. If you have an array of 8, it goes from 0 to 7.

In a tutorial, it's best to simply make 1 trigger for all players. It's not "that" tricky.

That's true, but in WC3 you can declare an array of size, lets say, 5, and you can still store/read data in/from any fields you want [423], [5923]. The maximum size of an array is 8192, so you can refer to any field from 0 to 8191.
 
Last edited by a moderator:
Level 40
Joined
Dec 14, 2005
Messages
10,532
well if you dont use verables how would you remove -name from the players name?
Inline the substring?

That's true, but in WC3 you can declare an array of size, lets say, 5, and you can still store/read data in/from any fields you want [423], [5923]. The maximum size of an array is 8192, so you can refer to any field from 0 to 8191.
8191 apparently isn't saved in Save Game.
 
Level 2
Joined
May 20, 2008
Messages
14
ok i got you thanks final code looked like this
Defentally alot eayser then the said method above

  • Events
    • Player - Player 1 (Red) types a chat message containing -name as A substring
  • Conditions
  • Actions
    • Player - Set name of Player 1 (Red) to (Substring((Entered chat string), 7, 40))
 
Last edited:
Top