-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.lua
49 lines (47 loc) · 2.28 KB
/
main.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
local QBCore = exports['qb-core']:GetCoreObject()
-- Events --
RegisterNetEvent('g-drugselling:server:sell', function(sellLocation)
local src = source
local player = QBCore.Functions.GetPlayer(src)
for k, v in pairs(sellLocation.sellable_items) do
local hasItem = player.Functions.GetItemByName(k)
if hasItem then
if hasItem.amount >= v.sell_quantity then
local bundlesToSell = math.floor(hasItem.amount / v.sell_quantity)
local quantityToSell = bundlesToSell * v.sell_quantity
if player.Functions.RemoveItem(k, quantityToSell) then
for k2, v2 in pairs(v.rewards) do
local isMoneyType = false
for k3, v3 in pairs(QBConfig.Money.MoneyTypes) do
if tostring(k3) == k2 then
isMoneyType = true
end
end
if isMoneyType then
if not player.Functions.AddMoney(k2, v2) then
player.Functions.AddItem(k, quantityToSell)
return
end
else
if not player.Functions.AddItem(k2, v2) then
player.Functions.AddItem(k, quantityToSell)
return
end
if sellLocation.itemNotificationsEnabled then
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[k2], 'add', v2)
end
end
end
local notifyPoliceRoll = math.random(1, 100)
if notifyPoliceRoll <= sellLocation.policeAlertChance then
TriggerServerEvent('police:server:policeAlert', Lang:t('info.police_alert'))
end
end
else
if sellLocation.notificationsEnabled then
TriggerClientEvent('QBCore:Notify', src, Lang:t('error.not_enough', { itemLabel = QBCore.Shared.Items[k]['label'] }), 'error')
end
end
end
end
end)