-
Notifications
You must be signed in to change notification settings - Fork 7
/
client.lua
467 lines (375 loc) · 10.3 KB
/
client.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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
RegisterNUICallback("getLocale", function(_, cb)
cb({locale = Config.Locale})
end)
CommunityService = {
value = false,
radiusBlip = nil,
markerBlip = nil,
marker = nil,
objectNet = nil,
update = function(self, value)
if value then
self:apply(value)
else
self:clear()
end
end,
apply = function(self, value)
if type(value) ~= "table" then
return
end
self.value = value
if not DoesBlipExist(self.radiusBlip) then
local blip = AddBlipForRadius(COMSERV.coords, COMSERV.radius + 0.0)
SetBlipColour(blip, 1)
SetBlipAlpha(blip, 150)
self.radiusBlip = blip
end
SendNUIMessage({ comserv = self.value })
CreateThread(function()
local lastTick = GetGameTimer()
while self.value do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
SetCurrentPedWeapon(playerPed, GetHashKey("weapon_unarmed"), true)
local distance = #(COMSERV.coords - playerCoords)
if distance > COMSERV.radius then
SetEntityCoords(playerPed, COMSERV.coords)
output(Translate("cannot_leave"))
self:nextTask()
Wait(2500)
end
if lastTick + 1000 < GetGameTimer() then
SendNUIMessage({ comserv = self.value })
lastTick = GetGameTimer()
end
Wait(250)
end
end)
CreateThread(function()
self:disabler()
end)
if not self.marker then
self:nextTask()
end
end,
clear = function(self)
if DoesBlipExist(self.radiusBlip) then
RemoveBlip(self.radiusBlip)
end
self:deleteTask()
self.value = false
SendNUIMessage({ comserv = false })
end,
nextTask = function(self)
self:deleteTask()
Wait(1)
local radius = math.ceil(COMSERV.radius * 0.7)
local posX, posY =
COMSERV.coords.x + math.random(-radius, radius), COMSERV.coords.y + math.random(-radius, radius)
local _, posZ = GetGroundZFor_3dCoord(posX, posY, 9999.0, true)
self.marker = vector3(posX, posY, posZ)
if DoesBlipExist(self.markerBlip) then
RemoveBlip(self.markerBlip)
end
self.markerBlip = AddBlipForCoord(self.marker)
SetBlipSprite(self.markerBlip, COMSERV.blip and COMSERV.blip.icon or 1)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(COMSERV.blip and COMSERV.blip.name or "")
EndTextCommandSetBlipName(self.markerBlip)
CreateThread(function()
local r, g, b, a = table.unpack(COMSERV.marker.color or { 200, 150, 0, 150 })
local lastTick = GetGameTimer()
while self.value and self.marker do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local distance = #(playerCoords - self.marker)
if distance <= (COMSERV.marker.size or 1) then
ESX.ShowHelpNotification(Translate("work_help"))
if IsControlJustPressed(0, 38) then
CreateThread(function()
self:startTaskProcess()
end)
end
end
local currentTick = GetGameTimer()
if lastTick + 2000 < currentTick then
local _, posZ = GetGroundZFor_3dCoord(self.marker.x, self.marker.y, 9999.0, true)
self.marker = vector3(self.marker.x, self.marker.y, posZ)
SetBlipCoords(self.markerBlip, self.marker)
lastTick = currentTick
end
if IsSphereVisible(self.marker, 0.0099999998) then
DrawMarker(
COMSERV.marker.typ or 1,
self.marker,
vector3(0, 0, 0),
vector3(0, 0, 0),
vector3((COMSERV.marker.size or 1), (COMSERV.marker.size or 1), (COMSERV.marker.size or 1)),
r or 200,
g or 150,
b or 0,
a or 150,
COMSERV.marker.upDown or false,
true,
2,
false,
nil,
nil,
false
)
Wait(0)
else
Wait(250)
end
end
end)
end,
deleteTask = function(self)
if DoesBlipExist(self.markerBlip) then
RemoveBlip(self.markerBlip)
end
self.markerBlip = nil
self.marker = nil
end,
startTaskProcess = function(self)
self:deleteTask()
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
ESX.Streaming.RequestModel(COMSERV.model)
local object = CreateObject(COMSERV.model, playerCoords - vector3(0, 0, 3), true, true, true)
self.objectNet = ObjToNet(object)
FreezeEntityPosition(playerPed, true)
ESX.Streaming.RequestAnimDict("amb@world_human_janitor@male@idle_a", function()
TaskPlayAnim(
playerPed,
"amb@world_human_janitor@male@idle_a",
"idle_a",
8.0,
-8.0,
-1,
0,
0,
false,
false,
false
)
AttachEntityToEntity(
object,
playerPed,
GetPedBoneIndex(playerPed, 28422),
-0.005,
0.0,
0.0,
360.0,
360.0,
0.0,
true,
true,
false,
true,
false,
true
)
end)
CreateThread(function()
Wait(10000)
local playerPed = PlayerPedId()
ClearPedTasks(playerPed)
FreezeEntityPosition(playerPed, false)
ESX.TriggerServerCallback("decreaseComservCount", function(value)
CommunityService:update(value)
end)
local object = NetToObj(self.objectNet)
if not DoesEntityExist(object) then
return
end
DetachEntity(object, true, true)
DeleteEntity(object)
self.objectNet = nil
end)
end,
disabler = function(self)
while self.value do
DisableControlAction(0, 24, true)
DisableControlAction(0, 25, true)
Wait(0)
end
end,
}
CommunityService.__index = CommunityService
AdminPanel = {
visible = false,
setVisible = function(self, state)
self.visible = state
SendNUIMessage({ adminPanel = state })
SetNuiFocus(self.visible, self.visible)
end,
init = function(self)
RegisterNetEvent("togglePunishmentsAdmin", function()
self:setVisible(not self.visible)
end)
RegisterNUICallback("closeAdminPanel", function()
self:setVisible(false)
end)
RegisterNUICallback("removeUser", function(data, cb)
ESX.TriggerServerCallback("removeUserFromPunishment", function(users)
cb({ users = users })
end, data.selectedTab, data.identifier)
end)
RegisterNUICallback("requestUsers", function(data, cb)
if not data.selectedTab then
return cb({ error = Translate("users_not_found") })
end
ESX.TriggerServerCallback("requestPunishmentUsers", function(users)
if not users then
return cb({ error = Translate("loading_error") })
end
cb({ users = users })
end, data.selectedTab)
end)
RegisterNUICallback("requestUserData", function(data, cb)
if not data.identifier then
return cb({ error = Translate("user_not_found") })
end
ESX.TriggerServerCallback("requestPunishmentUserData", function(error, userData)
if error then
return cb({ error = error })
end
cb({ userInfo = userData })
end, data.selectedTab, data.identifier)
end)
end,
}
AdminPanel.__index = AdminPanel
Jail = {
data = false,
timer = false,
update = function(self, data, isLogin)
if isLogin then
self.data = false
SendNUIMessage({ jail = false })
return
end
SendNUIMessage({ jail = data })
if not data then
return self:removePlayer()
end
self.data = false
Wait(5)
self:addPlayer(data)
end,
addPlayer = function(self, data)
self.data = data
local playerPed = PlayerPedId()
if not self.coords then
self.coords = JAIL.cells[math.random(1, #JAIL.cells)]
end
local playerCoords = GetEntityCoords(playerPed)
if #(playerCoords - self.coords) > JAIL.distance then
SetEntityCoords(playerPed, self.coords)
end
CreateThread(function()
self:distanceChecker()
end)
CreateThread(function()
self:disabler()
end)
CreateThread(function()
Wait(1000 * 60)
if Jail.data then
ESX.TriggerServerCallback("increaseAdminJailTime", function(data)
Jail:update(data)
end)
end
end)
end,
removePlayer = function(self)
self.data = false
Wait(150)
SetPlayerInvincible(PlayerId(), false)
local playerPed = PlayerPedId()
SetEntityCoords(playerPed, JAIL.outCoords)
SendNUIMessage({ jail = false })
end,
distanceChecker = function(self)
local lastTick = GetGameTimer()
while self.data do
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local distance = #(playerCoords - self.coords)
if distance >= JAIL.distance then
SetEntityCoords(playerPed, self.coords)
Wait(2500)
end
SetPlayerInvincible(PlayerId(), true)
SetCurrentPedWeapon(playerPed, GetHashKey("weapon_unarmed"), true)
if lastTick + 1000 < GetGameTimer() then
SendNUIMessage({ jail = self.data })
lastTick = GetGameTimer()
end
Wait(250)
end
end,
disabler = function(self)
while self.data do
DisableControlAction(0, 24, true)
DisableControlAction(0, 25, true)
Wait(0)
end
end,
}
Jail.__index = Jail
RegisterNetEvent("updatePlayerPunishment", function(name, data)
if name == "clear" then
CommunityService:update(false)
Jail:update(false, true)
return
end
if name == "comserv" then
if data then
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local distance = #(COMSERV.coords - playerCoords)
if distance > COMSERV.radius then
SetEntityCoords(playerPed, COMSERV.coords)
Wait(2500)
end
end
CommunityService:update(data)
elseif name == "jail" then
Jail:update(data)
end
end)
RegisterNetEvent("esx:onPlayerLogout", function()
TriggerEvent("updatePlayerPunishment", "clear")
end)
-- Add chat suggestions
CreateThread(function()
AdminPanel:init()
TriggerEvent("chat:addSuggestion", "/punishments", "Open Punishment List (Comserv, Jail, Ban)")
TriggerEvent("chat:addSuggestion", "/comserv", "Put player to community service", {
{ name = "id", help = "Target Player ID" },
{ name = "count", help = "Tasks Count" },
{ name = "reason", help = "Reason" },
})
TriggerEvent("chat:addSuggestion", "/removecomserv", "Remove player from community service", {
{ name = "id", help = "Target Player ID" },
})
TriggerEvent("chat:addSuggestion", "/ban", "Ban Player", {
{ name = "id", help = "Target Player ID" },
{ name = "days", help = "Days (0 - Infinity)" },
{ name = "reason", help = "Reason" },
})
TriggerEvent("chat:addSuggestion", "/unban", "Remove player ban", {
{ name = "name", help = "Identifier / Character Name" },
})
TriggerEvent("chat:addSuggestion", "/adminjail", "Put player to jail", {
{ name = "id", help = "Target Player ID" },
{ name = "minutes", help = "Minutes" },
{ name = "reason", help = "Reason" },
})
TriggerEvent("chat:addSuggestion", "/unjail", "Remove player from jail", {
{ name = "id", help = "Target Player ID" },
})
end)