/
sv_commands.lua
411 lines (341 loc) · 14 KB
/
sv_commands.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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
local function updateAgenda(ply, agenda, text)
local txt = hook.Run("agendaUpdated", ply, agenda, text)
agenda.text = txt or text
local phrase = DarkRP.getPhrase("agenda_updated")
for _, v in ipairs(player.GetAll()) do
if v:getAgendaTable() ~= agenda then continue end
v:setSelfDarkRPVar("agenda", agenda.text)
DarkRP.notify(v, 2, 4, phrase)
end
end
local function CreateAgenda(ply, args)
local agenda = ply:getAgendaTable()
if not agenda or not agenda.ManagersByKey[ply:Team()] then
DarkRP.notify(ply, 1, 6, DarkRP.getPhrase("incorrect_job", "agenda"))
return ""
end
updateAgenda(ply, agenda, args)
return ""
end
DarkRP.defineChatCommand("agenda", CreateAgenda, 0.1)
local function addAgenda(ply, args)
local agenda = ply:getAgendaTable()
if not agenda or not agenda.ManagersByKey[ply:Team()] then
DarkRP.notify(ply, 1, 6, DarkRP.getPhrase("incorrect_job", "agenda"))
return ""
end
agenda.text = agenda.text or ""
args = args or ""
updateAgenda(ply, agenda, agenda.text .. '\n' .. args)
return ""
end
DarkRP.defineChatCommand("addagenda", addAgenda, 0.1)
--[[---------------------------------------------------------
Mayor stuff
---------------------------------------------------------]]
local LotteryPeople = {}
local LotteryON = false
local LotteryAmount = 0
local CanLottery = CurTime()
local function EnterLottery(answer, ent, initiator, target, TimeIsUp)
local hasEntered = table.HasValue(LotteryPeople, target)
if tobool(answer) and not hasEntered then
if not target:canAfford(LotteryAmount) then
DarkRP.notify(target, 1,4, DarkRP.getPhrase("cant_afford", "lottery"))
return
end
table.insert(LotteryPeople, target)
target:addMoney(-LotteryAmount)
DarkRP.notify(target, 0,4, DarkRP.getPhrase("lottery_entered", DarkRP.formatMoney(LotteryAmount)))
hook.Run("playerEnteredLottery", target)
elseif IsValid(target) and answer ~= nil and not hasEntered then
DarkRP.notify(target, 1,4, DarkRP.getPhrase("lottery_not_entered", "You"))
end
if TimeIsUp then
LotteryON = false
CanLottery = CurTime() + 60
for i = #LotteryPeople, 1, -1 do
if not IsValid(LotteryPeople[i]) then table.remove(LotteryPeople, i) end
end
if #LotteryPeople == 0 then
DarkRP.notifyAll(1, 4, DarkRP.getPhrase("lottery_noone_entered"))
hook.Run("lotteryEnded", LotteryPeople)
return
end
local chosen = LotteryPeople[math.random(1, #LotteryPeople)]
local amt = #LotteryPeople * LotteryAmount
hook.Run("lotteryEnded", LotteryPeople, chosen, amt)
chosen:addMoney(amt)
DarkRP.notifyAll(0, 10, DarkRP.getPhrase("lottery_won", chosen:Nick(), DarkRP.formatMoney(amt)))
end
end
local function DoLottery(ply, amount)
if not ply:isMayor() then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("incorrect_job", "/lottery"))
return ""
end
if not GAMEMODE.Config.lottery then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("disabled", "/lottery", ""))
return ""
end
if player.GetCount() <= 2 or LotteryON then
DarkRP.notify(ply, 1, 6, DarkRP.getPhrase("unable", "/lottery", ""))
return ""
end
if CanLottery > CurTime() then
DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("have_to_wait", tostring(CanLottery - CurTime()), "/lottery"))
return ""
end
amount = tonumber(amount)
if not amount then
DarkRP.notify(ply, 1, 5, string.format("Please specify an entry cost ($%i-%i)", GAMEMODE.Config.minlotterycost, GAMEMODE.Config.maxlotterycost))
return ""
end
LotteryAmount = math.Clamp(math.floor(amount), GAMEMODE.Config.minlotterycost, GAMEMODE.Config.maxlotterycost)
hook.Run("lotteryStarted", ply, LotteryAmount)
LotteryON = true
LotteryPeople = {}
local phrase = DarkRP.getPhrase("lottery_has_started", DarkRP.formatMoney(LotteryAmount))
for k, v in ipairs(player.GetAll()) do
if v ~= ply then
DarkRP.createQuestion(phrase, "lottery" .. tostring(k), v, 30, EnterLottery, ply, v)
end
end
timer.Create("Lottery", 30, 1, function() EnterLottery(nil, nil, nil, nil, true) end)
return ""
end
DarkRP.defineChatCommand("lottery", DoLottery, 1)
local lastLockdown = -math.huge
function DarkRP.lockdown(ply)
local show = ply:EntIndex() == 0 and print or fp{DarkRP.notify, ply, 1, 4}
if GetGlobalBool("DarkRP_LockDown") then
show(DarkRP.getPhrase("unable", "/lockdown", DarkRP.getPhrase("stop_lockdown")))
return ""
end
if ply:EntIndex() ~= 0 and not ply:isMayor() then
show(DarkRP.getPhrase("incorrect_job", "/lockdown", ""))
return ""
end
if not GAMEMODE.Config.lockdown then
show(ply, 1, 4, DarkRP.getPhrase("disabled", "lockdown", ""))
return ""
end
if lastLockdown > CurTime() - GAMEMODE.Config.lockdowndelay then
show(DarkRP.getPhrase("wait_with_that"))
return ""
end
for _, v in ipairs(player.GetAll()) do
v:ConCommand("play " .. GAMEMODE.Config.lockdownsound .. "\n")
end
DarkRP.printMessageAll(HUD_PRINTTALK, DarkRP.getPhrase("lockdown_started"))
SetGlobalBool("DarkRP_LockDown", true)
DarkRP.notifyAll(0, 3, DarkRP.getPhrase("lockdown_started"))
hook.Run("lockdownStarted", ply)
return ""
end
DarkRP.defineChatCommand("lockdown", DarkRP.lockdown)
function DarkRP.unLockdown(ply)
local show = ply:EntIndex() == 0 and print or fp{DarkRP.notify, ply, 1, 4}
if not GetGlobalBool("DarkRP_LockDown") then
show(DarkRP.getPhrase("unable", "/unlockdown", DarkRP.getPhrase("lockdown_ended")))
return ""
end
if ply:EntIndex() ~= 0 and not ply:isMayor() then
show(DarkRP.getPhrase("incorrect_job", "/unlockdown", ""))
return ""
end
DarkRP.printMessageAll(HUD_PRINTTALK, DarkRP.getPhrase("lockdown_ended"))
DarkRP.notifyAll(0, 3, DarkRP.getPhrase("lockdown_ended"))
SetGlobalBool("DarkRP_LockDown", false)
lastLockdown = CurTime()
hook.Run("lockdownEnded", ply)
return ""
end
DarkRP.defineChatCommand("unlockdown", DarkRP.unLockdown)
--[[---------------------------------------------------------
License
---------------------------------------------------------]]
local function GrantLicense(answer, Ent, Initiator, Target)
Initiator.LicenseRequested = nil
if tobool(answer) then
DarkRP.notify(Initiator, 0, 4, DarkRP.getPhrase("gunlicense_granted", Target:Nick(), Initiator:Nick()))
DarkRP.notify(Target, 0, 4, DarkRP.getPhrase("gunlicense_granted", Target:Nick(), Initiator:Nick()))
Initiator:setDarkRPVar("HasGunlicense", true)
else
DarkRP.notify(Initiator, 1, 4, DarkRP.getPhrase("gunlicense_denied", Target:Nick(), Initiator:Nick()))
end
end
local function RequestLicense(ply)
if ply:getDarkRPVar("HasGunlicense") or ply.LicenseRequested then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/requestlicense", ""))
return ""
end
local LookingAt = ply:GetEyeTrace().Entity
local ismayor--first look if there's a mayor
local ischief-- then if there's a chief
local iscop-- and then if there's a cop to ask
for _, v in ipairs(player.GetAll()) do
if v:isMayor() and not v:getDarkRPVar("AFK") then
ismayor = true
break
end
end
if not ismayor then
for _, v in ipairs(player.GetAll()) do
if v:isChief() and not v:getDarkRPVar("AFK") then
ischief = true
break
end
end
end
if not ischief and not ismayor then
for _, v in ipairs(player.GetAll()) do
if v:isCP() then
iscop = true
break
end
end
end
if not ismayor and not ischief and not iscop then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/requestlicense", ""))
return ""
end
if not IsValid(LookingAt) or not LookingAt:IsPlayer() or LookingAt:GetPos():DistToSqr(ply:GetPos()) > 10000 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", "mayor/chief/cop"))
return ""
end
if ismayor and not LookingAt:isMayor() then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", "mayor"))
return ""
elseif ischief and not LookingAt:isChief() then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", "chief"))
return ""
elseif iscop and not LookingAt:isCP() then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", "cop"))
return ""
end
ply.LicenseRequested = true
DarkRP.notify(ply, 3, 4, DarkRP.getPhrase("gunlicense_requested", ply:Nick(), LookingAt:Nick()))
DarkRP.createQuestion(DarkRP.getPhrase("gunlicense_question_text", ply:Nick()), "Gunlicense" .. ply:EntIndex(), LookingAt, 20, GrantLicense, ply, LookingAt)
return ""
end
DarkRP.defineChatCommand("requestlicense", RequestLicense)
local function GiveLicense(ply)
local noMayorExists = fn.Compose{fn.Null, fn.Curry(fn.Filter, 2)(ply.isMayor), player.GetAll}
local noChiefExists = fn.Compose{fn.Null, fn.Curry(fn.Filter, 2)(ply.isChief), player.GetAll}
local canGiveLicense = fn.FOr{
ply.isMayor, -- Mayors can hand out licenses
fn.FAnd{ply.isChief, noMayorExists}, -- Chiefs can if there is no mayor
fn.FAnd{ply.isCP, noChiefExists, noMayorExists} -- CP's can if there are no chiefs nor mayors
}
if not canGiveLicense(ply) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("incorrect_job", "/givelicense"))
return ""
end
local LookingAt = ply:GetEyeTrace().Entity
if not IsValid(LookingAt) or not LookingAt:IsPlayer() or LookingAt:GetPos():DistToSqr(ply:GetPos()) > 10000 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", "player"))
return ""
end
DarkRP.notify(LookingAt, 0, 4, DarkRP.getPhrase("gunlicense_granted", ply:Nick(), LookingAt:Nick()))
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("gunlicense_granted", ply:Nick(), LookingAt:Nick()))
LookingAt:setDarkRPVar("HasGunlicense", true)
return ""
end
DarkRP.defineChatCommand("givelicense", GiveLicense)
local function rp_GiveLicense(ply, arg)
local target = DarkRP.findPlayer(arg)
if not target then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(arg)))
return
end
target:setDarkRPVar("HasGunlicense", true)
local nick, steamID
if ply:EntIndex() ~= 0 then
nick = ply:Nick()
steamID = ply:SteamID()
else
nick = "Console"
steamID = "Console"
end
DarkRP.notify(target, 0, 4, DarkRP.getPhrase("gunlicense_granted", nick, target:Nick()))
if ply ~= target then
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("gunlicense_granted", nick, target:Nick()))
end
DarkRP.log(nick .. " (" .. steamID .. ") force-gave " .. target:Nick() .. " a gun license", Color(30, 30, 30))
end
DarkRP.definePrivilegedChatCommand("setlicense", "DarkRP_SetLicense", rp_GiveLicense)
local function rp_RevokeLicense(ply, arg)
local target = DarkRP.findPlayer(arg)
if not target then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(arg)))
return
end
target:setDarkRPVar("HasGunlicense", nil)
local nick, steamID
if ply:EntIndex() ~= 0 then
nick = ply:Nick()
steamID = ply:SteamID()
else
nick = "Console"
steamID = "Console"
end
DarkRP.notify(target, 1, 4, DarkRP.getPhrase("gunlicense_denied", nick, target:Nick()))
if ply ~= target then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("gunlicense_denied", nick, target:Nick()))
end
DarkRP.log(nick .. " (" .. steamID .. ") force-removed " .. target:Nick() .. "'s gun license", Color(30, 30, 30))
end
DarkRP.definePrivilegedChatCommand("unsetlicense", "DarkRP_SetLicense", rp_RevokeLicense)
local function FinishRevokeLicense(vote, win)
if win == 1 then
vote.target:setDarkRPVar("HasGunlicense", nil)
vote.target:StripWeapons()
gamemode.Call("PlayerLoadout", vote.target)
DarkRP.notifyAll(0, 4, DarkRP.getPhrase("gunlicense_removed", vote.target:Nick()))
else
DarkRP.notifyAll(0, 4, DarkRP.getPhrase("gunlicense_not_removed", vote.target:Nick()))
end
end
local function VoteRemoveLicense(ply, args)
if #args == 1 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("vote_specify_reason"))
return ""
end
local reason = ""
for i = 2, #args, 1 do
reason = reason .. " " .. args[i]
end
reason = string.sub(reason, 2)
if string.len(reason) > 22 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/demotelicense", "<23"))
return ""
end
local p = DarkRP.findPlayer(args[1])
if p then
if CurTime() - ply.LastVoteCop < 80 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", math.ceil(80 - (CurTime() - ply:GetTable().LastVoteCop)), "/demotelicense"))
return ""
end
if ply:getDarkRPVar("HasGunlicense") then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/demotelicense", ""))
else
local voteInfo = DarkRP.createVote(p:Nick() .. ":\n" .. DarkRP.getPhrase("gunlicense_remove_vote_text2", reason), "removegunlicense", p, 20, FinishRevokeLicense, {
[p] = true,
[ply] = true
}, nil, nil, {
source = ply
})
if voteInfo then
-- Vote has started
DarkRP.notifyAll(0, 4, DarkRP.getPhrase("gunlicense_remove_vote_text", ply:Nick(), p:Nick()))
end
ply.LastVoteCop = CurTime()
end
return ""
else
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args[1])))
return ""
end
end
DarkRP.defineChatCommand("demotelicense", VoteRemoveLicense)