Mischief-1 Posted April 15 Share Posted April 15 Hi everyone, I would like to share this revived script for removing hex in players' nickname. Spoiler ---- //// server //// ------ -- Check if a nick is too long addEventHandler( "onPlayerChangeNick", root, function ( oldNick, newNick ) if (string.find(getPlayerName(source),"#%x%x%x%x%x%x")) or (string.find(getPlayerName(source),"#")) then outputChatBox("Colorname detected, its been removed.", source, 211, 211, 211,true) cancelEvent() else if ( string.len ( newNick ) < 4 ) then cancelEvent() outputChatBox("Your new nickname is to short, its changed back to #880808"..oldNick..".", source, 211, 211, 211,true) setPlayerName ( source, oldNick ) else if ( string.len ( newNick ) > 15 ) then cancelEvent() outputChatBox("Your new nickname is to long, its changed back to #880808"..oldNick..".", source, 211, 211, 211,true) setPlayerName ( source, oldNick ) else if (string.find(getPlayerName(source),"#%x%x%x%x%x%x")) or (string.find(getPlayerName(source),"#")) then outputChatBox("Colorname detected, its been removed.", source, 211, 211, 211,true) else outputChatBox('#880808' .. oldNick ..'#D3D3D3 changed his nickname to #880808' .. newNick, getRootElement(), 255, 255, 255, true) end end end end end ) ----///// anti color code & long name /////----- -- Check the nick on connect addEventHandler ( "onPlayerConnect", root, function ( playerNick, playerIP, playerUsername, playerSerial, playerVersionNumber ) if ( playerNick == "Player" ) or ( playerNick == "player" ) then cancelEvent( true, "The nickname \"Player\" is not allowed, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) elseif ( string.len ( playerNick ) > 18 ) then cancelEvent( true, "Your nickname is to long, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) elseif ( string.len ( playerNick ) < 4 ) then cancelEvent( true, "Your nickname is to short, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) else if (string.find(playerNick,"#%x%x%x%x%x%x")) or (string.find(playerNick,"#")) then cancelEvent( true, "Using hex or color in your name is not allowed. please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) end end end ) function deletecc() for k, v in ipairs (getElementsByType("player")) do local name = getPlayerName(v) if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(v,name) if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(v,name) cancelEvent() end end end end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),deletecc) function removeCC(oldNick,newNickname) local name = getPlayerName(source) if newNickname then name = newNickname end if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(source,name) if (newNickname) then if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(source,name) if (newNickname) then cancelEvent() end end end end end addEventHandler("onPlayerJoin",getRootElement(),removeCC) addEventHandler("onPlayerChangeNick",getRootElement(),removeCC) PS: I do not own this, credits go to where credit is due. I modified it and added conditions to make sure that no hex will go thru. as currently the script available in community does not work for people who uses two hexes in their name example /nick #FFA500#FFA500Test as it will only remove one. Current problem I'm trying to solve is that when changing nickname, it displays twice because the user changes the nickname twice so want to remove that one. See pic as reference. Thanks! Feel free to comment as well to help improve the code https://imgur.com/a/6MwJmst Link to comment
Mischief-1 Posted April 15 Author Share Posted April 15 4 hours ago, Mischief-1 said: Hi everyone, I would like to share this revived script for removing hex in players' nickname. Reveal hidden contents ---- //// server //// ------ -- Check if a nick is too long addEventHandler( "onPlayerChangeNick", root, function ( oldNick, newNick ) if (string.find(getPlayerName(source),"#%x%x%x%x%x%x")) or (string.find(getPlayerName(source),"#")) then outputChatBox("Colorname detected, its been removed.", source, 211, 211, 211,true) cancelEvent() else if ( string.len ( newNick ) < 4 ) then cancelEvent() outputChatBox("Your new nickname is to short, its changed back to #880808"..oldNick..".", source, 211, 211, 211,true) setPlayerName ( source, oldNick ) else if ( string.len ( newNick ) > 15 ) then cancelEvent() outputChatBox("Your new nickname is to long, its changed back to #880808"..oldNick..".", source, 211, 211, 211,true) setPlayerName ( source, oldNick ) else if (string.find(getPlayerName(source),"#%x%x%x%x%x%x")) or (string.find(getPlayerName(source),"#")) then outputChatBox("Colorname detected, its been removed.", source, 211, 211, 211,true) else outputChatBox('#880808' .. oldNick ..'#D3D3D3 changed his nickname to #880808' .. newNick, getRootElement(), 255, 255, 255, true) end end end end end ) ----///// anti color code & long name /////----- -- Check the nick on connect addEventHandler ( "onPlayerConnect", root, function ( playerNick, playerIP, playerUsername, playerSerial, playerVersionNumber ) if ( playerNick == "Player" ) or ( playerNick == "player" ) then cancelEvent( true, "The nickname \"Player\" is not allowed, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) elseif ( string.len ( playerNick ) > 18 ) then cancelEvent( true, "Your nickname is to long, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) elseif ( string.len ( playerNick ) < 4 ) then cancelEvent( true, "Your nickname is to short, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) else if (string.find(playerNick,"#%x%x%x%x%x%x")) or (string.find(playerNick,"#")) then cancelEvent( true, "Using hex or color in your name is not allowed. please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) end end end ) function deletecc() for k, v in ipairs (getElementsByType("player")) do local name = getPlayerName(v) if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(v,name) if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(v,name) cancelEvent() end end end end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),deletecc) function removeCC(oldNick,newNickname) local name = getPlayerName(source) if newNickname then name = newNickname end if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(source,name) if (newNickname) then if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(source,name) if (newNickname) then cancelEvent() end end end end end addEventHandler("onPlayerJoin",getRootElement(),removeCC) addEventHandler("onPlayerChangeNick",getRootElement(),removeCC) PS: I do not own this, credits go to where credit is due. I modified it and added conditions to make sure that no hex will go thru. as currently the script available in community does not work for people who uses two hexes in their name example /nick #FFA500#FFA500Test as it will only remove one. Current problem I'm trying to solve is that when changing nickname, it displays twice because the user changes the nickname twice so want to remove that one. See pic as reference. Thanks! Feel free to comment as well to help improve the code https://imgur.com/a/6MwJmst Seemed like I added extra lines that were not useful.. Here is the revised code. Spoiler -- Check if a nick is too long addEventHandler( "onPlayerChangeNick", root, function ( oldNick, newNick ) if (string.find(newNick,"#%x%x%x%x%x%x")) or (string.find(newNick,"#")) then cancelEvent() outputChatBox("#880808[Warning!] #D3D3D3Your new nickname has a hex value.", source, 211, 211, 211,true) elseif ( string.len ( newNick ) < 4 ) or ( string.len ( newNick ) > 15 ) then cancelEvent() outputChatBox("#880808[Warning!] #D3D3D3Your new nickname is either too short, too long.", source, 211, 211, 211,true) setPlayerName ( source, oldNick ) else outputChatBox('#880808' .. oldNick ..'#D3D3D3 changed his nickname to #880808' .. newNick, getRootElement(), 255, 255, 255, true) end end) ----///// anti color code & long name /////----- -- Check the nick on connect addEventHandler ( "onPlayerConnect", root, function ( playerNick, playerIP, playerUsername, playerSerial, playerVersionNumber ) if ( playerNick == "Player" ) or ( playerNick == "player" ) then cancelEvent( true, "The nickname \"Player\" is not allowed, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) elseif ( string.len ( playerNick ) > 18 ) then cancelEvent( true, "Your nickname is to long, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) elseif ( string.len ( playerNick ) < 4 ) then cancelEvent( true, "Your nickname is to short, please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) elseif (string.find(playerNick,"#%x%x%x%x%x%x")) or (string.find(playerNick,"#")) then cancelEvent( true, "Using hex or color in your name is not allowed. please change it to something else. You can change your nick in Settings menu Multiplayer tab." ) end end ) 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