fairyoggy Posted July 23, 2019 Share Posted July 23, 2019 How to forcibly change the nickname of the player? For example, a player logged on to the server and the nickname is changed to "Alex_Hunter" Link to comment
Scripting Moderators ds1-e Posted July 23, 2019 Scripting Moderators Share Posted July 23, 2019 23 minutes ago, slapz0r said: How to forcibly change the nickname of the player? For example, a player logged on to the server and the nickname is changed to "Alex_Hunter" function onPlayerLogin() setPlayerName(source, "Alex_Hunter") end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) Server-side. Quote Note that any change made to a players name with this function is not saved in their settings so the name change only lasts till they disconnect. 1 Link to comment
fairyoggy Posted July 23, 2019 Author Share Posted July 23, 2019 17 hours ago, majqq said: function onPlayerLogin() setPlayerName(source, "Alex_Hunter") end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) Server-side. but how to do if a player changes his nickname; he is again assigned a nickname "Alex_Hunter" ? I mean, if a player changes to some other nickname, he will again give the name Alex_Hunter Link to comment
HassoN Posted July 23, 2019 Share Posted July 23, 2019 Then use 'setElementData' and change his nick once he changes it again using onPlayerChangeNick Link to comment
Scripting Moderators ds1-e Posted July 24, 2019 Scripting Moderators Share Posted July 24, 2019 10 hours ago, slapz0r said: but how to do if a player changes his nickname; he is again assigned a nickname "Alex_Hunter" ? I mean, if a player changes to some other nickname, he will again give the name Alex_Hunter About solution above. Don't use elementdata for such a thing, or even better, don't use it at all. Use tables - they are fast and efficient. local player_names = {} -- Assign name to player function onPlayerLogin() setPlayerName(source, "Alex_Hunter") player_names[source] = "Alex_Hunter" end addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) -- Avoid any changes function onPlayerChangeNick(old, new, byuser) if player_names[source] then if old ~= new then setPlayerName(source, player_names[source]) -- you might replace it with cancelEvent(), it depends, read "Cancel event" note on https://wiki.multitheftauto.com/wiki/OnPlayerChangeNick end end end addEventHandler("onPlayerChangeNick", getRootElement(), onPlayerChangeNick) -- Clear data from table, after player quit function onPlayerQuit() if player_names[source] then player_names[source] = nil end end addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now