Jump to content

setPlayerName error


IMariukas

Recommended Posts

Posted

Hey so I wanted to do a script that when you write in the editbox something like "nissanskyline-fan" and click "Play" button it would setPlayerName, but I am having one problem that I don't know how to solve it.

Client side:

  
GUICharacter = { 
    Name = {} 
} 
GUIEditor = { 
    button = {}, 
    window = {}, 
    memo = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(356, 233, 648, 303, "Character switch", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
  
        GUICharacter.Name[1] = guiCreateEdit(40, 67, 236, 36, "Lastname_Firstname", false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(284, 67, 70, 36, "Play", false, GUIEditor.window[1]) 
        guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA") 
        GUIEditor.memo[1] = guiCreateMemo(378, 51, 254, 212, "The character switch is just a regular one to play.If you want to change your character name just change it in the edit box.", false, GUIEditor.window[1]) 
        guiMemoSetReadOnly(GUIEditor.memo[1], true)     
        addEventHandler("onClientGUIClick",GUIEditor.button[1],characterButtons)  
    end 
) 
  
addEventHandler("onClientRender", root, 
    function() 
        dxDrawLine(721, 268, 721, 514, tocolor(255, 255, 255, 255), 1, true) 
    end 
) 
  
function characterButtons (button, state, thePlayer, ...) 
if button == "left" and state == "up" then 
local cname = guiGetText(GUICharacter.Name[1]) 
    outputChatBox ("Your character name was changed to: " ..cname, getRootElement(), 244, 164, 96) 
    triggerServerEvent ("change:character:name",getRootElement(), cname) 
    end 
end 

Server side: - I am having an error here!

addEvent("change:character:name",true) 
addEventHandler("change:character:name",root,function(thePlayer, cname)  
        setPlayerName ( thePlayer, cname ) 
        end  
) 

ERROR - WARNING: ped\character_switch_server.lua:3: Bad argument @ 'setPlayerName' [Epected elemet at argument 1, got string 'Firstname_Lastname' ]

  • "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

- http://www.lua.org/about.html

Posted
addEvent("change:character:name",true) 
addEventHandler("change:character:name",root,function(cname) 
        setPlayerName ( client, cname ) 
        end  
) 

CiTLh.png
Posted

Hm, I saw in one script that it used client rather than player or something else, now I understand why and gonna remember this .Thanks TAPL.

  • "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

- http://www.lua.org/about.html

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...