Repository navigation
Expand file tree
/
Copy pathclient.lua
More file actions
583 lines (559 loc) · 19.7 KB
/
Copy pathclient.lua
File metadata and controls
583 lines (559 loc) · 19.7 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
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
local CurrentStore
local InRegZone, RegZoneID = false, nil
local TempStoreData = {}
local ox_inventory = exports.ox_inventory
local ox_target = exports.ox_target
local qb_target = exports['qb-target']
CopCount = 0
PlayerLoaded = false
local function SendDispatch()
if GetResourceState("ps-dispatch") == "started" then
exports['ps-dispatch']:StoreRobbery()
end
end
local function Alert(id)
local cfg = Config.Store[id]
if not cfg then return end
if cfg.alerted then return end
cfg.alerted = true
TriggerServerEvent("ran-storerobbery:server:registerAlert", id, true)
if cfg?.hack?.delayCount then
SetTimeout(1000 * cfg.hack.delayCount, function()
SendDispatch()
Functions.Notify("The police has been notified", "error")
end)
else
Functions.Notify("The police has been notified", "error")
SendDispatch()
end
end
local function DrawText3D(x, y, z, text)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(x, y, z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end
local propmodel = joaat('prop_till_01')
---@param victim number
---@param culprit number
---@return nil
local function EntityDamage(victim, culprit)
if culprit ~= cache.ped then return end
if Config.MinPolice > CopCount then return end
local alerted = false
if not CurrentStore then return end
if not TempStoreData then return end
local cfg = Config.Store[CurrentStore]
if cfg.alerted then return end
if next(TempStoreData) == nil then return end
local model = GetEntityModel(victim)
if model == propmodel and not alerted then
return Alert(CurrentStore)
end
end
local function Enter(self)
InRegZone = true
RegZoneID = self.regid
end
local function Exit()
InRegZone = false
RegZoneID = nil
end
local function AllStashSearched(id)
if not id then return end
local cfg = Config.Store[id]
if not cfg then return end
local allsearched = true
for k, v in pairs(cfg.search) do
if not v.iscomputer and not v.searched then
allsearched = false
break
end
end
return allsearched
end
local function RobRegistar()
if not CurrentStore then return end
if not RegZoneID or not InRegZone then
Functions.Notify("You need to stand in front of cashier", "error")
return
end
if Config.MinPolice > CopCount then
Functions.Notify("Not enough cops", "error")
return
end
local ped = cache.ped
local StoreConfig = Config.Store[CurrentStore]
if not StoreConfig then return end
local RegConfig = StoreConfig.registar[RegZoneID]
if RegConfig.robbed then
return Functions.Notify("There is no money in here", "error")
end
if not RegConfig then return end
if RegConfig.isusing then
return Functions.Notify("Somebody is in the register")
end
TriggerServerEvent("ran-storerobbery:server:setUse", CurrentStore, RegZoneID, true)
local anim = "oddjobs@shop_robbery@rob_till"
local animname = "loop"
lib.requestAnimDict(anim)
TaskPlayAnim(ped, anim, animname, 8.0, 8.0, -1, 3, 1.0, false, false, false)
local prize = math.floor(math.random(Config.Prize.min, Config.Prize.max))
if lib.progressCircle({
duration = Config.RegisterSearchTime,
label = 'Rummaging For Cash',
position = 'bottom',
useWhileDead = false,
canCancel = true,
disable = {
car = true,
move = true,
},
}) then
local success = exports['ran-minigames']:MineSweep(prize, 10, 3, "left")
if success then
local itemLabel = Functions.GetItemLabel(Config.Prize.item)
lib.callback("ran-houserobbery:server:getPrize", false, function(cb)
Functions.Notify(
("You got %s %s"):format(success,
Config.Prize.item and itemLabel or "Cash"), "success")
end, success, CurrentStore, RegZoneID)
end
TaskPlayAnim(ped, anim, "exit", 8.0, 8.0, -1, 0, 1.0, false, false, false)
TriggerServerEvent("ran-storerobbery:server:setUse", CurrentStore, RegZoneID, false)
else
TaskPlayAnim(ped, anim, "exit", 8.0, 8.0, -1, 0, 1.0, false, false, false)
TriggerServerEvent("ran-storerobbery:server:setUse", CurrentStore, RegZoneID, false)
end
end
local EData = nil
local function SearchCombination(storeid, sid)
if Config.MinPolice > CopCount then
Functions.Notify("Not enough police", "error")
return
end
local config = Config.Store[storeid]
if not config then return end
local searchLoc = config.search[sid]
if not searchLoc then return end
if config.cooldown then return end
if config.combination then
return Functions.Notify("You already got the combination...", "error")
end
if searchLoc.searched then
return Functions.Notify("You already search this place...", "error")
end
Alert(storeid)
if searchLoc.iscomputer then
if not AllStashSearched(storeid) then
return Functions.Notify("You need to search all the cabinet first...", "error")
end
local animdict = 'anim@scripted@player@mission@tunf_bunk_ig3_nas_upload@'
local anim = 'normal_typing'
lib.requestAnimDict(animdict)
TaskPlayAnim(cache.ped, animdict, anim, 8.0, 8.0, -1, 1, 1.0, false, false, false)
local success = exports['ran-minigames']:OpenTerminal()
if success then
local canGet = math.random(1, 100) > 20 and true or false
if canGet then
local TimeToWait = math.random(20, 30)
searchLoc.searched = true
Functions.Notify("You need to wait " .. TimeToWait .. " seconds, to decrypt the code")
SetTimeout(1000 * TimeToWait, function()
lib.callback.await("ran-storerobbery:server:combination", false, storeid, sid, true)
Functions.Notify("You got the combination key")
end)
else
lib.callback.await("ran-storerobbery:server:combination", false, storeid, sid, false)
Functions.Notify("Unable to get any information about pin from this computer", "error")
end
end
ClearPedTasks(cache.ped)
else
if lib.progressCircle({
duration = 5000,
position = "bottom",
useWhileDead = false,
label = "Searching combination",
canCancel = true,
disable = {
car = true
},
anim = {
dict = "mini@repair",
clip = "fixing_a_ped"
}
}) then
local canGet = math.random(1, 100) > 90 and true or false
lib.callback.await("ran-storerobbery:server:combination", false, storeid, sid, canGet)
if canGet then
Functions.Notify("You got the combination key")
else
Functions.Notify("You didn't get anything")
end
ClearPedTasks(cache.ped)
else
ClearPedTasks(cache.ped)
end
end
end
local function SetupStore(id)
local cfg = Config.Store[id]
if not cfg then return end
if cfg.cooldown then return end
EData = AddEventHandler('entityDamaged', EntityDamage)
local function UpdateConfig()
if not lib.table.matches(cfg, Config.Store[id]) then
cfg = Config.Store[id]
end
end
TempStoreData.registar = {}
for k, v in pairs(cfg.registar) do
TempStoreData.registar[k] = {}
TempStoreData.registar[k].zone = lib.zones.sphere({
coords = v.coords.xyz,
radius = 1.0,
regid = k,
onEnter = Enter,
onExit = Exit
})
end
local function Hack()
if cfg.hack.isusing then return end
if cfg.cooldown then return end
local success = exports['ran-minigames']:MemoryCard()
TriggerServerEvent("ran-storerobbery:server:setHackUse", id, true)
if success then
TriggerServerEvent("ran-houserobbery:server:setHackedState", id, true)
Wait(500)
Alert(id)
end
TriggerServerEvent("ran-storerobbery:server:setHackUse", id, false)
end
local function OpenPinPrompt()
local input = lib.inputDialog("Pin", {
{
type = 'number',
label = "Pin Number",
}
})
if not input then return end
if not input[1] then
return Functions.Notify("You need to fill the pin...", "error")
end
local num = tonumber(input[1])
if num == cfg.combination then
lib.callback.await("ran-storerobbery:server:setSafeState", false, CurrentStore, true)
return Functions.Notify("You unlocked the safe", "success")
else
return Functions.Notify("Wrong pin number...", "error")
end
end
local function InsideSafe(self)
if Config.MinPolice > CopCount then return end
if cfg.cooldown then return end
---@type vector3
local coords = self.coords
if cfg.safe.isopened then
DrawText3D(coords.x, coords.y, coords.z, "[~g~E~w~] Open Safe")
else
DrawText3D(coords.x, coords.y, coords.z, "[~r~E~w~] Try pin")
end
if IsControlJustPressed(0, 46) then
if cfg.safe.isopened and cfg.safe.id then
if Config.Inventory == "qb" then
TriggerServerEvent("inventory:server:OpenInventory", "stash", cfg.safe.id,
{ maxweight = 1000000, slots = 10 })
TriggerEvent("inventory:client:SetCurrentStash", cfg.safe.id)
elseif Config.Inventory == "ox" then
ox_inventory:openInventory("stash", cfg.safe.id)
end
else
OpenPinPrompt()
end
end
end
if cfg.hack then
local options = {
{
label = "Hack",
canInteract = function()
return not cfg.hack.hacked and not cfg.hack.isusing and not cfg.alerted and not cfg.cooldown
end,
distance = 1.0,
icon = "fas fa-laptop",
}
}
if Config.Target == "qb" then
options[1].action = Hack
options[1].item = Config.HackItem
local length = cfg.hack.size.x
local width = cfg.hack.size.y
TempStoreData.hack = qb_target:AddBoxZone('ran_robbery_hack', cfg.hack.coords, length,
width, {
name = 'ran_robbery_hack',
heading = cfg.hack.rotation,
minZ = cfg.hack.coords.z - cfg.hack.size.z,
maxZ = cfg.hack.coords.z + cfg.hack.size.z
}, {
options = options
})
elseif Config.Target == "ox" then
options[1].items = {
[Config.HackItem] = 1
}
options[1].onSelect = Hack
TempStoreData.hack = ox_target:addBoxZone({
coords = cfg.hack.coords,
size = cfg.hack.size,
rotation = cfg.hack.rotation,
options = options
})
end
end
if cfg.search then
TempStoreData.search = {}
for k, v in pairs(cfg.search) do
---@type OxTargetOption[] | any[]
local options = {}
if v.iscomputer then
options = {
{
label = "Search for combination",
distance = 2.0,
icon = "fa-solid fa-magnifying-glass",
canInteract = function()
return not cfg.combination and not cfg.cooldown
end,
},
{
label = "Look at the combination",
distance = 2.0,
icon = "fa-solid fa-computer",
canInteract = function()
return cfg.search[k].founded and AllStashSearched(id) and not cfg.cooldown
end,
}
}
if Config.Target == "qb" then
options[1].action = function()
SearchCombination(CurrentStore, k)
end
options[1].item = Config.HackItem
options[2].action = function()
Functions.Notify("The pin is " .. cfg.combination)
end
elseif Config.Target == "ox" then
options[1].onSelect = function()
SearchCombination(CurrentStore, k)
end
options[1].items = {
[Config.HackItem] = 1
}
options[2].onSelect = function()
Functions.Notify("The pin is " .. cfg.combination)
end
end
else
options = {
{
label = "Search for combination",
distance = 1.0,
icon = "fa-solid fa-magnifying-glass",
canInteract = function()
return not cfg.combination and not cfg.cooldown
end,
}
}
if Config.Target == "qb" then
options[1].action = function()
SearchCombination(CurrentStore, k)
end
elseif Config.Target == "ox" then
options[1].onSelect = function()
SearchCombination(CurrentStore, k)
end
end
end
if Config.Target == "qb" then
local length = v.size.x
local width = v.size.y
local minZ = v.coords.z - v.size.z
local maxZ = v.coords.z + v.size.z
TempStoreData.search[k] = qb_target:AddBoxZone('ran_robbery_search_' .. k, v.coords.xyz, length, width, {
name = 'ran_robbery_search_' .. k,
heading = v.rotation,
minZ = minZ,
maxZ = maxZ
}, {
options = options,
})
elseif Config.Target == "ox" then
TempStoreData.search[k] = exports.ox_target:addBoxZone({
coords = v.coords,
size = v.size,
rotation = v.rotation,
options = options,
drawSprite = false,
})
end
end
end
if cfg.safe then
TempStoreData.safe = lib.zones.sphere({
coords = cfg.safe.coords.xyz,
radius = 1.0,
inside = InsideSafe
})
end
CreateThread(function()
while CurrentStore == id do
UpdateConfig()
Wait(500)
end
end)
end
local function ResetStore(id)
if TempStoreData.hack then
if Config.Target == "ox" then
ox_target:removeZone(TempStoreData.hack)
elseif Config.Target == "qb" then
qb_target:RemoveZone(TempStoreData.hack?.name)
end
end
if TempStoreData.registar then
for _, v in pairs(TempStoreData.registar) do
if v.zone then
v.zone:remove()
end
end
end
if TempStoreData.search then
for _, v in pairs(TempStoreData.search) do
if Config.Target == "qb" then
qb_target:RemoveZone(v.name)
elseif Config.Target == "ox" then
ox_target:removeZone(v)
end
end
end
if TempStoreData.safe then
TempStoreData.safe:remove()
end
if EData then
RemoveEventHandler(EData)
EData = nil
end
table.wipe(TempStoreData)
end
local function ConfigContext()
local pnis = promise.new()
local opts = {}
for k, v in pairs(Config.Store) do
opts[#opts + 1] = {
title = ("Config Number: [%s] %s"):format(k, CurrentStore == k and "| Current Store" or " "),
description = ("Hack: %s | Register: %s | Robbed: %s"):format(
v.hack and true or false,
#v.registar,
v.alerted or false),
onSelect = function()
pnis:resolve(k)
end,
}
end
lib.registerContext({
id = "ran_storerobbery_config_context",
title = "Config",
options = opts,
onExit = function()
pnis:resolve(false)
end
})
lib.showContext('ran_storerobbery_config_context')
return Citizen.Await(pnis)
end
lib.callback.register("ran-storerobbery:client:openConfigContext", function()
return ConfigContext()
end)
lib.callback.register("ran-storerobbery:client:resetStore", function()
if not CurrentStore then return end
local cfg = Config.Store[CurrentStore]
if not cfg then return end
if cfg.cooldown then
Functions.Notify("This store is already on cooldown", "error")
return
end
if not cfg.alerted then
Functions.Notify("This store is not even robbed...", "error")
return
end
local alert = lib.alertDialog({
header = "Confirmation",
content = "Are you sure you want to reset the store?",
centered = true,
cancel = true
})
if alert == "confirm" then
return CurrentStore
elseif alert == "cancel" then
return false
end
end)
RegisterNetEvent("ran-storerobbery:client:setConfigs", function(cfg)
Config.Store = cfg
end)
RegisterNetEvent("ran-storerobbery:client:setStoreConfig", function(id, cfg)
if not id or not cfg then return end
if not type(cfg) == "table" then return end
if not Config.Store[id] then return end
Config.Store[id] = cfg
end)
CreateThread(function()
while true do
if PlayerLoaded then
local pos = GetEntityCoords(cache.ped)
for k, v in pairs(Config.Store) do
local pos2 = v.coords
local dist = #(pos - pos2)
if dist <= 20.0 and CurrentStore ~= k then
CurrentStore = k
SetupStore(k)
elseif dist >= 20.0 and CurrentStore == k then
ResetStore(k)
table.wipe(TempStoreData)
CurrentStore = nil
end
end
end
Wait(1000)
end
end)
CreateThread(function()
local options = {
{
label = "Grab Cash",
canInteract = function(entity, distance, coords, name, bone)
return entity and GetEntityHealth(entity) < 1000 and CurrentStore and not Config.Store[CurrentStore]
.cooldown
end,
icon = "fa-solid fa-cash-register",
}
}
if Config.Target == "qb" then
options[1].action = RobRegistar
qb_target:AddTargetModel('prop_till_01', {
options = options
})
elseif Config.Target == "ox" then
options[1].onSelect = RobRegistar
ox_target:addModel('prop_till_01', options)
end
end)