Jump to content

[HELP] show player account name instead nickname in server


SinaAmp

Recommended Posts

Posted

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)

 

Posted (edited)

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
  • Scripting Moderators
Posted
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

Posted
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
  • Scripting 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
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
Posted (edited)

@sinakh i dont know ur mta mod
U need to find script which use 'setPlayerName' function and remove this

Example:

setPlayerName(player, 'nickname' .. math.random(99999))

 

Edited by nikitafloy

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