General > Developers Corner

Custom Echo Text Colors

(1/2) > >>

Darkblizzard:
Hello,
I was wondering if I wanted to do a custom string with color such as for the format between else and end. Where or how could I make a certain text from the formal string be colored? Majority of the Garry's Mod Functions are based on adding the text with the color, but here it just needs the color. Just trying to make the text "[Admin Request]" color green, and that's it.



--- Code: ---function ulx.asay( calling_ply, message )
local format
local me = "/me "
if message:sub( 1, me:len() ) == me then
format = "(ADMINS) *** #P #s"
message = message:sub( me:len() + 1 )
else
format = "[Admin Request] #P: #s"    --I WANT TO CHANGE THIS
end

local players = player.GetAll()
for i=#players, 1, -1 do
local v = players[ i ]
if not ULib.ucl.query( v, seeasayAccess ) and v ~= calling_ply then -- Calling player always gets to see the echo
table.remove( players, i )
end
end

ulx.fancyLog( players, format, calling_ply, message )
end
--- End code ---

Timmy:
The ulx.fancyLog function takes care of text coloring for you. You can specify the colors in XGUI ("Settings" tab > "Server" tab > Select "ULX Command/Event Echoes" option).



You can use ULib.tsayColor if you want to use custom colors for a specific ULX command. Note that this function does not accept a formatted string like ulx.fancyLog or ulx.fancyLogAdmin. You have to format the string yourself.

--- Code: ---ULib.tsayColor( players, true, Color( 0, 255, 0), "Timmy typed a message" )
--- End code ---

You will also have to log the event manually with ulx.logString.

--- Code: ---ulx.logString( "Timmy typed a message", true )
--- End code ---

Darkblizzard:
Is there no simpler way? I just want to color one piece of text in the string.

Timmy:
I’m not aware of a simpler way.

The underlying logic that applies text coloring is abstracted away.

JamminR:
There is no easy way to make commands that use ulx.fancyLog have partial color changes.
The ulx.fancyLog command colors the entire string of text using ULib.tsayColor

Navigation

[0] Message Index

[#] Next page

Go to full version