ULX

Author Topic: Custom Echo Text Colors  (Read 3012 times)

0 Members and 2 Guests are viewing this topic.

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Custom Echo Text Colors
« 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

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Custom Echo Text Colors
« Reply #1 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).



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: [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.
Code: [Select]
ulx.logString( "Timmy typed a message", true )

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Re: Custom Echo Text Colors
« Reply #2 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.

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Custom Echo Text Colors
« Reply #3 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.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Custom Echo Text Colors
« Reply #4 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 of text using ULib.tsayColor
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Darkblizzard

  • Newbie
  • *
  • Posts: 39
  • Karma: 1
Re: Custom Echo Text Colors
« Reply #5 on: July 16, 2018, 11:04:27 PM »
Where does it set the color of "#P" and "#s"?
« Last Edit: July 17, 2018, 12:55:10 AM by Darkblizzard »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Custom Echo Text Colors
« Reply #6 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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming