Skip to content

Commit b216a90

Browse files
xLuxyqaisjp
authored andcommitted
admin2: Allow user nicknames to be colorcoded
1 parent 3c56156 commit b216a90

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

[admin]/admin2/server/admin_functions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ aFunctions = {
4747
local textDisplay = textCreateDisplay()
4848
local textItem =
4949
textCreateTextItem(
50-
"(ADMIN)" .. getPlayerName(source) .. ":\n\n" .. text,
50+
"(ADMIN)" .. stripColorCodes(getPlayerName(source)) .. ":\n\n" .. text,
5151
0.5,
5252
0.5,
5353
2,

[admin]/admin2/server/admin_server.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,31 @@ end
9898

9999
function aAction(type, action, admin, player, data, more)
100100
if (aLogMessages[type]) then
101-
function aStripString(string)
101+
function aStripString(string, hex)
102+
if not hex then
103+
hex = ""
104+
end
102105
string = tostring(string)
103-
string = string.gsub(string, "$admin", getPlayerName(admin))
106+
string = string.gsub(string, "$admin", getPlayerName(admin) .. hex)
104107
string = string.gsub(string, "$data2", more or "")
105108
if (player) then
106-
string = string.gsub(string, "$player", getPlayerName(player))
109+
string = string.gsub(string, "$player", getPlayerName(player) .. hex)
107110
end
108-
return tostring(string.gsub(string, "$data", data or ""))
111+
return string.gsub(string, "$data", (data and data .. hex or ""))
109112
end
110113
local node = aLogMessages[type][action]
111114
if (node) then
112115
local r, g, b = node["r"], node["g"], node["b"]
116+
local hex = RGBToHex(r, g, b)
117+
113118
if (node["all"]) then
114-
outputChatBox(aStripString(node["all"]), root, r, g, b)
119+
outputChatBox(aStripString(node["all"], hex), root, r, g, b, true)
115120
end
116121
if (node["admin"]) and (admin ~= player) then
117-
outputChatBox(aStripString(node["admin"]), admin, r, g, b)
122+
outputChatBox(aStripString(node["admin"], hex), admin, r, g, b, true)
118123
end
119124
if (node["player"]) then
120-
outputChatBox(aStripString(node["player"]), player, r, g, b)
125+
outputChatBox(aStripString(node["player"], hex), player, r, g, b, true)
121126
end
122127
if (node["log"]) then
123128
outputServerLog(aStripString(node["log"]))

[admin]/admin2/shared/utils.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ function stripColorCodes(str)
1616
until str:len() == oldLen
1717
return str
1818
end
19+
20+
function RGBToHex(red, green, blue, alpha)
21+
-- Make sure RGB values passed to this function are correct
22+
if( ( red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 ) or ( alpha and ( alpha < 0 or alpha > 255 ) ) ) then
23+
return nil
24+
end
25+
26+
-- Alpha check
27+
if alpha then
28+
return string.format("#%.2X%.2X%.2X%.2X", red, green, blue, alpha)
29+
else
30+
return string.format("#%.2X%.2X%.2X", red, green, blue)
31+
end
32+
end

0 commit comments

Comments
 (0)