Files
md-drugs/server/cornerselling.lua
T

290 lines
13 KiB
Lua
Raw Normal View History

2025-07-14 01:34:58 -07:00
2024-11-12 17:08:02 -08:00
local DrugDeals = {}
2024-11-12 01:04:42 -08:00
local Drugs = {
["weed_white-widow"] = {rep = 1,min = 15, max = 24 },
["weed_og-kush"] = {rep = 1,min = 15, max = 28 },
["weed_skunk"] = {rep = 1,min = 15, max = 31 },
["weed_amnesia"] = {rep = 1,min = 18, max = 34 },
["weed_purple-haze"] = {rep = 1,min = 18, max = 37},
["weed_ak47"] = {rep = 1,min = 18, max = 40},
["crack_baggy"] = {rep = 1,min = 18, max = 34},
["cokebaggy"] = {rep = 1,min = 18, max = 37},
["cokebaggystagetwo"] = {rep = 1,min = 18, max = 40},
["cokebaggystagethree"] = {rep = 1,min = 18, max = 40},
["heroin_ready"] = {rep = 1,min = 18, max = 40},
["heroin_readystagetwo"] = {rep = 1,min = 18, max = 40},
["heroin_readystagethree"] = {rep = 1,min = 18, max = 40},
["baggedcracked"] = {rep = 1,min = 18, max = 40},
["baggedcrackedstagetwo"] = {rep = 1,min = 18, max = 40},
["baggedcrackedstagethree"] = {rep = 1,min = 18, max = 40},
["white_playboys"] = {rep = 1,min = 18, max = 40},
["white_playboys2"] = {rep = 1,min = 18, max = 40},
["white_playboys3"] = {rep = 1,min = 18, max = 40},
["white_playboys4"] = {rep = 1,min = 18, max = 40},
["blue_playboys"] = {rep = 1,min = 18, max = 40},
["blue_playboys2"] = {rep = 1,min = 18, max = 40},
["blue_playboys3"] = {rep = 1,min = 18, max = 40},
["blue_playboys4"] = {rep = 1,min = 18, max = 40},
["red_playboys"] = {rep = 1,min = 18, max = 40},
["red_playboys2"] = {rep = 1,min = 18, max = 40},
["red_playboys3"] = {rep = 1,min = 18, max = 40},
["red_playboys4"] = {rep = 1,min = 18, max = 40},
["orange_playboys"] = {rep = 1,min = 18, max = 40},
["orange_playboys2"] = {rep = 1,min = 18, max = 40},
["orange_playboys3"] = {rep = 1,min = 18, max = 40},
["orange_playboys4"] = {rep = 1,min = 18, max = 40},
["white_aliens"] = {rep = 1,min = 18, max = 40},
["white_aliens2"] = {rep = 1,min = 18, max = 40},
["white_aliens3"] = {rep = 1,min = 18, max = 40},
["white_aliens4"] = {rep = 1,min = 18, max = 40},
["blue_aliens"] = {rep = 1,min = 18, max = 40},
["blue_aliens2"] = {rep = 1,min = 18, max = 40},
["blue_aliens3"] = {rep = 1,min = 18, max = 40},
["blue_aliens4"] = {rep = 1,min = 18, max = 40},
["red_aliens"] = {rep = 1,min = 18, max = 40},
["red_aliens2"] = {rep = 1,min = 18, max = 40},
["red_aliens3"] = {rep = 1,min = 18, max = 40},
["red_aliens4"] = {rep = 1,min = 18, max = 40},
["orange_aliens"] = {rep = 1,min = 18, max = 40},
["orange_aliens2"] = {rep = 1,min = 18, max = 40},
["orange_aliens3"] = {rep = 1,min = 18, max = 40},
["orange_aliens4"] = {rep = 1,min = 18, max = 40},
["white_pl"] = {rep = 1,min = 18, max = 40},
["white_pl2"] = {rep = 1,min = 18, max = 40},
["white_pl3"] = {rep = 1,min = 18, max = 40},
["white_pl4"] = {rep = 1,min = 18, max = 40},
["blue_pl"] = {rep = 1,min = 18, max = 40},
["blue_pl2"] = {rep = 1,min = 18, max = 40},
["blue_pl3"] = {rep = 1,min = 18, max = 40},
["blue_pl4"] = {rep = 1,min = 18, max = 40},
["red_pl"] = {rep = 1,min = 18, max = 40},
["red_pl2"] = {rep = 1,min = 18, max = 40},
["red_pl3"] = {rep = 1,min = 18, max = 40},
["red_pl4"] = {rep = 1,min = 18, max = 40},
["orange_pl"] = {rep = 1,min = 18, max = 40},
["orange_pl2"] = {rep = 1,min = 18, max = 40},
["orange_pl3"] = {rep = 1,min = 18, max = 40},
["orange_pl4"] = {rep = 1,min = 18, max = 40},
["white_trolls"] = {rep = 1,min = 18, max = 40},
["white_trolls2"] = {rep = 1,min = 18, max = 40},
["white_trolls3"] = {rep = 1,min = 18, max = 40},
["white_trolls4"] = {rep = 1,min = 18, max = 40},
["blue_trolls"] = {rep = 1,min = 18, max = 40},
["blue_trolls2"] = {rep = 1,min = 18, max = 40},
["blue_trolls3"] = {rep = 1,min = 18, max = 40},
["blue_trolls4"] = {rep = 1,min = 18, max = 40},
["red_trolls"] = {rep = 1,min = 18, max = 40},
["red_trolls2"] = {rep = 1,min = 18, max = 40},
["red_trolls3"] = {rep = 1,min = 18, max = 40},
["red_trolls4"] = {rep = 1,min = 18, max = 40},
["orange_trolls"] = {rep = 1,min = 18, max = 40},
["orange_trolls2"] = {rep = 1,min = 18, max = 40},
["orange_trolls3"] = {rep = 1,min = 18, max = 40},
["orange_trolls4"] = {rep = 1,min = 18, max = 40},
["white_cats"] = {rep = 1,min = 18, max = 40},
["white_cats2"] = {rep = 1,min = 18, max = 40},
["white_cats3"] = {rep = 1,min = 18, max = 40},
["white_cats4"] = {rep = 1,min = 18, max = 40},
["blue_cats"] = {rep = 1,min = 18, max = 40},
["blue_cats2"] = {rep = 1,min = 18, max = 40},
["blue_cats3"] = {rep = 1,min = 18, max = 40},
["blue_cats4"] = {rep = 1,min = 18, max = 40},
["red_cats"] = {rep = 1,min = 18, max = 40},
["red_cats2"] = {rep = 1,min = 18, max = 40},
["red_cats3"] = {rep = 1,min = 18, max = 40},
["red_cats4"] = {rep = 1,min = 18, max = 40},
["orange_cats"] = {rep = 1,min = 18, max = 40},
["orange_cats2"] = {rep = 1,min = 18, max = 40},
["orange_cats3"] = {rep = 1,min = 18, max = 40},
["orange_cats4"] = {rep = 1,min = 18, max = 40},
["blunts"] = {rep = 1,min = 18, max = 40},
["leanblunts"] = {rep = 1,min = 18, max = 40},
["dextroblunts"] = {rep = 1,min = 18, max = 40},
["chewyblunt"] = {rep = 1,min = 18, max = 40},
["blunt"] = {rep = 1,min = 18, max = 40},
["specialchocolate"] = {rep = 1,min = 18, max = 40},
["specialbrownie"] = {rep = 1,min = 18, max = 40},
["specialcookie"] = {rep = 1,min = 18, max = 40},
["specialmuffin"] = {rep = 1,min = 18, max = 40},
["shatter"] = {rep = 1,min = 18, max = 40},
["ciggie"] = {rep = 1,min = 18, max = 40},
2025-09-08 00:06:28 -07:00
["methbags"] = {rep = 1,min = 18, max = 40},
2024-11-12 01:04:42 -08:00
["driedmescaline"] = {rep = 1,min = 18, max = 40},
["shrooms"] = {rep = 1,min = 18, max = 40},
["gratefuldead_tabs"] = {rep = 1,min = 18, max = 40},
["bart_tabs"] = {rep = 1,min = 18, max = 40},
["pineapple_tabs"] = {rep = 1,min = 18, max = 40},
["yinyang_tabs"] = {rep = 1,min = 18, max = 40},
2025-09-08 00:06:28 -07:00
["wildcherry_tabs"] = {rep = 1,min = 18, max = 40},
2024-11-12 01:04:42 -08:00
["smiley_tabs"] = {rep = 1,min = 18, max = 40},
["cupoflean"] = {rep = 1,min = 18, max = 40},
["cupofdextro"] = {rep = 1,min = 18, max = 40},
}
2023-12-07 15:45:48 -08:00
2025-07-14 01:34:58 -07:00
local drugsNames = {}
2026-01-16 02:57:26 -07:00
local soldPeds = {}
2025-07-14 01:34:58 -07:00
for k, v in pairs(Drugs) do
table.insert(drugsNames, k)
end
GlobalState.DrugNames = drugsNames
2025-07-16 01:48:56 -07:00
2025-07-14 01:34:58 -07:00
local RobbedDrugs = {}
2025-09-08 00:06:28 -07:00
local cornsellConfig = {
MarkedBills = false, -- if you want to use qb markedbills for selling set to true, if you want to use a custom item or cash set to false
CustomItem = '', -- If you want to use a custom item for selling, put the item name here, if not leave it blank ''
--- if MarkedBills is false and CustomItem is blank it will pay cash
policeRequired = 0, -- if you want cops to be required to sell set this to a number above 0
robChance = 1, -- Chance To Be Robbed 1 = 1%
}
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
local function getLoc(src, ped)
local coords, peds = GetEntityCoords(GetPlayerPed(src)), GetEntityCoords(ped)
local dist = #(coords - peds)
if dist < 5.0 then
return true
end
return false
end
2026-01-19 00:38:01 -07:00
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
local ped = NetworkGetEntityFromNetworkId(ped)
if not getLoc(src, ped) then
return false
end
if soldPeds[src] == nil then
soldPeds[src] = {}
end
if soldPeds[src][ped] then
return false
end
2024-11-12 01:04:42 -08:00
for k, v in pairs(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)
2025-09-08 00:06:28 -07:00
if maths <= cornsellConfig.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)
2025-08-09 23:58:38 -06:00
local price = (math.random(Drugs[k]['min'], 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)
2024-11-12 17:08:02 -08:00
for k, v in pairs(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
for k, v in pairs (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
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-16 02:57:26 -07:00
if not csCheck(src, item, amount, price) then
return
end
local ped = NetworkGetEntityFromNetworkId(peds)
if not getLoc(src, ped) then
print('not close enough to ped')
return
end
if not soldPeds[src] or not soldPeds[src][ped] then
print('ped not in soldPeds')
return
end
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
2025-07-16 01:48:56 -07:00
AddRep(src, 'cornerselling', Drugs[item].rep * amount)
2026-01-16 02:57:26 -07:00
DrugDeals[src] = nil
2025-09-08 00:06:28 -07:00
if cornsellConfig.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
if cornsellConfig.CustomItem ~= '' then
2026-01-16 02:57:26 -07:00
Bridge.Inventory.AddItem(src, cornsellConfig.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
if not getLoc(src, ped) then return end
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-19 00:38:01 -07:00
local jobCount = Bridge.Framework.GetPlayersByJob('police')
if #jobCount < cornsellConfig.policeRequired then
2026-01-16 02:57:26 -07:00
Bridge.Notify.SendNotify(src, Bridge.Language.Locale('Catches.noCops'), '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)
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)