[How to] Use colors in lua scripting


#1

Hey guys today i will post a good thing for lua coders want to make colored message.
(not with ^1…)

Colors:
~r~ = Red
~b~ = Blue
~g~ = Green
~y~ = Yellow
~p~ = Purple
~c~ = Grey
~m~ = Dark Grey
~u~ = Black
~o~ = Orange

Special:
~n~ = New line
~s~ = Reset Color
~h~ = Bold text

For notification:
∑ = Rockstar Icon
÷ = Rockstar Icon
¦ = Rockstar Verified Icon


Want to learn Lua
Death drawText - requesting dev assistance
Help with Tornado script
Color codes for ~ colors
#2

Is it possible to change the font size as well? (I am not familiar with lua)


#3

@DevoutRain2500 Currently in the chat, no. Or you can rewrite the chat resource.


#4

Awesome, here’s an example:
Text colors example
Input string: ∑÷¦~r~r ~b~b ~g~g ~y~y ~p~p ~c~gr ~m~d gr ~u~bl ~o~or ~s~re ~n~nl ~h~Bold

For some reason, the ÷ doesn’t seem to be doing anything special, other than looking slightly bold.


#6

^1 hi my name is crystal and I like chicken


#7

How can I assign colors in the “User and Admin” lines?
I tried to put (~ r ~, ~ s ~, ~ u ~) colors but they did not work.

– Hooking into chat messages to insert admin tags.
AddEventHandler(‘chatMessageEntered’, function(name, color, message)
CancelEvent()

local tag = "^whiteUser ^black| ^gray"

if(Users[source] ~= nil)then
	if(tonumber(Users[source].admin) > 0)then
		tag = "^redAdmin ^black| ^gray"
	end
end

TriggerEvent('chatMessage', source, tag .. GetPlayerName(source), message)

TriggerClientEvent('chatMessage', -1, tag .. GetPlayerName(source), {0, 0x99, 255}, message)

print(GetPlayerName(source) .. ': ' .. message)

end)


#9

Test with color codes ^1 - ^9, only black, white and gray do not work.


#10

Does anyone know what codes work with white, black and gray in .lua script?


#11

^0 is white. Not sure of the others.


#12

0 is based off the message color. So 0 can be red if your rgb is 255,0,0


#13

If indeed I have tried ^0 but it does not work.


#14

My bad then. Didn’t know that. I never change the color aside from using the ^1-9


#15

It’s all good. Just thought others should know. I spent about 3 hours trying to figure it out only to find out that 0 did that.


#16

Set the RGB to the gray color you want then use ^0


#17

I configured it but now everything is gray. What codes do I use for black color and white color?

local tag = "^whiteUser ^black| ^"

if(Users[source] ~= nil)then
	if(tonumber(Users[source].admin) > 0)then
		tag = "^1Admin ^black| ^"
	end
end

TriggerEvent('chatMessage', source, tag .. GetPlayerName(source), message)

TriggerClientEvent('chatMessage', -1, tag .. GetPlayerName(source), {128, 128, 128}, message)

print(GetPlayerName(source) .. ': ' .. message)

end)


#18

Use ^0 and change the color to the color you want. ^0 goes to the RGB color you set when sending the message


#19

I’m sorry, I’m new to this. You can configure the lines of “User” and “Admin” as an example please.

local tag = "^whiteUser ^black| ^gray"

if(Users[source] ~= nil)then
	if(tonumber(Users[source].admin) > 0)then
		tag = "^redAdmin ^black| ^gray"
	end
end

TriggerEvent('chatMessage', source, tag .. GetPlayerName(source), message)

TriggerClientEvent('chatMessage', -1, tag .. GetPlayerName(source), {0, 0x99, 255}, message)

print(GetPlayerName(source) .. ': ' .. message)

end)


#20

Are these colors correct?

^1 = red
^2 = green
^3 = yellow
^4 = blue
^5 = CYAN
^6 = Pink
^7 = white
^8 is a color that changes depending what level you are on.
American maps = Dark Green
Russian maps = Dark red/marroon
British maps = Dark Blue
^9 = gray
^0= black
^c = Blandishbeige


#21

^0 is based on the RGB of the message sent

riggerClientEvent(‘chatMessage’, -1, tag … GetPlayerName(source), {0,0,0} , message) – Would be white


#22

Ok bro I got it thanks. But it seems to me that RGB {0,0,0} is black, not white