Ulysses

General => Developers Corner => Topic started by: Darkblizzard on July 14, 2018, 01:17:44 PM

Title: Custom Echo Text Colors
Post by: Darkblizzard on July 14, 2018, 01:17:44 PM
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: [Select]
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
Title: Re: Custom Echo Text Colors
Post by: Timmy on July 14, 2018, 02:43:41 PM
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).

(https://timmy.github.io/images/xgui-command-event-echoes.png)

You can use ULib.tsayColor (https://ulyssesmod.net/docs/files/lua/ulib/shared/messages-lua.html#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: [Select]
ULib.tsayColor( players, true, Color( 0, 255, 0), "Timmy typed a message" )
You will also have to log the event manually with ulx.logString (https://github.com/TeamUlysses/ulx/blob/v3.73/lua/ulx/log.lua#L138).
Code: [Select]
ulx.logString( "Timmy typed a message", true )
Title: Re: Custom Echo Text Colors
Post by: Darkblizzard on July 14, 2018, 02:58:24 PM
Is there no simpler way? I just want to color one piece of text in the string.
Title: Re: Custom Echo Text Colors
Post by: Timmy on July 14, 2018, 03:25:25 PM
I’m not aware of a simpler way.

The underlying logic that applies text coloring is abstracted away.
Title: Re: Custom Echo Text Colors
Post by: JamminR on July 14, 2018, 03:27:38 PM
There is no easy way to make commands that use ulx.fancyLog have partial color changes.
The ulx.fancyLog command colors the entire string (https://github.com/TeamUlysses/ulx/blob/c372f1a84fe86a5ecba21b16fcf73a4c78143eab/lua/ulx/log.lua#L503) of text using ULib.tsayColor (http://ulyssesmod.net/docs/files/lua/ulib/shared/messages-lua.html#tsayColor)
Title: Re: Custom Echo Text Colors
Post by: Darkblizzard on July 16, 2018, 11:04:27 PM
Where does it set the color of "#P" and "#s"?
Title: Re: Custom Echo Text Colors
Post by: JamminR on July 17, 2018, 03:58:33 PM
Follow the function code.
Starts here - https://github.com/TeamUlysses/ulx/blob/c372f1a84fe86a5ecba21b16fcf73a4c78143eab/lua/ulx/log.lua#L455
Goes down, determines if it's the beginning of the line, sets default color, goes down, if it comes across a player, colors misc color.