diff --git a/.vscode/settings.json b/.vscode/settings.json index 5464e9e..e7240e4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,8 @@ { "Lua.diagnostics.disable": [ "missing-parameter", - "param-type-mismatch" + "param-type-mismatch", + "lowercase-global" ], "Lua.diagnostics.globals": [ "lib", diff --git a/client/functions.lua b/client/functions.lua index a7e2700..51f75f5 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -9,6 +9,8 @@ function getJobType() return QBCore.Functions.GetPlayerData().job.type elseif Config.Framework == 'esx' then return ESX.PlayerData.job.type + elseif Config.Framework == 'qbx' then + return QBX.PlayerData.job.type end end @@ -17,6 +19,18 @@ function getJobName() return QBCore.Functions.GetPlayerData().job.name elseif Config.Framework == 'esx' then return ESX.PlayerData.job.name + elseif Config.Framework == 'qbx' then + return QBX.PlayerData.job.name + end +end + +function getGang() + if Config.Framework == 'qb' then + return QBCore.Functions.GetPlayerData().gang.name + elseif Config.Framework == 'esx' then + return ESX.GetPlayerData().job.name + elseif Config.Framework == 'qbx' then + return QBX.PlayerData.gang.name end end @@ -186,15 +200,15 @@ function minigame() function Notify(text, type) if notifytype =='ox' then - lib.notify({title = text, type = type}) - elseif notifytype == 'qb' then - QBCore.Functions.Notify(text, type) + lib.notify({title = text, type = type}) + elseif notifytype == 'qb' then + QBCore.Functions.Notify(text, type) elseif notifytype == 'okok' then - exports['okokNotify']:Alert('', text, 4000, type, false) + exports['okokNotify']:Alert('', text, 4000, type, false) else print"^1 SCRIPT ERROR: Md-DRUGS set your notification with one of the options!" end - end +end function GetImage(img) if GetResourceState('ox_inventory') == 'started' then @@ -247,10 +261,9 @@ end function makeMenu(name, rep) local menu = {} local data = lib.callback.await('md-drugs:server:menu', false, name) - print(data) for k, v in pairs (data.table) do local allow = false - if rep == nil then + if rep == nil then allow = true else if rep.dealerrep >= v.minrep then allow = true end @@ -403,7 +416,6 @@ function tele(coords) DoScreenFadeIn(500) end - function AddBoxZoneSingle(name, loc, data) if Config.Target == 'qb' then exports['qb-target']:AddBoxZone(name, loc, 1.5, 1.75, {name = name, minZ = loc.z-1,maxZ = loc.z +1}, @@ -453,13 +465,7 @@ function AddBoxZoneSingle(name, loc, data) }) end end -local function getGang() - if Config.Framework == 'qb' then - return QBCore.Functions.GetPlayerData().gang.name - elseif Config.Framework == 'esx' then - return ESX.GetPlayerData().job.name - end -end + function AddBoxZoneMulti(name, table, data) for k, v in pairs (table) do if v.gang == nil or v.gang == '' or v.gang == "" then v.gang = 1 end @@ -655,7 +661,7 @@ function StartRay2() until run == false end -function getAmbo() +function getAmbo() if Config.Framework == 'qb' then local Player = QBCore.Functions.GetPlayerData() if Player.PlayerData.job.type == 'ems' then @@ -670,6 +676,13 @@ function getAmbo() else return false end + elseif Config.Framework == 'qbx' then + local Player = QBX.PlayerData + if Player.job.name == 'ambulance' then + return true + else + return false + end end end diff --git a/fxmanifest.lua b/fxmanifest.lua index 153a10e..86dcc80 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,9 @@ description "drugs by mustache dom" fx_version "cerulean" game "gta5" version '3.9.0' + client_scripts { + --'@qbx_core/modules/playerdata.lua', 'client/**.lua', } diff --git a/server/cocaine.lua b/server/cocaine.lua index 597fc4f..e45d8a4 100644 --- a/server/cocaine.lua +++ b/server/cocaine.lua @@ -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') diff --git a/server/cornerselling.lua b/server/cornerselling.lua index 9c848b4..3f5d882 100644 --- a/server/cornerselling.lua +++ b/server/cornerselling.lua @@ -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) \ No newline at end of file diff --git a/server/crack.lua b/server/crack.lua index 4e6b1a4..8736430 100644 --- a/server/crack.lua +++ b/server/crack.lua @@ -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') diff --git a/server/deliveries.lua b/server/deliveries.lua index 2ab0696..247dd1d 100644 --- a/server/deliveries.lua +++ b/server/deliveries.lua @@ -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) diff --git a/server/functions.lua b/server/functions.lua index cf46687..da428b5 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -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) diff --git a/shared/config.lua b/shared/config.lua index 5bb54da..d33bbc3 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -55,4 +55,6 @@ 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 \ No newline at end of file