-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.lua
More file actions
76 lines (69 loc) · 2.97 KB
/
Copy pathchat.lua
File metadata and controls
76 lines (69 loc) · 2.97 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- ttd_util/chat.lua
return function(ttd_util)
local core, C = core, core.colorize
local chat = { admins = {} }
-- /jailchat command --------------------------------------------------
core.register_chatcommand("jailchat", {
params = "<join|leave>",
description = "Join or leave the jail chat channel",
privs = { server = true },
func = function(name, param)
param = param:lower()
if param == "join" then
chat.admins[name] = "jail"
return true, "You have joined the jail chat channel."
elseif param == "leave" then
chat.admins[name] = nil
return true, "You have left the jail chat channel."
else
return false, "Usage: /jailchat <join|leave>"
end
end
})
-- Helpers ------------------------------------------------------------
local function format_jail_message(sender, message)
return C("yellow", "[") .. C("#FF6721", "JAIL") .. C("yellow", "]") ..
" " .. C("yellow", "<") .. C("#FF6721", sender) ..
C("yellow", ">") .. " " .. C("yellow", message)
end
local function send_jail_message(sender, message)
local jail = ttd_util.jail
for _, player in ipairs(core.get_connected_players()) do
local pname = player:get_player_name()
local pmode = chat.admins[pname]
if jail.is_jailed(pname) or pmode == "jail" then
core.chat_send_player(
pname,
format_jail_message(sender, message)
)
end
end
end
-- Chat interception --------------------------------------------------
core.register_on_chat_message(function(name, message)
local jail = ttd_util.jail
local jailed = jail.is_jailed(name)
local mode = chat.admins[name]
if jailed then
-- Jailed player: send only to jail channel
send_jail_message(name, message)
return true
end
if mode == "jail" then
-- Admin in jailchat mode: send only to jail channel
send_jail_message(name, message)
return true
end
-- Default: global chat (everyone not jailed sees it)
for _, player in ipairs(core.get_connected_players()) do
local pname = player:get_player_name()
if not jail.is_jailed(pname) then
core.chat_send_player(
pname,
"<" .. name .. "> " .. message
)
end
end
return true
end)
end