- Joined
- Dec 10, 2007
- Messages
- 65
first of all, you need a prompt for the user.
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:
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.
-
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.
-
Events:
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]
-
Events:
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.