OnPlayerChangeNick: Difference between revisions
Jump to navigation
Jump to search
m (Added proper issues section) |
Zangomangu (talk | contribs) (Removed old issues) |
||
(17 intermediate revisions by 7 users not shown) | |||
Line 5: | Line 5: | ||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string oldNick, string newNick | string oldNick, string newNick, bool changedByUser | ||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''oldNick:''' the nickname the player had before. | *'''oldNick:''' the nickname the [[player]] had before. | ||
*'''newNick:''' the new nickname of the player. | *'''newNick:''' the new nickname of the player. | ||
{{New items|3.0154|1.5.3| | |||
*'''changedByUser:''' a [[boolean]] representing whether the name was changed using [[setPlayerName]] or by the user. | |||
|9765}} | |||
==Source== | ==Source== | ||
The source of this event is the player that changed his nick | The [[event system#Event source|source]] of this event is the player that changed his nick | ||
==Cancel effect== | ==Cancel effect== | ||
Line 17: | Line 20: | ||
==Example== | ==Example== | ||
<section name="Server Example 1" class="server" show="true"> | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function nickChangeHandler(oldNick, newNick) | function nickChangeHandler(oldNick, newNick) | ||
Line 28: | Line 32: | ||
end | end | ||
-- add an event handler | -- add an event handler | ||
addEventHandler("onPlayerChangeNick", | addEventHandler("onPlayerChangeNick", root, nickChangeHandler) | ||
</syntaxhighlight> | </syntaxhighlight></section> | ||
This | {{New items|3.0154|1.5.3| | ||
<section name="Server Example 2" class="server" show="true"> | |||
This function checks if the nickname of a player was changed by a script, if so, a message is shown in the server logs. | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function | function wasNickChangedByUser(oldNick, newNick, changedByUser) | ||
if (changedByUser == false) then -- check if the nickname was not changed by the user | |||
outputServerLog("Player "..oldNick.."'s name was changed to "..newNick.." by a script") -- output to the server's logs | |||
end | |||
end | end | ||
addEventHandler("onPlayerChangeNick", | addEventHandler("onPlayerChangeNick", root, wasNickChangedByUser) -- add an event handler | ||
</syntaxhighlight> | </syntaxhighlight></section>|9765}} | ||
{{See also/Server event|Player events}} | |||
{{ | |||
}} | |||
[[ru:onPlayerChangeNick]] |
Latest revision as of 10:40, 30 January 2022
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
The source of this event is the player that changed his nick
Cancel effect
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.
Example
Click to collapse [-]
Server Example 1function 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)
Click to collapse [-]
Server Example 2This function checks if the nickname of a player was changed by a script, if so, a message is shown in the server logs.
function wasNickChangedByUser(oldNick, newNick, changedByUser) if (changedByUser == false) then -- check if the nickname was not changed by the user outputServerLog("Player "..oldNick.."'s name was changed to "..newNick.." by a script") -- output to the server's logs end end addEventHandler("onPlayerChangeNick", root, wasNickChangedByUser) -- add an event handler
See Also
Player events
- onPlayerACInfo
- onPlayerBan
- onPlayerChangeNick
- onPlayerChat
- onPlayerClick
- onPlayerCommand
- onPlayerConnect
- onPlayerContact
- onPlayerDamage
- onPlayerJoin
- onPlayerLogin
- onPlayerLogout
- onPlayerMarkerHit
- onPlayerMarkerLeave
- onPlayerModInfo
- onPlayerMute
- onPlayerNetworkStatus
- onPlayerPickupHit
- onPlayerPickupLeave
- onPlayerPickupUse
- onPlayerPrivateMessage
- onPlayerQuit
- onPlayerScreenShot
- onPlayerSpawn
- onPlayerStealthKill
- onPlayerTarget
- onPlayerUnmute
- onPlayerVehicleEnter
- onPlayerVehicleExit
- onPlayerVoiceStart
- onPlayerVoiceStop
- onPlayerWasted
- onPlayerWeaponFire
- onPlayerWeaponSwitch