-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathsv_selling.lua
More file actions
83 lines (80 loc) · 2.94 KB
/
sv_selling.lua
File metadata and controls
83 lines (80 loc) · 2.94 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
local getCopsAmount = function()
local copsAmount = 0
local onlinePlayers = exports.it_bridge:GetOnlinePlayers()
if Config.Debug then lib.print.info('Online Players: ', #onlinePlayers) end
for i=1, #onlinePlayers do
local currentPlayer = onlinePlayers[i]
if currentPlayer then
local job = exports.it_bridge:GetPlayerJob(currentPlayer.source)
if Config.Debug then lib.print.info('Player', onlinePlayers[i], 'Job: ', job.name) end
for _, v in pairs(Config.PoliceJobs) do
if job.name == v then
if Config.OnlyCopsOnDuty then
if job.onDuty then
copsAmount = copsAmount + 1
end
else
copsAmount = copsAmount + 1
end
end
end
end
end
return copsAmount
end
RegisterNetEvent('it-drugs:server:initiatedrug', function(cad)
local src = source
local Player = exports.it_bridge:GetPlayer(src)
if Player then
local price = cad.price * cad.amount
if Config.SellSettings['giveBonusOnPolice'] then
local copsamount = getCopsAmount()
if copsamount > 0 and copsamount < 3 then
price = price * 1.2
elseif copsamount >= 3 and copsamount <= 6 then
price = price * 1.5
elseif copsamount >= 7 and copsamount <= 10 then
price = price * 1.7
elseif copsamount >= 10 then
price = price * 2.0
end
end
price = math.floor(price)
if exports.it_bridge:HasItem(src, cad.item, cad.amount) then
if exports.it_bridge:RemoveItem(src, tostring(cad.item), cad.amount) then
math.randomseed(GetGameTimer())
local stealChance = math.random(0, 100)
if stealChance < Config.SellSettings['stealChance'] then
ShowNotification(src, _U('NOTIFICATION__STOLEN__DRUG'), 'Error')
else
local moneyType = 'cash'
local rewardItems = nil
if Config.SellEverywhere['enabled'] then
moneyType = Config.SellEverywhere.drugs[cad.item].moneyType or 'cash'
rewardItems = Config.SellEverywhere.drugs[cad.item].rewardItems
else
moneyType = Config.SellZones[cad.zone].drugs[cad.item].moneyType or 'cash'
rewardItems = Config.SellZones[cad.zone].drugs[cad.item].rewardItems
end
exports.it_bridge:AddMoney(src, moneyType, price, "Money from Drug Selling")
if rewardItems then
for _, v in pairs(rewardItems) do
exports.it_bridge:GiveItem(src, v.name, (v.amount * cad.amount))
end
end
ShowNotification(src, _U('NOTIFICATION__SOLD__DRUG'):format(price), 'Success')
end
local coords = GetEntityCoords(GetPlayerPed(src))
SendToWebhook(src, 'sell', nil, ({item = cad.item, amount = cad.amount, price = price, coords = coords}))
if Config.Debug then print('You got ' .. cad.amount .. ' ' .. cad.item .. ' for $' .. price) end
else
ShowNotification(src, _U('NOTIFICATION__SELL__FAIL'):format(cad.item), 'Error')
end
else
ShowNotification(src, _U('NOTIFICATION__NO__ITEM__LEFT'):format(cad.item), 'Error')
end
end
end)
lib.callback.register('it-drugs:server:getCopsAmount', function(source)
return getCopsAmount()
end)