onPlayerChangeNick | Multi Theft Auto: Wiki Skip to content

onPlayerChangeNick

Client-side
Server-side
Shared

This event is triggered when a player changes his nickname.

Parameters

string oldNick, string newNick, bool changedByUser
  • oldNick: the nickname the player had before.
  • newNick: the new nickname of the player.
  • changedByUser: a boolean representing whether the name was changed using setPlayerName or by the user.

Source

element: The source of this event is the player that changed his nick

Canceling

Cancelling this event depends on how it is called, if it is called by the scripting event then it is NOT cancelable. If it is called from the /nick command it IS cancelable. If this event is cancelled and can be cancelled then the name will not change.

Code Examples

server
function nickChangeHandler(oldNick, newNick)
-- check if there's account with newNick as username
if getAccount(newNick) then
outputChatBox("Sorry, there already exists an account with your new nickname as username.", source, 0, 255, 0)
outputChatBox("Please choose another one.", source, 0, 255, 0)
-- cancel the event to prevent the nick from being changed
cancelEvent()
end
end
-- add an event handler
addEventHandler("onPlayerChangeNick", root, nickChangeHandler)

See Also