General > Developers Corner
Command Prefix
(1/1)
Rice Cooker:
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!
Timmy:
You could monkey patch ulx.fancyLogAdmin. It's a little tricky because the function is undocumented and variadic.
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.
Rice Cooker:
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?
Timmy:
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.
--- Code: ----- lua/ulx/modules/tsaycolor_patch.lua
local tsayColor = ULib.tsayColor
function ULib.tsayColor( ply, wait, ... )
return tsayColor( ply, wait, Color( 247, 143, 179 ), "> ", ... )
end
--- End code ---
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.
--- Code: ----- 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
--- End code ---
Navigation
[0] Message Index
Go to full version