Page 1 of 1

Simple Change name Command?

Posted: May 10th, 2009, 2:57 pm
by zamundax
How can I insert a simple change name Command
That requires no activation
And evry one can use it

Re: Simple Change name Command?

Posted: May 10th, 2009, 4:55 pm
by Risen
Here's the one I wrote for my map, You'll need JNGP to compile it.
Spoiler:

Code: Select all

scope ChangeName initializer init
 
    globals
        private constant string        TRIGGER     = "-" // The activator E.G. "-name"
        private constant string        COMMAND     = "name" //The Cmd E.G. "-changename"
        private constant integer       LENGTH      = StringLength( TRIGGER ) + StringLength( COMMAND )
        private constant integer       MAX_LENGTH  = 16 // Maximum characters E.G. "-name 123456789123456"
 
        private          string  array pSaveListed
        private          integer       pSaveCount  = 0
    endglobals
 
    private function addSaveListed takes string s returns nothing
        set pSaveCount              = pSaveCount + 1
        set pSaveListed[pSaveCount] = StringCase( s, false )
    endfunction
 
    private function RegisterChatEvent takes trigger t, string s returns nothing
        local integer i = 0
           loop
              exitwhen i > 11
              call TriggerRegisterPlayerChatEvent( t, Player(i), s, false )
              set i = i + 1
          endloop
    endfunction

    private function isSaveListed takes string s returns boolean
        local integer i = 0
 
        set s = StringCase( s, false )
        loop
            set i = i + 1
            exitwhen i > pSaveCount
 
            if s == pSaveListed[i] then
                return true
            endif
        endloop
 
        return false
    endfunction
 
    private function conditions takes nothing returns boolean
        return SubString( GetEventPlayerChatString(), 0, LENGTH ) == TRIGGER + COMMAND
    endfunction
 
    private function actions takes nothing returns nothing
        local string  e = GetEventPlayerChatString()
        local string  s = SubString( e, LENGTH + 1, StringLength( e ) )
        local integer l = StringLength( s )
        local player  p = GetTriggerPlayer()
 
        if l > 0 and l < MAX_LENGTH then
 
            if isSaveListed( s ) then
                call DisplayTextToPlayer( p, 0, 0, "You can't change your name to an Administrator." )
            else
                call SetPlayerName( p, s )
            endif
        endif
        set p = null
    endfunction
 
    //===========================================================================
    private function init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call RegisterChatEvent( t, TRIGGER + COMMAND )
        call TriggerAddCondition( t, Condition( function conditions ) )
        call TriggerAddAction( t, function actions )
        call addSaveListed( "The_Risen_One" )
        set t = null
    endfunction
 
endscope

Re: Simple Change name Command?

Posted: May 11th, 2009, 1:26 pm
by zamundax
Yeah but I am not going to insert it in my map
I want to insert it from JassCraft

Re: Simple Change name Command?

Posted: May 11th, 2009, 8:42 pm
by Risen
There should be a built one in a few cheatpacks.

Re: Simple Change name Command?

Posted: May 13th, 2009, 9:42 pm
by Ken
This should work, probably. Works like "-name x" where x is the new name you want.

Code: Select all

globals
Trigger trg_NameChange = CreateTrigger()
// the rest of your globals
endglobals

function NameChange_Actions takes nothing returns nothing
local string s = GetEventPlayerChatString()
local string s2 = SubString(s, 6, StringLength(s)+1)
if SubString( s, 0, 6) == "-name " then
call SetPlayerName( GetTriggerPlayer(), s2 )
endfunction

// the rest of your functions

function Main takes nothing returns nothing
// function main locals
local integer ii = 0
loop
exitwhen ii > 11
call TriggerRegisterPlayerChatEvent( trg_NameChange, Player(ii), "-name ", false )
endloop
call TriggerAddAction( trg_NameChange, function NameChange_Actions )
// the rest of function main

Re: Simple Change name Command?

Posted: May 14th, 2009, 12:28 pm
by zamundax
Try it.It doesn't work

Re: Simple Change name Command?

Posted: May 14th, 2009, 6:45 pm
by Ken
Ops, no endif.

Just add in an endif above the endfunction. :D

Re: Simple Change name Command?

Posted: May 15th, 2009, 12:34 pm
by ZaXTheAlien
with your code you loop it forever at ii=0

Code: Select all

globals
Trigger trg_NameChange = CreateTrigger()
// the rest of your globals
endglobals

function NameChange_Actions takes nothing returns nothing
local string s = GetEventPlayerChatString()
local string s2 = SubString(s, 6, StringLength(s)+1)
if SubString( s, 0, 6) == "-name " then
call SetPlayerName( GetTriggerPlayer(), s2 )
endif
endfunction

// the rest of your functions

function Main takes nothing returns nothing
// function main locals
local integer ii = 0
loop
exitwhen ii > 11
call TriggerRegisterPlayerChatEvent( trg_NameChange, Player(ii), "-name ", false )
set ii=ii+1
endloop
call TriggerAddAction( trg_NameChange, function NameChange_Actions )
// the rest of function main

fixed