Jump to content

outputChatBox different colors?


Cronoss

Recommended Posts

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

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 by Burak5312
  • Like 1
Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...