Ulysses
General => Developers Corner => Topic started by: Rice Cooker on July 03, 2019, 06:55:57 PM
-
I have been wondering for awhile and I have tried many ways but I can seem to find a way.
Is there a way to have ulx fancylog or command echo start with a prefix? Its not necessary but it looks more elegant.
Ex: If Admin Jails Player
Command Echo: > Admin has jailed Player
Trying To Add: >
I appreciate any help or suggestions that people can offer.
Thanks!
-
You could monkey patch (https://en.wikipedia.org/wiki/Monkey_patch) ulx.fancyLogAdmin. It's a little tricky because the function is undocumented and variadic (https://en.wikipedia.org/wiki/Variadic_function).
Steps:
- Hijack ulx.fancyLogAdmin.
- Find out at which argument holds the formatting string.
- Customize the formatting string.
- Call the original ulx.fancyLogAdmin with the customized formatting string.
I attached a working example to my post. Download and take a peek at the source if you want to see my implementation.
-
Thanks Timmy! I tried your example and it worked. Is there a way to set the prefix to a predetermined color instead of relying on the default chat color?
-
Sure.
Internally, ulx.fancyLogAdmin uses ULib.tsayColor to send colorful chat messages to you and your players. (Source: https://github.com/TeamUlysses/ulx/blob/v3.73/lua/ulx/log.lua#L503)
Documentation for ULib.tsayColor: https://ulyssesmod.net/docs/files/lua/ulib/shared/messages-lua.html#tsayColor
You can monkey patch ULib.tsayColor so that it automatically prepends your colored prefix.
-- lua/ulx/modules/tsaycolor_patch.lua
local tsayColor = ULib.tsayColor
function ULib.tsayColor( ply, wait, ... )
return tsayColor( ply, wait, Color( 247, 143, 179 ), "> ", ... )
end
But that will add the prefix every time ULib or ULX send colorful messages. Even for adverts. Perhaps it would be better to temporarily patch tsayColor when fancyLogAdmin runs.
-- lua/ulx/modules/fancylogadmin_patch.lua
local fancyLogAdmin = ulx.fancyLogAdmin
local tsayColor = ULib.tsayColor
local function customTsayColor( ply, wait, ... )
return tsayColor( ply, wait, Color( 247, 143, 179 ), "> ", ... )
end
function ulx.fancyLogAdmin( ... )
ULib.tsayColor = customTsayColor
fancyLogAdmin( ... )
ULib.tsayColor = tsayColor
end