fairyoggy Posted July 23, 2019 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"
sacr1ficez Posted July 23, 2019 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 Script security
fairyoggy Posted July 23, 2019 Author 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
HassoN Posted July 23, 2019 Posted July 23, 2019 Then use 'setElementData' and change his nick once he changes it again using onPlayerChangeNick * There is No God but Allah discord: HassoN#2709 Visit my wiki profile: https://wiki.multitheftauto.com/wiki/User:Hassan_saad
sacr1ficez Posted July 24, 2019 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) Script security
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