added qbx

This commit is contained in:
Mustache Dom committed 2025-01-29 20:26:39 -08:00
1 parent b4234abaf3
commit e0eb843d4e
9 files changed
+166 -142

No files matched your search

+9 -12
View File
@@ -70,6 +70,7 @@ RegisterServerEvent('md-drugs:server:cutcokeone', function(num)
else
if not checkLoc(src, 'CuttingCoke', num) then return end
end
local tier = 'tier1'
if Config.TierSystem then
local cokeTiers = {
{item = 'coke', tier = 'tier1', log = ' Cut Coke'},
@@ -78,14 +79,12 @@ RegisterServerEvent('md-drugs:server:cutcokeone', function(num)
}
for _, v in ipairs(cokeTiers) do
if hasItem(src, v.item, 1) then
if not GetRecipe(src, 'cocaine', 'cutcoke', v.tier) then return end
return
tier = v.tier
break
end
end
if not GetRecipe(src, 'cocaine', 'cutcoke', 'tier1') then return end
else
if not GetRecipe(src, 'cocaine', 'cutcoke', 'tier1') then return end
end
if not GetRecipe(src, 'cocaine', 'cutcoke', tier) then return end
end)
RegisterServerEvent('md-drugs:server:bagcoke', function(num)
@@ -95,6 +94,7 @@ RegisterServerEvent('md-drugs:server:bagcoke', function(num)
else
if not checkLoc(src, 'BaggingCoke', num) then return end
end
local tier = 'tier1'
if Config.TierSystem then
local cokeTiers = {
{item = 'loosecoke', tier = 'tier1', log = ' Bagged Coke'},
@@ -103,22 +103,19 @@ RegisterServerEvent('md-drugs:server:bagcoke', function(num)
}
for _, v in ipairs(cokeTiers) do
if hasItem(src, v.item, 1) then
if not GetRecipe(src, 'cocaine', 'bagcoke', v.tier) then return end
AddRep(src, 'coke')
return
tier = v.tier
break
end
end
if not GetRecipe(src, 'cocaine', 'bagcoke', 'tier1') then return end
else
if not GetRecipe(src, 'cocaine', 'bagcoke', 'tier1') then return end
end
if not GetRecipe(src, 'cocaine', 'bagcoke', tier) then return end
AddRep(src, 'coke', 1)
end)
local cokecut = {loosecokestagetwo = 2, loosecokestagethree = 3}
for k, v in pairs (cokecut) do
CUI(k, function(source, item)
local src = source
if not hasItem(src, 'bakingsoda', 1) then Notifys(src, 'You Need Baking Soda For this', 'error') return end
if hasItem(src, k, 1) then
if not Itemcheck(src, 'bakingsoda', 1) then return end
local check = lib.callback.await('md-drugs:client:uncuff', src, 'Cutting It Further')
+25 -28
View File
@@ -129,48 +129,50 @@ lib.callback.register('md-drugs:server:cornerselling:getAvailableDrugs', functio
local item = getItemCount(source, k)
if item >= 1 then
if item > 15 then item = 15 end
Log(GetName(source) .. ' Allowed To Sell ' .. k .. '!' , 'cornerselling')
local amount = math.random(1, item)
if amount >= 15 then amount = 15 end
local price = math.random(Drugs[k]['min'], Drugs[k]['max']) * amount
local result = math.floor(price * rep.price)
table.insert(DrugDeals, {item = k, amount = amount, price = result, cid = getCid(source), ped = ped})
return {item = k, amount = amount, price = result, ped = ped}
local price = (math.random(Drugs[k]['min'], Drugs[k]['max']) * amount) * rep.price
DrugDeals[getCid(source)] = {item = k, amount = amount, price = price, ped = ped}
Log(GetName(source) .. ' Allowed To Sell ' .. k .. '!' , 'cornerselling')
return DrugDeals[getCid(source)]
end
end
return {item = 'nothing', amount = 0, price = 0, ped = ped}
end)
lib.callback.register('md-drugs:server:hasDrugs', function(source)
local Player = getPlayer(source)
for k, v in pairs(Drugs) do
local item = hasItem(source, k, 1)
if item then
if hasItem(source, k, 1) then
return true
end
end
return false
end)
RegisterNetEvent('md-drugs:server:sellCornerDrugs', function(item, amount, price)
local src = source
local Player = getPlayer(src)
local function csCheck(src, item, amount, price)
local isIn = false
for k, v in pairs (Drugs) do
if item == k then
if item == k then
isIn = true
end
end
if not isIn then return end
for k, v in pairs (DrugDeals) do
if v.cid == getCid(source) and v.item == item and v.amount == amount and v.price == price then
if handleCornersell(src, item, amount, price) then
AddRep(src, 'cornerselling', Drugs[item].rep * amount)
Log(GetName(src) .. ' Sold ' .. amount .. ' Of ' .. item .. ' For A Price Of ' .. price .. '!' , 'cornerselling')
table.remove(DrugDeals, k)
end
if not isIn then return false end
if DrugDeals[getCid(src)] then
if DrugDeals[getCid(src)].item == item and DrugDeals[getCid(src)].amount == amount and DrugDeals[getCid(src)].price == price then
return true
end
end
return false
end
RegisterNetEvent('md-drugs:server:sellCornerDrugs', function(item, amount, price)
local src = source
if not csCheck(src, item, amount, price) then return end
if handleCornersell(src, item, amount, price) then
AddRep(src, 'cornerselling', Drugs[item].rep * amount)
Log(string.format('%s Sold %s Of %s For A Price Of $%s !', GetName(src),amount, item, price), 'cornerselling')
DrugDeals[getCid(src)] = nil
end
end)
lib.addCommand('cornersell', {
@@ -179,18 +181,13 @@ lib.addCommand('cornersell', {
},
}, function(source, args, raw)
local src = source
local Player = getPlayer(src)
Log(GetName(source) .. ' Used Command cornersell!' , 'cornerselling')
TriggerClientEvent('md-drugs:client:cornerselling', src)
end)
RegisterServerEvent('md-drugs:server:cornerselling:stop', function()
local src = source
local Player = getPlayer(src)
for k, v in pairs (DrugDeals) do
if v.cid == getCid(source) then
TriggerClientEvent('md-drugs:client:cornerselling:remove', src, DrugDeals[k].ped)
table.remove(DrugDeals, k)
end
if DrugDeals[getCid(src)] then
DrugDeals[getCid(src)] = nil
end
end)
+4 -9
View File
@@ -1,8 +1,7 @@
RegisterServerEvent('md-drugs:server:makecrackone', function(num)
local src = source
local Player = getPlayer(src)
local count,type, tier = 0, 'cookcrack', 'tier1'
local type, tier ='cookcrack', 'tier1'
if not checkLoc(src, 'makecrack', num) then return end
if Config.TierSystem then
local crackTiers = {
@@ -11,10 +10,9 @@ RegisterServerEvent('md-drugs:server:makecrackone', function(num)
{item = 'loosecokestagethree', tier = 'tier3', log = ' Cut Crack tier 3'}
}
for _, v in ipairs(crackTiers) do
if count >= 1 then break end
if hasItem(src, v.item, 1) then
tier = v.tier
count = count + 1
break
end
end
end
@@ -24,8 +22,7 @@ end)
RegisterServerEvent('md-drugs:server:bagcrack', function(num)
local src = source
local Player = getPlayer(src)
local count,type, tier = 0, 'bagcrack', 'tier1'
local type, tier = 'bagcrack', 'tier1'
if not checkLoc(src, 'bagcrack', num) then return end
if Config.TierSystem then
local crackTiers = {
@@ -34,10 +31,9 @@ RegisterServerEvent('md-drugs:server:bagcrack', function(num)
{item = 'crackrockstagethree', tier = 'tier3', log = ' Bagged Crack tier 3'}
}
for _, v in ipairs(crackTiers) do
if count >= 1 then break end
if hasItem(src, v.item, 1) then
tier = v.tier
count = count + 1
break
end
end
end
@@ -48,7 +44,6 @@ local cokecut = {crackrockstagetwo = 2, crackrockstagethree = 3}
for k, v in pairs (cokecut) do
CUI(k, function(source, item)
local src = source
local Player = getPlayer(src)
if hasItem(src, k, 1) then
if not Itemcheck(src, 'bakingsoda', 1) then return end
local check = lib.callback.await('md-drugs:client:uncuff', src, 'Cutting Crack Rock Further')
+7 -17
View File
@@ -84,7 +84,7 @@ lib.callback.register('md-drugs:server:getDealers', function(data)
local loc = json.encode({x = 899.98, y = -2603.24, z = 6.11, h = 176.12 })
if not check[1] then
MySQL.insert('INSERT INTO dealers SET name = ?, coords = ?, time = ?, createdby = ?', {'MD', loc, 'any', 'code Newb'})
Wait(2000)
Wait(2000)
local check2 = MySQL.query.await('SELECT * FROM dealers', {})
return check2
else
@@ -94,24 +94,19 @@ end)
local DeliveryItems = {
{ item = "weed_brick", minrep = 0, payout = {min = 10, max = 50}},
{ item = "coke_brick", minrep = 0, payout = {min = 10, max = 50}},
{item = "weed_brick", minrep = 0, payout = {min = 10, max = 50}},
{item = "coke_brick", minrep = 0, payout = {min = 10, max = 50}},
}
lib.callback.register('md-drugs:server:GetDeliveryItem', function(data)
local src = source
local Player = getPlayer(src)
local itemnum = math.random(1, #DeliveryItems)
local item = DeliveryItems[itemnum].item
local amount = math.random(1,4)
local check = MySQL.query.await('SELECT * FROM deliveriesdealer WHERE cid = ?', {getCid(src)})
local locnum = math.random(1, #dloc)
local coord = json.encode({
x = dloc[locnum].coords.x,
y = dloc[locnum].coords.y,
z = dloc[locnum].coords.z ,
w = dloc[locnum].coords.w
})
local coord = json.encode({ x = dloc[locnum].coords.x, y = dloc[locnum].coords.y, z = dloc[locnum].coords.z , w = dloc[locnum].coords.w })
if not check[1] then
MySQL.insert('INSERT INTO deliveriesdealer SET cid = ?, itemdata = ?, timestart = ?, maxtime = ?, location = ?',
{getCid(src), json.encode({item = item, amount = amount}), os.time(), os.time() + (15 * 60), coord })
@@ -165,7 +160,7 @@ lib.addCommand("newdealer", {
local dealerName = args.name
local pos = json.encode({x = coords.x, y = coords.y, z = coords.z})
local result = MySQL.scalar.await('SELECT name FROM dealers WHERE name = ?', { dealerName })
if result then
return Notifys(source,"Already Exists", "error")
@@ -176,12 +171,7 @@ lib.addCommand("newdealer", {
}, function()
QBConfig.Dealers[dealerName] = {
name = dealerName,
coords = {
x = coords.x,
y = coords.y,
z = coords.z,
h = GetEntityHeading(ped)
},
coords = { x = coords.x, y = coords.y, z = coords.z, h = GetEntityHeading(ped) },
}
TriggerClientEvent('md-drugs:client:RefreshDealers', -1, QBConfig.Dealers)
end)
+86 -59
View File
@@ -1,6 +1,8 @@
local QBCore, ESX = {}, {}
local QBCore, ESX, qbx = {}, {}, nil
local notify = Config.Notify -- qb or ox
local inventory = Config.Inventory -- qb or ox
local invname = ''
------------------------------------------ logging stuff
local logs = false
local logapi = GetConvar("fivemerrLogs", "")
@@ -14,8 +16,11 @@ if Config.Framework == 'qb' then
QBCore = exports['qb-core']:GetCoreObject()
elseif Config.Framework == 'esx' then
ESX = exports['es_extended']:getSharedObject()
elseif Config.Framework == 'qbx' then
qbx = exports.qbx_core
end
CreateThread(function()
if logs then
print'^2 Logs Enabled for md-drugs'
@@ -30,17 +35,11 @@ end
end)
function Log(message, type)
if logs == false then return end
local buffer = {
level = "info",
message = message,
resource = GetCurrentResourceName(),
metadata = {
drugs = type,
playerid = source
}
if logs == false then return end
local buffer = { level = "info", message = message, resource = GetCurrentResourceName(),
metadata = { drugs = type, playerid = source}
}
SetTimeout(500, function()
SetTimeout(500, function()
PerformHttpRequest(endpoint, function(status, _, _, response)
if status ~= 200 then
if type(response) == 'string' then
@@ -49,19 +48,8 @@ if logs == false then return end
end
end, 'POST', json.encode(buffer), headers)
buffer = nil
end)
end)
end
---------------------------------------------------- inventory catcher
local invname = ''
CreateThread(function()
if GetResourceState('ps-inventory') == 'started' then
invname = 'ps-inventory'
elseif GetResourceState('qb-inventory') == 'started' then
invname = 'qb-inventory'
else
invname = 'inventory'
end
end)
------------------------------------ Player Stuff functions
function getPlayer(source)
local src = source
@@ -71,6 +59,9 @@ function getPlayer(source)
elseif Config.Framework == 'esx' then
local Player = ESX.GetPlayerFromId(src)
return Player
elseif Config.Framework == 'qbx' then
local Player = qbx:GetPlayer(source)
return Player
end
end
@@ -81,6 +72,9 @@ function getPlayerByCid(cid)
elseif Config.Framework == 'esx' then
local Player = ESX.GetPlayerFromIdentifier(cid)
return Player
elseif Config.Framework == 'qbx' then
local Player = qbx:GetPlayerByCitizenId(cid)
return Player
end
end
@@ -92,10 +86,13 @@ function GetName(source)
elseif Config.Framework == 'esx' then
local Player = getPlayer(src)
return Player.getName()
elseif Config.Framework == 'qbx' then
local Player = getPlayer(src)
return Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
end
end
function getCid(source)
function getCid(source)
local src = source
if Config.Framework == 'qb' then
local Player = getPlayer(src)
@@ -103,8 +100,12 @@ function getCid(source)
elseif Config.Framework == 'esx' then
local Player = getPlayer(src)
return Player.getIdentifier()
elseif Config.Framework == 'qbx' then
local Player = getPlayer(src)
return Player.PlayerData.citizenid
end
end
function GetCoords(source)
local ped = GetPlayerPed(source)
local playerCoords = GetEntityCoords(ped)
@@ -115,7 +116,8 @@ function dist(source, coords)
local playerPed = GetPlayerPed(source)
local pcoords = GetEntityCoords(playerPed)
local dist = #(pcoords - coords)
return dist
return dist
end
function CheckDist(source, coords)
@@ -124,7 +126,7 @@ function CheckDist(source, coords)
local ok
if #(pcoords - coords) < 4.0 then
return ok
else
else
DropPlayer(source, 'md-drugs: You Were A Total Of ' .. #(pcoords - coords) .. ' Too Far Away To Trigger This Event')
return false
end
@@ -144,7 +146,7 @@ function Notifys(source, text, type)
end
end
function GetLabels(item)
function GetLabels(item)
if inventory == 'qb' then
return QBCore.Shared.Items[item].label
elseif inventory == 'ox' then
@@ -158,6 +160,8 @@ function CUI(item, useFunction)
QBCore.Functions.CreateUseableItem(item, useFunction)
elseif Config.Framework == 'esx' then
ESX.RegisterUsableItem(item, useFunction)
elseif Config.Framework == 'qbx' then
qbx:CreateUseableItem(item, useFunction)
end
end
@@ -230,7 +234,7 @@ function RemoveItem(source, item, amount)
if Player.Functions.RemoveItem(item, amount) then
TriggerClientEvent(invname ..":client:ItemBox", source, QBCore.Shared.Items[item], "remove", amount)
return true
else
else
Notifys(source, 'You Need ' .. amount .. ' Of ' .. GetLabels(item) .. ' To Do This', 'error')
end
elseif inventory == 'ox' then
@@ -277,6 +281,12 @@ function addMoney(source, type, amount)
else
return false
end
elseif Config.Framework == 'qbx' then
if qbx:AddMoney(source, type, amount) then
return true
else
return false
end
end
end
@@ -299,6 +309,12 @@ function removeMoney(source, type, amount)
else
return false
end
elseif Config.Framework == 'qbx' then
if qbx:RemoveMoney(source, type, amount) then
return true
else
return false
end
end
end
local function handleFresh(source)
@@ -312,7 +328,6 @@ local function handleFresh(source)
end
function getRep(source, type)
local Player = getPlayer(source)
local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {getCid(source)})
if not sql[1] then
local new = handleFresh(source)
@@ -326,7 +341,6 @@ function getRep(source, type)
end
function GetAllRep(source)
local Player = getPlayer(source)
local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {getCid(source)})
if not sql[1] then
local new = handleFresh(source)
@@ -338,9 +352,9 @@ function GetAllRep(source)
end
end
function AddRep(source, type, amount)
function AddRep(source, type, amount)
if not Config.TierSystem then return false end
if not amount then amount = 1 end
local Player = getPlayer(source)
local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {getCid(source)})
local reps = json.decode(sql[1].drugrep)
local update
@@ -376,17 +390,17 @@ lib.addCommand('addCornerSellingTOREP', {
local old = json.decode(v.drugrep)
local get = old[1] or old
table.insert(new, {
coke = get.coke,
lsd = get.lsd,
heroin = get.heroin,
dealerrep = get.dealerrep,
cornerselling = {
price = QBConfig.SellLevel[1].price,
rep = 0,
label = QBConfig.SellLevel[1].label,
level = 1
}
})
coke = get.coke,
lsd = get.lsd,
heroin = get.heroin,
dealerrep = get.dealerrep,
cornerselling = {
price = QBConfig.SellLevel[1].price,
rep = 0,
label = QBConfig.SellLevel[1].label,
level = 1
}
})
local news = json.encode(new)
MySQL.query.await('UPDATE drugrep SET drugrep = ? WHERE cid = ?', {news, v.cid})
end
@@ -417,6 +431,8 @@ function getCops()
end
end
return amount
elseif Config.Framework == 'qbx' then
return qbx:GetDutyCountType('leo')
end
end
@@ -447,9 +463,23 @@ function getNear(src)
end
end
return near
elseif Config.Framework == 'qbx' then
local near = {}
local players = qbx:GetPlayers()
for k, v in pairs (players) do
local targ = qbx:GetPlayer(v)
local tname = GetName(v)
local ped, tped = GetPlayerPed(src), GetPlayerPed(v)
local dist = #(GetEntityCoords(ped) - GetEntityCoords(tped))
if dist < 5.0 then
table.insert(near, {label = tname, value = getCid(v)})
end
end
return near
end
end
function handleCornersell(source, item, amount, price)
function handleCornersell(source, item, amount, price)
if RemoveItem(source, item, amount) then
if inventory == 'qb' then
local Player = getPlayer(source)
@@ -466,34 +496,28 @@ function handleCornersell(source, item, amount, price)
AddItem(source, 'black_money', price)
return true
end
else
return false
end
return false
end
lib.callback.register('md-drugs:server:GetCoppers', function(source, cb, args)
local amount = 0
local players = QBCore.Functions.GetQBPlayers()
for k, v in pairs(players) do
if v.PlayerData.job.type == 'leo' and v.PlayerData.job.onduty then
amount = amount + 1
end
end
return amount
return getCops()
end)
lib.callback.register('md-drugs:server:GetRep', function(source, cb, args)
local src = source
local rep = GetAllRep(source)
return rep
end)
CreateThread(function()
if not GetResourceState('ox_lib'):find("start") then
print('^1 ox_lib Is A Depndancy, Not An Optional ')
if GetResourceState('ps-inventory') == 'started' then
invname = 'ps-inventory'
elseif GetResourceState('qb-inventory') == 'started' then
invname = 'qb-inventory'
else
invname = 'inventory'
end
end)
CreateThread(function()
local url = "https://raw.githubusercontent.com/Mustachedom/md-drugs/main/version.txt"
local version = GetResourceMetadata('md-drugs', "version" )
PerformHttpRequest(url, function(err, text, headers)
@@ -501,4 +525,7 @@ CreateThread(function()
print('^2 Your Version:' .. version .. ' | Current Version:' .. text .. '' )
end
end, "GET", "", "")
if GetResourceState('ox_lib') ~= 'started' then
print('^1 ox_lib Is A Depndancy, Not An Optional ')
end
end)