Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit b282d56

Browse files
author
nrzull
committed
redirect messages from outputChatBox
1 parent 03b3384 commit b282d56

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed

chat2_client.lua

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function show(bool)
4141
if chatInstanceLoaded ~= true then
4242
if chatInstanceLoading ~= true then
4343
create()
44-
setTimer(show, 300, 1, bool)
44+
return setTimer(show, 300, 1, bool)
4545
else
46-
setTimer(show, 300, 1, bool)
46+
return setTimer(show, 300, 1, bool)
4747
end
4848
end
4949

@@ -83,6 +83,24 @@ function onChatSendMessage(message, messageType)
8383
triggerServerEvent("onChat2SendMessage", resourceRoot, message, messageType)
8484
end
8585

86+
function listenForOutputChatBox(_, _, _, _, _, message, r, g, b)
87+
local hexColor = ""
88+
89+
if (r and g and b) then
90+
hexColor = RGBToHex(r, g, b)
91+
end
92+
93+
output(string.format("%s%s", hexColor, message))
94+
end
95+
96+
function onClientResourceStart()
97+
addDebugHook("postFunction", listenForOutputChatBox, {"outputChatBox"})
98+
end
99+
100+
function onClientResourceStop()
101+
removeDebugHook("postFunction", listenForOutputChatBox)
102+
end
103+
86104
addEventHandler("onClientResourceStart", resourceRoot, onResourceStart)
87105
addEventHandler("onClientResourceStop", resourceRoot, onResourceStop)
88106
addEventHandler("onChat2Loaded", resourceRoot, onChatLoaded)
@@ -91,3 +109,5 @@ addEventHandler("onChat2SendMessage", resourceRoot, onChatSendMessage)
91109
addEventHandler("onChat2Output", localPlayer, output)
92110
addEventHandler("onChat2Clear", localPlayer, clear)
93111
addEventHandler("onChat2Show", localPlayer, show)
112+
addEventHandler("onClientResourceStart", resourceRoot, onClientResourceStart)
113+
addEventHandler("onClientResourceStop", resourceRoot, onClientResourceStop)

chat2_server.lua

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ function useCustomEventHandlers(bool)
2525
isDefaultOutput = not bool
2626
end
2727

28-
function RGBToHex(red, green, blue)
29-
if (red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) then
30-
return nil
31-
end
32-
33-
return string.format("#%.2X%.2X%.2X", red, green, blue)
34-
end
35-
3628
function onChatSendMessage(message, messageType)
3729
if type(message) ~= "string" or utf8.len(message) < minLength or utf8.len(message) > maxLength then
3830
return
@@ -102,13 +94,26 @@ function onPlayerChat(message, messageType)
10294
end
10395
end
10496

105-
-- listen for messages that were sent from resources
106-
function onChatMessage(message, elementOrResource)
107-
if not isElement(elementOrResource) then
108-
output(root, message)
97+
function listenForOutputChatBox(_, _, _, _, _, message, receiver, r, g, b)
98+
receiver = receiver or root
99+
local hexColor = ""
100+
101+
if (r and g and b) then
102+
hexColor = RGBToHex(r, g, b)
109103
end
104+
105+
output(receiver, string.format("%s%s", hexColor, message))
106+
end
107+
108+
function onResourceStart()
109+
addDebugHook("postFunction", listenForOutputChatBox, {"outputChatBox"})
110+
end
111+
112+
function onResourceStop()
113+
removeDebugHook("postFunction", listenForOutputChatBox)
110114
end
111115

112116
addEventHandler("onChat2SendMessage", resourceRoot, onChatSendMessage)
113117
addEventHandler("onPlayerChat", root, onPlayerChat)
114-
addEventHandler("onChatMessage", root, onChatMessage)
118+
addEventHandler("onResourceStart", resourceRoot, onResourceStart)
119+
addEventHandler("onResourceStop", resourceRoot, onResourceStop)

chat2_shared.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function RGBToHex(red, green, blue)
2+
if (red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) then
3+
return nil
4+
end
5+
6+
return string.format("#%.2X%.2X%.2X", red, green, blue)
7+
end

meta.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<meta>
22
<info name="chat2" type="script" version="0.3.0" author="nrzull" />
33

4+
<script src="chat2_shared.lua" type="shared" />
45
<script src="chat2_server.lua" type="server" />
56
<script src="chat2_client.lua" type="client" />
67
<file src="index.html" />

0 commit comments

Comments
 (0)