Cronoss Posted January 28, 2022 Share Posted January 28, 2022 Hello, It's me again, I'm trying to make a RP chat, I want to change the color of player's name and the text "dice:", but the rest of the message keep it white, should I make this code again? I've tried changing the color with Hex codes but I don't get the result I want. I know I can change the Player Nametag with "setPlayerNametagColor" but I want to include the text "dice:", so that doesn't works for me function chatRP (mensaje, tipoMensaje) local jugadores = getElementsByType ("player") local x, y, z = getElementPosition (source) local sourceName = getPlayerName (source) if tipodeMensaje == 0 then for i,v in ipairs (jugadores) do local x2, y2, z2 = getElementPosition (v) if getDistanceBetweenPoints3D (x, y, z, x2, y2, z2) <= distanciaChat then if getElementDimension (source) == getElementDimension (v) then outputChatBox ("[ING] "..sourceName.." dice: "..mensaje..".", v, 255, 255, 255, true) mensaje = mensaje:gsub("^%l", string.upper) end end end cancelEvent () elseif tipodeMensaje == 1 then Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 (edited) actually hex codes will work for you, but before that you can clear the hex codes in the player's name For example, I made the dice text red here, you can use it this way to get what you want, but make sure the last parameter of the outputChatBox is true. local clearedName = string.gsub(sourceName, "#%x%x%x%x%x%x", "") outputChatBox ("[ING] "..clearedName.."#FF0000dice: "..mensaje..".", v, 255, 255, 255, true) Edited January 28, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 28, 2022 Author Share Posted January 28, 2022 It worked, but now I noticed another problem mensaje = mensaje:gsub("^%l", string.upper) This part doesn't execute any command when the resource starts Link to comment
Shady1 Posted January 28, 2022 Share Posted January 28, 2022 mensaje:gsub no such code If you share the whole thing with us, we can better understand and help. Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 I tested this code it converts the first character of the text to uppercase mensaje = "hello" -- hello mensaje = mensaje:gsub("^%l", string.upper) outputDebugString(mensaje) -- Hello 1 Link to comment
Shady1 Posted January 28, 2022 Share Posted January 28, 2022 mensaje = mensaje:gsub("^%l", string.upper) if you share this whole section with us, we can understand what you are trying to do,then Burak can give the necessary answer. 1 Link to comment
Cronoss Posted January 28, 2022 Author Share Posted January 28, 2022 This is the code, I want to pper the first letter when the player says something, I've tried with the example from MTA Wiki: local function doCapitalizing( substring ) -- Upper the first character and leave the rest as they are return substring:sub( 1, 1 ):upper( ) .. substring:sub( 2 ) end function capitalize( text ) -- Sanity check assert( type( text ) == "string", "Bad argument 1 @ capitalize [String expected, got " .. type( text ) .. "]") -- We don't care about the number of words, so return only the first result string.gsub provides return ( { string.gsub( text, "%a+", doCapitalizing ) } )[1] end Editing the rest, of course, but didn't get a result This is the code without the gsub part: function chatRP (mensaje, tipodeMensaje) local jugadores = getElementsByType ("player") local distanciaDelChat = 10 local x, y, z = getElementPosition (source) local sourceName = getPlayerName (source) if tipodeMensaje == 0 then for i,v in ipairs (jugadores) do local x2, y2, z2 = getElementPosition (v) if getDistanceBetweenPoints3D (x, y, z, x2, y2, z2) <= distanciaDelChat then if getElementDimension (source) == getElementDimension (v) then local clearedName = string.gsub(sourceName, "#%x%x%x%x%x%x", "") outputChatBox ("#FFF1C3[ING] "..clearedName.." dice: #FFFFFF" ..mensaje..".", v, 255, 255, 255, true) end end end cancelEvent () Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 (edited) your code already has mensaje:gsub part doing this job mensaje = mensaje:gsub("^%l", string.upper) you don't need to do anything else Edited January 28, 2022 by Burak5312 1 Link to comment
Cronoss Posted January 28, 2022 Author Share Posted January 28, 2022 I put the gsub part above the outputchatbox and now it works thank you both for the help, saludos 1 Link to comment
βurak Posted January 28, 2022 Share Posted January 28, 2022 (edited) no problem it was my pleasure Edited January 28, 2022 by Burak5312 1 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