goodiewarrior Posted July 12, 2016 Share Posted July 12, 2016 Hello, I want to shorten a string like, if one string (nickname from player) is too long, shorten it. Like this: -> original string: Nickname -> remove it untill it is only 4 length. -> returns Nick Link to comment
G-Stefan Posted July 12, 2016 Share Posted July 12, 2016 One way is to split it in letters then create a new variable which will contain the four chars in a string The function is here https://wiki.multitheftauto.com/wiki/RemoveHex NOT CREATED BY ME Link to comment
Walid Posted July 12, 2016 Share Posted July 12, 2016 One way is to split it in letters then create a new variable which will contain the four chars in a stringThe function is here https://wiki.multitheftauto.com/wiki/RemoveHex NOT CREATED BY ME I think you need to read his question again. RemoveHex(created By me) : This function is used to remove hex color codes from strings. Hello, I want to shorten a string like, if one string (nickname from player) is too long, shorten it.Like this: -> original string: Nickname -> remove it untill it is only 4 length. -> returns Nick All what you need string.len if (string.len (name) > 4) then -- change the player name end For more information about strings check my tuto Lua Strings Link to comment
John Smith Posted July 12, 2016 Share Posted July 12, 2016 Generally to shorten a string, you should use string.sub e.g: local myString = "Nickname" outputChatBox( string.sub(myString, 1, 4) ) -- Returns 'Nick' Number 1 in there indicates where you want to shorten the string from, in case it's from N ( Nickname ) and Number 4 indicates where to you want to shorten the string, in this case to k ( Nickname ) Link to comment
G-Stefan Posted July 12, 2016 Share Posted July 12, 2016 Wrong function lol I searched for string. Split ) Link to comment
Voltex'GNR Posted July 13, 2016 Share Posted July 13, 2016 One way is to split it in letters then create a new variable which will contain the four chars in a stringThe function is here https://wiki.multitheftauto.com/wiki/RemoveHex NOT CREATED BY ME I think you need to read his question again. RemoveHex(created By me) : This function is used to remove hex color codes from strings. Hello, I want to shorten a string like, if one string (nickname from player) is too long, shorten it.Like this: -> original string: Nickname -> remove it untill it is only 4 length. -> returns Nick All what you need string.len if (string.len (name) > 4) then -- change the player name end For more information about strings check my tuto Lua Strings removeHex, isn't removing the Hexs Today These Days the only Solution to remove hexs, is to remove the Color of The Player When he chats. Link to comment
Walid Posted July 13, 2016 Share Posted July 13, 2016 removeHex, isn't removing the Hexs TodayThese Days the only Solution to remove hexs, is to remove the Color of The Player When he chats. Really lol ? simply to prevent players from using hex codes you can use it on: onPlayerJoin onPlayerChangeNick Link to comment
TorNix~|nR Posted July 13, 2016 Share Posted July 13, 2016 if you need to remove the colors in chat and in server use this addEventHandler ( "onPlayerConnect", getRootElement(),function(nick) if(string.find(nick,"#%x%x%x%x%x%x"))then cancelEvent(true,"Remove your name colors for join the IP") end end) addEventHandler ( "onPlayerConnect", getRootElement(),function(nick) if(string.find(nick,"##%x%x%x%x%x%x"))then cancelEvent(true,"Remove your name colors for join the IP") end end) addEventHandler ( "onPlayerChat", getRootElement(),function(nick) if(string.find(nick,"#%x%x%x%x%x%x"))then kickPlayer(source, getRootElement(), "Do not use colors in Chat!") end end) addEventHandler ( "onPlayerChat", getRootElement(),function(nick) if(string.find(nick,"##%x%x%x%x%x%x"))then kickPlayer(source, getRootElement(), "Do not use colors in Chat!") 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