-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchat_broadcaster.lua
56 lines (47 loc) · 1.68 KB
/
chat_broadcaster.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local chat_box = peripheral.find("chatBox")
local modems = {peripheral.find("modem")}
local player_detector = peripheral.find("playerDetector")
local modem
for k,v in pairs(modems) do
if v.isWireless() == true then
modem = modems[k]
end
end
if modem then
rednet.open(peripheral.getName(modem))
rednet.broadcast({message="Chat Broadcast System has started."}, "chat_misc_broadcast")
end
local function chatThread()
while true do
local event, username, message, uuid, hidden = os.pullEvent("chat")
if not hidden then
rednet.broadcast({message=message, username=username}, "chat_event_broadcast")
print("Broadcasted:\n"..message.."\n"..username)
end
end
end
local function playerThread()
while true do
if player_detector then
local event, username = os.pullEvent()
local message = ""
if event == "playerJoin" then
message = username.." joined the game."
print(username.." Joined the game")
elseif event == "playerLeave" then
message = username.." left the game."
print(username.." Left the game")
elseif event == "playerClick" and username == "JajaSteele" then
message = username.." Clicked the detector. (This is a test message)"
print(username.." Clicked the game")
end
if #message > 0 then
rednet.broadcast({message=message}, "chat_player_broadcast")
print("Broadcasted:\n"..message)
end
else
sleep(10)
end
end
end
parallel.waitForAll(playerThread, chatThread)