Jump to content

[HELP] show player account name instead nickname in server


Recommended Posts

hello guys

i need to show player account name instaead nikname in server or if you can show me a example script that can save player nickname and after login set player nickname to saved nikname

i found this code but this can't change player nickname to account name after login

local counter = 0
local originalName = {}

addEventHandler('onPlayerJoin', root, function()
	local name = getPlayerName(source)
    originalName[source] = name
	setPlayerName(source, "Guest_"..counter)
    counter = counter + 1
end)

addEventHandler('onPlayerLogin', root, function()
    setPlayerName(source, originalName[source])
end)

 

Link to comment

Set account name instead nickname:

addEventHandler('onPlayerLogin', root, function(_,account)
    setPlayerName(source, getAccountName(account))
end)

Save account name on first server login and loading:

addEventHandler('onPlayerLogin', root, function(_,account)
    local accName = getAccountData(account, 'savedName')
	if not accName then
		accName = getAccountName(account)
		setAccountData(account, 'savedName', accName)
	end

	setPlayerName(source, accName)
end)
Edited by nikitafloy
  • Thanks 1
Link to comment
  • Other Languages Moderators
12 minutes ago, nikitafloy said:

Save account name on first server login and loading:


addEventHandler('onPlayerLogin', root, function(_,account)
    local accName = getAccountData(account, 'savedName')
	if not accName then
		accName = getAccountName(account)
		setAccountData(account, 'savedName', accName)
	end

	setPlayerName(source, accName)
end)

Can you please explain this?
why are you saving the account name? you can always use getAccountName

Link to comment
1 hour ago, xLive said:

Can you please explain this?
why are you saving the account name? you can always use getAccountName

"i need ... player account name instaead nikname ... example script that can save player nickname and after login set player nickname to saved nikname"
@sinakh want that

If he want to save nickname (player), not nickname (which was account name and was saved in accountData):

addEventHandler('onPlayerLogin', root, function(_,account)
    local name = getAccountData(account, 'savedName')
	if not name then
		name = getPlayerName(source)
		setAccountData(account, 'savedName', name)
	end

	setPlayerName(source, name)
end)

 

  • Haha 1
Link to comment
  • Other Languages Moderators
Posted (edited)
48 minutes ago, nikitafloy said:

"i need ... player account name instaead nikname ... example script that can save player nickname and after login set player nickname to saved nikname"
@sinakh want that

If he want to save nickname (player), not nickname (which was account name and was saved in accountData):



addEventHandler('onPlayerLogin', root, function(_,account)
    local name = getAccountData(account, 'savedName')
	if not name then
		name = getPlayerName(source)
		setAccountData(account, 'savedName', name)
	end

	setPlayerName(source, name)
end)

 

Oh sorry! i thought you saving the account name not the player name.

Edited by xLive
  • Haha 1
Link to comment
Posted (edited)

thank you so much bro❤️ that worked

do you know how i can prevent random name after player join and login ?

i mean my login panel get username and pasword for login and register but how it can get nick name from player and prevent random nickname?

i dont know usually rp servers how they get nickname and which default script make onjoin random nick name

Edited by sinakh
Link to comment

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...