Well name is one of those pre-defined/engine variables that you can't use.
Instead use something else like
this.npc_name.
Also starts() is a string/object function. You call it like this:
I've also included how to extract the player's input using tokenize and substring.
PHP Code:
//#CLIENTSIDE
function onPlayerChats() {
// Checks if player chat starts with "/setname "
// I added the trailing space so: /setname test - will work
// and: /setnametest - will not.
if (player.chat.starts("/setname ")) {
// Substring Method
// The starting position of the player's input is equal to the length of the command.
temp.new_name = player.chat.substring("/setname ".length());
// Tokenize Method
temp.tokens = player.chat.tokenize();
temp.new_name = temp.tokens[1];
// Set NPC's Name
this.npc_name = temp.new_name;
}
}
The difference between substring and tokenize.
string.substring(start_position, [length]) - extracts a section of a string, if you don't specify a length it extracts everything from the starting position.
string.tokenize([token]) - splits the string into multiple tokens based on the token you passed to it. If you don't specify a token it uses a blank space.
For your scenario here it's best to just use substring because then the player won't be required to use quotations.
Quote:
Originally Posted by callimuc
advice
|
I know you're trying to help but I think you might end up causing more harm than good.