• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

About Strings

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
A player just type -Name and what the thier name to be after.

eg. "-Name TheCakeIsALie"

JASS:
library NameChange initializer init

globals
    private string EnteredString
    private string NameString
endglobals

private function ChangeName takes nothing returns nothing
    local player Play = GetTriggerPlayer()
    
    set EnteredString = GetEventPlayerChatString()
    set NameString = SubString(EnteredString,6,StringLength(EnteredString))
    
    call SetPlayerName(Play,NameString)
    
    //If you have a dialog or multiboard you should update those
endfunction

private function init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    local integer index = 0
    
    loop
        exitwhen index >= bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerChatEvent(Trig,Player(Index),"-Name ",false)
        set index = index + 1
    endloop
    
    call TriggerAddAction(Trig,function ChangeName)
endfunction

endlibrary

If you dont know how substrings work ill will tell you

JASS:
native SubString takes string source, integer start, integer end returns string

the parameter start sould be 6 since "-name " is 6 charters. The end parameter in this case should be at the end of the entered message.
So if we type "-Name TheCakeIsALie" it will only get "TheCakeIsALie" and set that as a name
 
Ok, I want to type a name, any name, then set the player name to that string that was typed.

That was my triggers
  • Change Player Name
    • Events
      • Player - Player 1 (Red) types a chat message containing A as A substring
      • Player - Player 1 (Red) types a chat message containing B as A substring
      • Player - Player 1 (Red) types a chat message containing C as A substring
      • Player - Player 1 (Red) types a chat message containing D as A substring
      • Player - Player 1 (Red) types a chat message containing E as A substring
      • Player - Player 1 (Red) types a chat message containing F as A substring
      • Player - Player 1 (Red) types a chat message containing G as A substring
      • Player - Player 1 (Red) types a chat message containing H as A substring
      • Player - Player 1 (Red) types a chat message containing I as A substring
      • Player - Player 1 (Red) types a chat message containing J as A substring
      • Player - Player 1 (Red) types a chat message containing K as A substring
      • Player - Player 1 (Red) types a chat message containing L as A substring
      • Player - Player 1 (Red) types a chat message containing M as A substring
      • Player - Player 1 (Red) types a chat message containing N as A substring
      • Player - Player 1 (Red) types a chat message containing O as A substring
      • Player - Player 1 (Red) types a chat message containing P as A substring
      • Player - Player 1 (Red) types a chat message containing Q as A substring
      • Player - Player 1 (Red) types a chat message containing R as A substring
      • Player - Player 1 (Red) types a chat message containing S as A substring
      • Player - Player 1 (Red) types a chat message containing T as A substring
      • Player - Player 1 (Red) types a chat message containing U as A substring
      • Player - Player 1 (Red) types a chat message containing V as A substring
      • Player - Player 1 (Red) types a chat message containing W as A substring
      • Player - Player 1 (Red) types a chat message containing X as A substring
      • Player - Player 1 (Red) types a chat message containing Y as A substring
      • Player - Player 1 (Red) types a chat message containing Z as A substring
    • Conditions
    • Actions
      • Player - Set name of Player 1 (Red) to (Entered chat string)
But EoW told me that it was wrong, I don't know how to set a player name except by this way, other ways I don't understand except for the trigger posted in the thread http://www.hiveworkshop.com/forums/triggers-and-scripts-269/halp-w-camera-commands-138113/ by EoW, that I understand.
 
  • Change Playername
    • Events
      • Player - Player 1 (Red) types a chat message containing -setname as A substring
      • Player - Player 2 (Blue) types a chat message containing -setname as A substring
      • Player - Player 3 (Teal) types a chat message containing -setname as A substring
      • Player - Player 4 (Purple) types a chat message containing -setname as A substring
      • Player - Player 5 (Yellow) types a chat message containing -setname as A substring
      • Player - Player 6 (Orange) types a chat message containing -setname as A substring
      • Player - Player 7 (Green) types a chat message containing -setname as A substring
      • Player - Player 8 (Pink) types a chat message containing -setname as A substring
    • Conditions
      • (Substring((Entered chat string), 1, 9)) Equal to -setname
    • Actions
      • Game - Display to (All players) the text: (PlayerName[(Player number of (Triggering player))] + ( changed his/her name to + (Substring((Entered chat string), 10, 20))))
      • Player - Set name of (Triggering player) to (Substring((Entered chat string), 10, 20))
with this code, you can change your playername, if you type -setname + yourname.
the substring 10,20 means, that you can type max 10 letters
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
Yes your code does that, but your code has 1 flaw which Amigurumi covers perfectly,
If i would type "wtflolhax-Name lol i owned your code" then it would not set my name properly, and if i would try to teach someone in-game how to set your name, and i type "You just have to type '-Name YourName' and then you are done! =D" then it would bug.
That condition covers that.
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
library NameChange initializer init

globals
    private string EnteredString
    private string NameString
endglobals

private function ChangeName takes nothing returns nothing
    local player Play = GetTriggerPlayer()
    
    set EnteredString = GetEventPlayerChatString()
    set NameString = SubString(EnteredString,6,StringLength(EnteredString))
    
    call SetPlayerName(Play,NameString)
    
    //If you have a dialog or multiboard you should update those
endfunction

private function Conds takes nothing returns boolean
    return SubString(GetEventPlayerChatString(),1,6) == "-Name "
endfunction

private function init takes nothing returns nothing
    local trigger Trig = CreateTrigger()
    local integer index = 0
    
    loop
        exitwhen index >= bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerChatEvent(Trig,Player(Index),"-Name ",false)
        set index = index + 1
    endloop
    
    call TriggerAddCodition(Trig,Condition(function Conds))
    call TriggerAddAction(Trig,function ChangeName)
endfunction

endlibrary

That should do it :)
 
Status
Not open for further replies.
Top