-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcommands_banish.lua
More file actions
330 lines (302 loc) · 13.8 KB
/
commands_banish.lua
File metadata and controls
330 lines (302 loc) · 13.8 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
-- Banish-related command registrations
function BANISH_AddBanishCommands()
CMD_AddCommand("jail", "<player> (/unjail to unjail)",
function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
STORAGE_EnsureGlobal()
-- Only if name provided
if param.parameter then
local victim = game.players[param.parameter]
if (victim) then
STORAGE_MakePlayerStorage(victim)
if player and victim.index == player.index then
UTIL_SmartPrint(player, "You can't put yourself in jail. Go touch grass.")
return
end
storage.PData[victim.index].banished = 1000
BANISH_DoJail(victim)
UTIL_SmartPrint(player, "Jailed player.")
else
UTIL_SmartPrint(player, "Couldn't find that player.")
end
else
UTIL_SmartPrint(player, "Who do you want to jail?")
end
end)
CMD_AddCommand("unjail", "<player>",
function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
STORAGE_EnsureGlobal()
-- Only if name provided
if param.parameter then
local victim = game.players[param.parameter]
if (victim) then
STORAGE_MakePlayerStorage(victim)
if player and victim and victim.index == player.index then
UTIL_SmartPrint(player, "You can't unjail yourself.")
return
end
storage.PData[victim.index].banished = 0
for _, vote in ipairs(storage.SM_Store.votes) do
if vote and vote.victim then
if vote.victim.index == victim.index then
vote.overruled = true
break
end
end
end
if not victim.character then
UTIL_SmartPrint(player, "They are OFFLINE right now, but will be unjailed on login.")
else
UTIL_SmartPrint(player, "Unjailed player.")
end
BANISH_UnbanishPlayer(victim)
else
UTIL_SmartPrint(player, "Couldn't find that player.")
end
else
UTIL_SmartPrint(player, "Who do you want unjail?")
end
end)
-- Mod vote overrrule
CMD_AddCommand("overrule",
"Moderators only: <defendant>\n(overrule votes against defendant)\n<clear>\n(clear all votes, will unbanish all)",
function(param)
local player
if param and param.player_index then
player = game.players[param.player_index]
end
if CMD_ModsOnly(param) then
return
end
STORAGE_EnsureGlobal()
-- Moderator only
if storage.SM_Store and storage.SM_Store.votes then
-- get arguments
local args = UTIL_SplitStr(param.parameter, " ")
-- Must have arguments
if args and args[1] ~= "" then
if args[1] == "clear" then
storage.SM_Store.votes = {}
UTIL_SmartPrint(player, "All votes cleared.")
BANISH_UpdateVotes()
return
end
local victim = game.players[args[1]]
-- If victim found
if victim then
local count = 0
for _, vote in ipairs(storage.SM_Store.votes) do
if vote and vote.victim then
if vote.victim == victim and not vote.overruled then
vote.overruled = true
count = count + 1
end
end
end
if count > 0 then
UTIL_SmartPrint(player, "Overruled " .. count .. " votes against " .. victim.name)
else
for _, vote in ipairs(storage.SM_Store.votes) do
if vote and vote.victim then
if vote.victim == victim and vote.overruled then
vote.overruled = false
count = count + 1
end
end
end
UTIL_SmartPrint(player,
"Withdrew " .. count .. " overrulings, against " .. victim.name)
end
BANISH_UpdateVotes()
return
else
UTIL_SmartPrint(player, "Couldn't find a player by that name.")
end
else
UTIL_SmartPrint(player,
"Who do you want to overrule votes against? <player> or <clear> (clears/unbanishes all)")
end
else
UTIL_SmartPrint(player, "There are no votes to overrule.")
end
end)
-- Print votes
CMD_AddCommand("votes", "(Shows banish votes)", function(param)
if param and param.player_index then
local player = game.players[param.player_index]
if CMD_NoBanished(player) then
return
end
-- Only if banish data found
if storage.SM_Store and storage.SM_Store.votes then
-- Print votes
local pcount = 0
for _, vote in ipairs(storage.SM_Store.votes) do
if vote and vote.voter and vote.voter.valid and vote.victim then
local notes = ""
if vote.withdrawn then
notes = "(WITHDRAWN) "
end
if vote.overruled then
notes = "(OVERRULED) "
end
pcount = pcount + 1
UTIL_SmartPrint(player, notes .. "plaintiff: " .. vote.voter.name .. ", defendant: " ..
vote.victim.name .. ", complaint:\n" .. vote.reason)
end
end
-- Tally votes before proceeding
BANISH_UpdateVotes()
local player_indices = {}
for player_index, _ in pairs(game.players) do
table.insert(player_indices, player_index)
end
table.sort(player_indices)
-- Print accused
if storage.PData then
for _, victim_index in ipairs(player_indices) do
local victim = game.players[victim_index]
if storage.PData[victim.index].banished and storage.PData[victim.index].banished > 0 then
UTIL_SmartPrint(player, victim.name .. " has had " .. storage.PData[victim.index].banished ..
" complaints against them.")
pcount = pcount + 1
end
end
end
-- Show summery of votes against them
if storage.SM_Store.votes then
for _, victim_index in ipairs(player_indices) do
local victim = game.players[victim_index]
local votecount = 0
for _, vote in ipairs(storage.SM_Store.votes) do
if victim == vote.voter then
votecount = votecount + 1
end
end
if votecount > 2 then
UTIL_SmartPrint(player, victim.name .. " has voted against " .. votecount .. " players.")
pcount = pcount + 1
end
end
end
-- Nothing found, report it
if pcount <= 0 then
UTIL_SmartPrint(player, "The docket is clean.")
end
return
else
-- No vote data
UTIL_SmartPrint(player, "The docket is clean.")
BANISH_UpdateVotes()
return
end
end
end)
-- Banish command
CMD_AddCommand("unbanish", "<player>\n(Withdraws a banish vote)", function(param)
if param and param.player_index then
local player = game.players[param.player_index]
if CMD_NoBanished(player) then
return
end
if player and param.parameter then
-- regulars/moderators players only
if UTIL_Is_Regular(player) or UTIL_Is_Veteran(player) or player.admin then
-- get arguments
local args = UTIL_SplitStr(param.parameter, " ")
-- Must have arguments
if args and args[1] ~= "" then
local victim = game.players[args[1]]
-- Must have valid victim
if victim and victim.character and victim.character.valid then
-- Check if we voted against them
if storage.SM_Store.votes then
for _, vote in ipairs(storage.SM_Store.votes) do
if vote and vote.voter and vote.victim then
if vote.voter == player and vote.victim == victim then
if vote.withdrawn then
UTIL_SmartPrint(player, "You've already withdrawn your vote.")
return
end
-- Send report to discord and withdraw vote
local message = player.name .. " WITHDREW their vote to banish: " ..
victim.name
UTIL_MsgAllSys(message)
print("[REPORT] " .. message)
UTIL_SmartPrint(player,
"Your vote has been withdrawn, and posted on Discord.")
vote.withdrawn = true
BANISH_UpdateVotes() -- Must do this to delete from tally
return
end
end
end
UTIL_SmartPrint(player, "I don't see a vote from you, against that player, to withdraw.")
end
else
UTIL_SmartPrint(player, "There are no players online by that name.")
end
else
UTIL_SmartPrint(player, "Usage: /unbanish <player>")
end
else
UTIL_SmartPrint(player, "Only regulars/moderator status players can vote.")
return
end
else
UTIL_SmartPrint(player, "Usage: /unbanish <player>")
end
else
UTIL_SmartPrint(nil, "The console can't vote.")
end
end)
-- Banish command
CMD_AddCommand("banish", "<player> <reason for banishment>\n(Sends player to a confined area, off-map)",
function(param)
if param and param.player_index then
local player = game.players[param.player_index]
if not param.parameter then
UTIL_SmartPrint(player, "Banish who?")
return
end
local args = UTIL_SplitStr(param.parameter, " ")
if not args[2] then
UTIL_SmartPrint(player, "You must specify a reason.")
return
end
local victim = game.players[args[1]]
-- Quick arg combine
local reason = table.concat(args, " ", 2)
if UTIL_Is_Banished(victim) then
UTIL_SmartPrint(player, "They are already banished!")
return
end
BANISH_DoBanish(player, victim, reason)
end
end)
-- User report command
CMD_AddCommand("report", "<detailed report here>\n(Sends in a report to the moderators)", function(param)
if param and param.player_index then
local player = game.players[param.player_index]
if CMD_NoBanished(player) then
return
end
BANISH_DoReport(player, param.parameter)
else
UTIL_SmartPrint(nil, "The console doesn't need to send in reports this way.")
end
end)
end