-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
132 lines (98 loc) · 3.5 KB
/
Copy pathserver.lua
File metadata and controls
132 lines (98 loc) · 3.5 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
local QBCore = exports['qbx_core']:GetCoreObject()
local dumpsterLocks = {}
local dumpsterCooldowns = {}
math.randomseed(os.time())
local function notify(src, msg, type)
TriggerClientEvent('ox_lib:notify', src, {
description = msg,
type = type or "inform"
})
end
local function getRandomLoot()
local loot = {}
if math.random(1, 100) <= 33 then
return loot
end
local common = Config.CommonLoot[math.random(#Config.CommonLoot)]
table.insert(loot, {
item = common.item,
quantity = math.random(common.min, common.max)
})
for _, rare in pairs(Config.RareLoot) do
if math.random(1, 100) <= rare.chance then
table.insert(loot, {
item = rare.item,
quantity = rare.quantity
})
break
end
end
return loot
end
RegisterNetEvent('aimeri_dumpster:server:searchDumpster', function(name)
local src = source
if dumpsterCooldowns[name] and os.time() - dumpsterCooldowns[name] < Config.Cooldown then
return notify(src, "Dumpster is on cooldown", "error")
end
dumpsterCooldowns[name] = os.time()
local loot = getRandomLoot()
for _, v in pairs(loot) do
exports.ox_inventory:AddItem(src, v.item, v.quantity)
end
notify(src, "You found something!", "success")
end)
RegisterNetEvent('aimeri_dumpster:server:openDumpsterInventory', function(name)
local src = source
local player = exports.qbx_core:GetPlayer(src)
if not player then return end
local cid = player.PlayerData.citizenid
if dumpsterLocks[name] and dumpsterLocks[name].owner ~= cid then
return notify(src, "Locked dumpster", "error")
end
exports.ox_inventory:openInventory('stash', {
id = name,
label = "Dumpster",
slots = 40,
weight = 1000000
})
end)
RegisterNetEvent('aimeri_dumpster:server:padlockDumpster', function(name)
local src = source
local player = exports.qbx_core:GetPlayer(src)
local cid = player.PlayerData.citizenid
if dumpsterLocks[name] then
return notify(src, "Already locked", "error")
end
dumpsterLocks[name] = { owner = cid }
MySQL.insert('INSERT INTO aimeri_dumpster (dumpster_name, owner_cid) VALUES (?, ?)', {
name, cid
})
exports.ox_inventory:RemoveItem(src, 'padlock', 1)
notify(src, "Dumpster locked", "success")
end)
RegisterNetEvent('aimeri_dumpster:server:attemptBobbyPin', function(name, success)
local src = source
local player = exports.qbx_core:GetPlayer(src)
local lock = dumpsterLocks[name]
if not lock then return notify(src, "Not locked", "error") end
exports.ox_inventory:RemoveItem(src, 'bobbypin', 1)
if success then
dumpsterLocks[name] = nil
MySQL.query('DELETE FROM aimeri_dumpster WHERE dumpster_name = ?', { name })
notify(src, "Unlocked!", "success")
else
notify(src, "Failed", "error")
end
end)
RegisterCommand('cleardumpsterlocks', function(source)
if not Config.DebugLock then return end
MySQL.query.await('DELETE FROM aimeri_dumpster')
dumpsterLocks = {}
print('[aimeri_dumpster] All dumpster locks cleared.')
if source > 0 then
TriggerClientEvent('ox_lib:notify', source, {
description = 'All dumpster locks cleared.',
type = 'success'
})
end
end, true)