Repository navigation
Expand file tree
/
Copy pathserver.lua
More file actions
297 lines (269 loc) · 9.45 KB
/
Copy pathserver.lua
File metadata and controls
297 lines (269 loc) · 9.45 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
local hookid
local StringCharset = {}
local NumberCharset = {}
local webhook
for i = 48, 57 do NumberCharset[#NumberCharset + 1] = string.char(i) end
for i = 65, 90 do StringCharset[#StringCharset + 1] = string.char(i) end
for i = 97, 122 do StringCharset[#StringCharset + 1] = string.char(i) end
local function SetupStore()
TriggerClientEvent("ran-storerobbery:client:setConfigs", -1, Config.Store)
end
local function SendLog(title, content, tageveryone)
if not webhook then
warn("No webhook link for " .. GetCurrentResourceName())
return
end
local embedData = {
username = "Store Robbery",
embeds = {
{
title = title,
color = 16711680,
footer = {
text = os.date('%c')
},
description = content,
author = {
name = "Store Robbery",
icon_url =
"https://media.discordapp.net/attachments/1139589833459761175/1144841078223159326/logo.png"
}
}
}
}
if tageveryone then
embedData.content = "@everyone"
end
PerformHttpRequest(webhook, function() end, 'POST', json.encode(embedData), { ['Content-Type'] = 'application/json' })
end
function RandomStr(length)
if length <= 0 then return '' end
return RandomStr(length - 1) .. StringCharset[math.random(1, #StringCharset)]
end
function RandomInt(length)
if length <= 0 then return '' end
return RandomInt(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
end
local function ResetStore(id)
local cfg = Config.Store[id]
if not cfg then return end
if not cfg.cooldown then return end
cfg.cooldown = false
cfg.alerted = false
cfg.combination = nil
for _, v in pairs(cfg.registar) do
v.robbed = false
v.isusing = false
end
for _, v in pairs(cfg.search) do
v.searched = false
if v.iscomputer then
v.founded = false
end
end
if cfg.safe and cfg.safe.opened then
cfg.safe.opened = false
cfg.safe.id = nil
end
end
local function Cooldown(storeid)
local cfg = Config.Store[storeid]
if not cfg then
warn("No config found for " .. storeid)
return
end
cfg.cooldown = true
SetTimeout(1000 * 60 * 60, function()
ResetStore(storeid)
end)
SendLog("Robbery end", ("Robbery with storeid: %s has ended"):format(storeid))
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, cfg)
end
local function GenerateSafeItems()
local totalChance = 0
for item, properties in pairs(Config.Prize.safe) do
totalChance = totalChance + properties.chance
end
local randomNumber = math.random(1, totalChance)
local currentChance = 0
local selectedItems = {}
for item, properties in pairs(Config.Prize.safe) do
currentChance = currentChance + properties.chance
if randomNumber <= currentChance then
local itemCount = math.random(properties.min, properties.max)
selectedItems[#selectedItems + 1] = {
[1] = item,
[2] = itemCount
}
end
end
return selectedItems
end
local function IncludeInventoryID(id)
for _, v in ipairs(Config.Store) do
if v.safe then
if v.safe.id == id then
return true
end
end
end
return false
end
local function GenerateCombination()
return RandomInt(4)
end
RegisterNetEvent("ran-storerobbery:server:getConfig", function()
local src = source
TriggerClientEvent("ran-storerobbery:client:setConfigs", src, Config.Store)
end)
RegisterNetEvent("ran-storerobbery:server:setUse", function(storeid, regid, status)
local storeConfig = Config.Store[storeid]
if not storeConfig then return end
local regConfig = storeConfig.registar[regid]
if not regConfig then return end
regConfig.isusing = status
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, storeConfig)
end)
RegisterNetEvent("ran-storerobbery:server:setHackUse", function(storeid, status)
local cfg = Config.Store[storeid]
if not cfg then return end
cfg.hack.isusing = status
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, cfg)
end)
RegisterNetEvent("ran-storerobbery:server:registerAlert", function(storeid, status)
local src = source
local cfg = Config.Store[storeid]
if not cfg then return end
if cfg.alerted == status then return end
cfg.alerted = status
SetTimeout(1000 * 60 * 60, function()
cfg = Config.Store[storeid]
if not cfg then return end
if not cfg.cooldown then
ResetStore(storeid)
end
end)
SendLog("Robbery Started", ("%s has started a robbery, storeid: %s"):format(GetPlayerName(src), storeid))
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, cfg)
end)
AddEventHandler('onResourceStart', function(resource)
if resource ~= cache.resource then return end
SetupStore()
if Config.Inventory == "ox" then
hookid = exports.ox_inventory:registerHook("swapItems", function(payload)
if payload.fromType == "player" and IncludeInventoryID(payload.toInventory) then
return false
else
return true
end
end, {
inventoryFilter = {
'^temp-[%w]+',
}
})
end
end)
RegisterNetEvent("ran-houserobbery:server:setHackedState", function(storeid, status)
local src = source
local cfg = Config.Store[storeid]
if not cfg then
warn("No config found for " .. storeid)
return
end
if cfg.hack.hacked == status then return end
cfg.hack.hacked = status
local delayCount = math.random(60, 90)
cfg.hack.delayCount = delayCount
Functions.NotifyClient(src, "The alarm will be delayed for " .. math.floor(delayCount) .. " seconds")
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, cfg)
end)
lib.callback.register("ran-houserobbery:server:getPrize", function(source, prize, storeid, regid)
local config = Config.Store[storeid]
if not config then return end
local regConfig = config.registar[regid]
if not regConfig then return end
if regConfig.robbed then return end
if prize > Config.Prize.max then
DropPlayer(source, "Exploit")
return
end
regConfig.robbed = true
local itemExist = Functions.ItemExist(Config.Prize.item)
if Config.Prize.item and itemExist then
Functions.AddItem(source, Config.Prize.item, prize, nil)
else
Functions.AddMoney(source, 'cash', prize)
end
SendLog("Get Prize",
("%s are robbing a register and got %s %s"):format(GetPlayerName(source), prize,
itemExist and itemExist.label or "cash"), prize >= Config.Prize.max)
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, config)
return true
end)
lib.callback.register("ran-storerobbery:server:combination", function(source, storeid, sid, status)
local cfg = Config.Store[storeid]
if not cfg then return end
local scfg = cfg.search[sid]
if not scfg then return end
if status then
local combination = GenerateCombination()
cfg.combination = tonumber(combination)
if scfg.iscomputer then
scfg.founded = true
else
Functions.AddItem(source, 'stickynote', 1, { combination = combination })
end
end
scfg.searched = true
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, cfg)
return true
end)
lib.callback.register("ran-storerobbery:server:setSafeState", function(_, storeid)
local config = Config.Store[storeid]
if not config then return end
if config.safe.opened and config.safe.id then return end
config.safe.isopened = true
config.safe.id = Functions.RegisterSafe(storeid, GenerateSafeItems())
TriggerClientEvent("ran-storerobbery:client:setStoreConfig", -1, storeid, config)
return true
end)
lib.addCommand("reset-store", {
help = "Reset Store (Store Robbery)"
}, function(source)
if source == 0 or not source then return end
local job = Functions.GetJob(source)
if not job or job ~= "police" then return end
local sc = lib.callback.await("ran-storerobbery:client:resetStore", source)
if sc then
Cooldown(sc)
end
end)
lib.addCommand("get-store-config", {
help = "Get Store Config (ADMIN ONLY)",
restricted = 'group.admin'
}, function(source)
---@type number | false
local cb = lib.callback.await("ran-storerobbery:client:openConfigContext", source)
if cb then
local cfg = Config.Store[cb]
if not cfg then return end
local ped = GetPlayerPed(source)
if not ped then return end
local coords = cfg.coords
SetEntityCoords(ped, coords.x, coords.y, coords.z - 1.0, true, false, false, false)
end
end)
Functions.CreateUseableItem('stickynote', function(src, item)
if item.info then
Functions.NotifyClient(src, "Combination: " .. item.info.combination)
elseif item.metadata then
Functions.NotifyClient(src, "Combination: " .. item.metadata.combination)
end
end)
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
if hookid then
exports.ox_inventory:removeHooks(hookid)
end
end
end)