Files
md-drugs/server/cornerselling.lua
T

167 lines
5.3 KiB
Lua
Raw Normal View History

2025-07-14 01:34:58 -07:00
2024-11-12 17:08:02 -08:00
local DrugDeals = {}
2025-07-14 01:34:58 -07:00
local drugsNames = {}
2026-01-16 02:57:26 -07:00
local soldPeds = {}
2026-01-31 02:05:15 -07:00
for k, v in pairs(Config.Cornerselling.Drugs) do
2025-07-14 01:34:58 -07:00
table.insert(drugsNames, k)
end
GlobalState.DrugNames = drugsNames
2026-01-31 02:05:15 -07:00
2026-01-23 04:10:58 -07:00
GlobalState.MDDrugsLocations = Locations
2025-07-14 01:34:58 -07:00
local RobbedDrugs = {}
2026-01-31 02:05:15 -07:00
2026-01-16 02:57:26 -07:00
2025-07-14 01:34:58 -07:00
local function beingRobbed(source, item, amount, ped)
local src = source
2026-01-16 02:57:26 -07:00
Bridge.Inventory.RemoveItem(src, item, amount)
Bridge.Notify.SendNotify(src, Bridge.Language.Locale('Cornerselling.gotRobbed'), 'error')
RobbedDrugs[src] = {item = item, amount = amount, ped = ped}
2025-09-08 00:06:28 -07:00
return true
2025-07-14 01:34:58 -07:00
end
local function getDrugBack(source, item, amount)
local src = source
2026-01-16 02:57:26 -07:00
if RobbedDrugs[src] then
if RobbedDrugs[src].item == item and RobbedDrugs[src].amount == amount then
Bridge.Inventory.AddItem(src, item, amount)
Bridge.Notify.SendNotify(src, Bridge.Language.Locale('Cornerselling.gotBack'), 'success')
RobbedDrugs[src] = nil
2025-07-14 01:34:58 -07:00
return true
end
end
end
2026-01-16 02:57:26 -07:00
Bridge.Callback.Register('md-drugs:server:cornerselling:getAvailableDrugs', function(source, ped)
local src = source
2024-10-28 14:11:49 -07:00
local rep = getRep(source, 'cornerselling')
2026-01-16 02:57:26 -07:00
local priceAdjust = rep.price
2026-01-21 21:27:08 -07:00
2026-01-16 02:57:26 -07:00
local ped = NetworkGetEntityFromNetworkId(ped)
2026-01-21 21:27:08 -07:00
if not checkDistance(src, GetEntityCoords(ped), 5.0, 'md-drugs:server:cornerselling:getAvailableDrugs') then
2026-01-16 02:57:26 -07:00
return false
end
2026-01-21 21:27:08 -07:00
2026-01-16 02:57:26 -07:00
if soldPeds[src] == nil then
soldPeds[src] = {}
end
2026-01-21 21:27:08 -07:00
2026-01-16 02:57:26 -07:00
if soldPeds[src][ped] then
return false
end
2026-01-21 21:27:08 -07:00
2026-01-31 02:05:15 -07:00
for k, v in pairs(Config.Cornerselling.Drugs) do
2026-01-16 02:57:26 -07:00
local count = Bridge.Inventory.GetItemCount(src, k)
if count >= 1 then
2025-07-14 01:34:58 -07:00
local maths = math.random(1,100)
2026-01-21 21:27:08 -07:00
2026-01-31 02:44:07 -07:00
if maths <= Config.Cornerselling.config.robChance then
2026-01-16 02:57:26 -07:00
beingRobbed(source, k, count, ped)
soldPeds[src][ped] = {item = k, amount = count}
2025-07-14 01:34:58 -07:00
return 'robbed'
else
2026-01-16 02:57:26 -07:00
if count > 15 then count = 15 end
local amount = math.random(1, count)
2026-01-31 02:05:15 -07:00
local price = (math.random(Config.Cornerselling.Drugs[k]['min'], Config.Cornerselling.Drugs[k]['max']) * amount) * priceAdjust
2026-01-16 02:57:26 -07:00
DrugDeals[src] = {item = k, amount = amount, price = math.floor(price), ped = ped}
soldPeds[src][ped] = DrugDeals[src]
return DrugDeals[src]
2025-07-14 01:34:58 -07:00
end
2023-12-07 15:45:48 -08:00
end
end
2025-07-14 01:34:58 -07:00
return false
2023-12-07 15:45:48 -08:00
end)
2026-01-16 02:57:26 -07:00
Bridge.Callback.Register('md-drugs:server:hasDrugs', function(source)
2026-01-31 02:05:15 -07:00
for k, v in pairs(Config.Cornerselling.Drugs) do
2026-01-16 02:57:26 -07:00
if Bridge.Inventory.HasItem(source, k) then
2024-11-12 17:08:02 -08:00
return true
end
end
return false
end)
2023-12-07 15:45:48 -08:00
2025-07-14 01:34:58 -07:00
local function csCheck(src, item, amount, price)
2024-11-12 01:04:42 -08:00
local isIn = false
2026-01-31 02:05:15 -07:00
for k, v in pairs (Config.Cornerselling.Drugs) do
2025-07-14 01:34:58 -07:00
if item == k then
2024-11-12 01:04:42 -08:00
isIn = true
end
end
2026-01-21 21:27:08 -07:00
2025-07-14 01:34:58 -07:00
if not isIn then return false end
2026-01-16 02:57:26 -07:00
if DrugDeals[src] then
if DrugDeals[src].item == item and DrugDeals[src].amount == amount and DrugDeals[src].price == price then
2025-07-14 01:34:58 -07:00
return true
2024-05-02 18:34:49 -07:00
end
2024-11-12 01:04:42 -08:00
end
2025-07-14 01:34:58 -07:00
return false
end
2026-01-16 02:57:26 -07:00
RegisterNetEvent('md-drugs:server:sellCornerDrugs', function(item, amount, price, peds)
2025-07-14 01:34:58 -07:00
local src = source
2026-01-21 21:27:08 -07:00
2026-01-16 02:57:26 -07:00
if not csCheck(src, item, amount, price) then
return
end
2026-01-21 21:27:08 -07:00
2026-01-16 02:57:26 -07:00
local ped = NetworkGetEntityFromNetworkId(peds)
2026-01-21 21:27:08 -07:00
if not checkDistance(src, GetEntityCoords(ped), 5.0, 'md-drugs:server:sellCornerDrugs') then
2026-01-16 02:57:26 -07:00
return
end
2026-01-21 21:27:08 -07:00
2026-01-16 02:57:26 -07:00
if not soldPeds[src] or not soldPeds[src][ped] then
return
end
2026-01-21 21:27:08 -07:00
2026-01-16 02:57:26 -07:00
if not Bridge.Inventory.RemoveItem(src, item, amount) then
Bridge.Notify.SendNotify(src, Bridge.Language.Locale('Cornerselling.notEnough'), 'error')
DrugDeals[src] = nil
2025-07-14 01:34:58 -07:00
return
end
2026-01-21 21:27:08 -07:00
2026-01-31 02:05:15 -07:00
AddRep(src, 'cornerselling', Config.Cornerselling.Drugs[item].rep * amount)
2026-01-16 02:57:26 -07:00
DrugDeals[src] = nil
2026-01-21 21:27:08 -07:00
2026-01-31 02:44:07 -07:00
if Config.Cornerselling.config.MarkedBills then
2026-01-16 02:57:26 -07:00
Bridge.Inventory.AddItem(src, 'markedbills', price, nil, {worth = price})
2025-09-08 00:06:28 -07:00
return
end
2026-01-31 02:44:07 -07:00
if Config.Cornerselling.config.CustomItem ~= '' then
Bridge.Inventory.AddItem(src, Config.Cornerselling.config.CustomItem, price)
2025-09-08 00:06:28 -07:00
return
end
2026-01-16 02:57:26 -07:00
Bridge.Framework.AddAccountBalance(src, 'cash', price)
2025-07-14 01:34:58 -07:00
end)
2026-01-16 02:57:26 -07:00
RegisterNetEvent('md-drugs:server:getBackRobbed', function(peds)
local src = source
local tabl = RobbedDrugs[src]
2025-07-14 01:34:58 -07:00
if tabl == nil then return end
2026-01-16 02:57:26 -07:00
local ped = NetworkGetEntityFromNetworkId(peds)
if ped ~= tabl.ped then return end
2026-01-21 21:27:08 -07:00
if not checkDistance(src, GetEntityCoords(ped), 5.0, 'md-drugs:server:getBackRobbed') then
return
end
2026-01-16 02:57:26 -07:00
getDrugBack(src, tabl.item, tabl.amount)
RobbedDrugs[src] = nil
2023-12-07 15:45:48 -08:00
end)
2026-01-19 00:38:01 -07:00
RegisterCommand('cornersell', function(source, args, raw)
2024-07-19 10:28:34 -07:00
local src = source
2026-01-31 02:44:07 -07:00
if #Bridge.Framework.GetPlayersByJob('police') < Config.Cornerselling.config.policeRequired then
Bridge.Notify.SendNotify(src, Bridge.Language.Locale('Cornerselling.notEnoughCops', Config.Cornerselling.config.policeRequired - #Bridge.Framework.GetPlayersByJob('police')), 'error')
2025-09-08 00:06:28 -07:00
return
end
2024-07-19 10:28:34 -07:00
TriggerClientEvent('md-drugs:client:cornerselling', src)
2026-01-19 00:38:01 -07:00
end, false)
2026-01-21 21:27:08 -07:00
2026-01-19 00:38:01 -07:00
TriggerClientEvent('chat:addSuggestion', -1, '/cornersell', Bridge.Language.Locale('Cornerselling.comDes'))
2024-11-12 17:08:02 -08:00
RegisterServerEvent('md-drugs:server:cornerselling:stop', function()
local src = source
2026-01-16 02:57:26 -07:00
if DrugDeals[src] then
DrugDeals[src] = nil
2024-11-12 17:08:02 -08:00
end
end)