HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Quick Help

01-20-2008, 10:47 PM#1
Joker
How do you allow the players to change their name in game?
I know you have to do something with the substring, but I can't do it right.
01-21-2008, 03:33 AM#2
Zandose
GUI or vJASS, your choice. I suggest vJASS, but you'll need to have the NewGen World Editor. The GUI one has leaks; it's just the way GUI is.

Collapse JASS:
scope NameChange

globals
    private constant boolean MAX_LENGTH_CHECK = true //Use true or false (Case-Sensitive)
    private constant integer MAX_LENGTH = 10 //The limit for how long a name can be
endglobals

private function Actions takes nothing returns nothing
    local string s = GetEventPlayerChatString()
    local integer l = StringLength(s)
    local string sub
    local player p = GetTriggerPlayer()
    set s = null //Although is can never be removed I can still set it to null saving a little space
    if l >= 6 + MAX_LENGTH and MAX_LENGTH_CHECK then //Check to make sure the number of characters isn't over MAX_LENGTH (default: 10)
        call DisplayTextToPlayer(p, 0, 0, "Error: Name to long. Limit is " + I2S(MAX_LENGTH) + " characters.")
        return //Stop the trigger
    endif
    set sub = SubString(s, 6, l)
    call SetPlayerName(p, sub)
    call DisplayTextToPlayer(p, 0, 0, "Your name has been changed to: " + sub)
    set sub = null
endfunction

public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerChatEvent(trig, Player(i), "-name", false )
        set i = i + 1
        exitwhen i == 12
    endloop
    call TriggerAddAction(trig, function Actions)
endfunction

endscope
Trigger:
NameChangeGUI
Collapse Events
Player - Player 1 (Red) types a chat message containing -name as A substring
Player - Player 2 (Blue) types a chat message containing -name as A substring
Player - Player 3 (Teal) types a chat message containing -name as A substring
Player - Player 4 (Purple) types a chat message containing -name as A substring
Player - Player 5 (Yellow) types a chat message containing -name as A substring
Player - Player 6 (Orange) types a chat message containing -name as A substring
Player - Player 7 (Green) types a chat message containing -name as A substring
Player - Player 8 (Pink) types a chat message containing -name as A substring
Player - Player 9 (Gray) types a chat message containing -name as A substring
Player - Player 10 (Light Blue) types a chat message containing -name as A substring
Player - Player 11 (Dark Green) types a chat message containing -name as A substring
Player - Player 12 (Brown) types a chat message containing -name as A substring
Conditions
Collapse Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Length of (Substring((Entered chat string), 7, (Length of (Entered chat string))))) Greater than or equal to 10
Collapse Then - Actions
Game - Display to (Player group((Triggering player))) the text: Error: Name too lon...
Collapse Else - Actions
Player - Set name of (Triggering player) to (Substring((Entered chat string), 7, (Length of (Entered chat string))))
Game - Display to (Player group((Triggering player))) the text: (Your name has been changed to: + (Substring((Entered chat string), 6, (Length of (Entered chat string)))))
Attached Files
File type: w3xNameChange.w3x (13.3 KB)
01-21-2008, 03:55 AM#3
Tide-Arc Ephemera
Your GUI is messed, it should be "as a substring", not an exact match.
01-21-2008, 05:14 AM#4
Zandose
Quote:
Originally Posted by Tide-Arc Ephemera
Your GUI is messed, it should be "as a substring", not an exact match.
Oh. I wasn't really trying hard when I made that. I don't like GUI anymore

Edit: Ok I've updated both triggers.
01-21-2008, 05:21 AM#5
Joker
Your GUI script wasn't necessary anyway. Thx :]
01-21-2008, 05:34 AM#6
Zandose
Quote:
Originally Posted by Joker
Your GUI script wasn't necessary anyway. Thx :]
I just assumed you were using GUI by the "sound" of the question.

By the way, I forgot to check if the trigger worked before posting it, so don't blame me :) I'll fix it if it doesn't.

That +rep message wasn't very funny...