From 4fdef3cf3018401b23a9b2d0058eed60e52d0d08 Mon Sep 17 00:00:00 2001 From: Mustache Dom <123716453+Mustachedom@users.noreply.github.com> Date: Mon, 14 Jul 2025 01:34:58 -0700 Subject: [PATCH] - fix up heroin --- client/cocaine.lua | 41 ++-- client/cornerselling.lua | 238 ++++++++++++-------- client/heroin.lua | 183 ++++++++++------ fxmanifest.lua | 2 + server/cornerselling.lua | 143 +++++++----- server/functions.lua | 454 +++++++++++++++++++++++++++------------ server/heroin.lua | 204 +++++++++--------- shared/config.lua | 6 +- 8 files changed, 795 insertions(+), 476 deletions(-) diff --git a/client/cocaine.lua b/client/cocaine.lua index 533dd88..fbf6608 100644 --- a/client/cocaine.lua +++ b/client/cocaine.lua @@ -1,27 +1,32 @@ local CocaPlant = {} local cuttingcoke = nil local baggingcoke = nil + local function pick(loc) if not progressbar(Lang.Coke.picking, 4000, 'uncuff') then return end TriggerServerEvent("coke:pickupCane", loc) return true end +local function targetOps(loc) + return { + { + icon = "fa-solid fa-seedling", + label = ps.lang('targets.coke.pick'), + action = function() + if not pick(loc) then return end + end + } + } +end + RegisterNetEvent('coke:respawnCane', function(loc) local v = GlobalState.CocaPlant[loc] local hash = GetHashKey(v.model) if not CocaPlant[loc] then CocaPlant[loc] = CreateObject(hash, v.location, false, true, true) Freeze(CocaPlant[loc], true, v.heading) - ps.entityTarget(CocaPlant[loc], { - { - icon = "fa-solid fa-seedling", - label = ps.lang('targets.coke.pick'), - action = function() - if not pick(loc) then return end - end - } - }) + ps.entityTarget(CocaPlant[loc], targetOps(loc)) end end) @@ -37,15 +42,7 @@ RegisterNetEvent("coke:init", function() if not v.taken then CocaPlant[k] = CreateObject(hash, v.location.x, v.location.y, v.location.z, false, true, true) Freeze(CocaPlant[k], true, v.heading) - ps.entityTarget(CocaPlant[k], { - { - icon = "fa-solid fa-seedling", - label = ps.lang('targets.coke.pick'), - action = function() - if not pick(k) then return end - end - } - }) + ps.entityTarget(CocaPlant[k], targetOps(k)) end end end) @@ -67,7 +64,10 @@ for k, v in pairs (GlobalState.MDDrugsLocs.MakePowder) do label = ps.lang('.targets.coke.pick'), icon = 'fa-solid fa-seedling', action = function() - if not ps.hasItem('coca_leaf') then return end + if not ps.hasItem('coca_leaf') then + ps.notify('You Need A Coke Leaf') + return + end if not ps.progressbar(ps.lang('Coke.makepow'), 4000, 'uncuff') then return end TriggerServerEvent("md-drugs:server:makepowder", k) end, @@ -94,6 +94,7 @@ for k, v in pairs (GlobalState.MDDrugsLocs.CuttingCoke) do } }) end + for k, v in pairs (GlobalState.MDDrugsLocs.BaggingCoke) do ps.boxTarget('bagcoke'..k, v.loc, {length = 1.0, width = 1.0, height = 1.0, rotation = 180.0}, { { @@ -109,4 +110,4 @@ for k, v in pairs (GlobalState.MDDrugsLocs.BaggingCoke) do end } }) -end +end \ No newline at end of file diff --git a/client/cornerselling.lua b/client/cornerselling.lua index 20731a4..be59564 100644 --- a/client/cornerselling.lua +++ b/client/cornerselling.lua @@ -1,115 +1,173 @@ local sell = false -local sold = false -local targbusy = false local inZone = false -local active = false +local buyers = {} -local function reset(targ) +local function walkAway(targ) FreezeEntityPosition(targ, false) ClearPedTasks(targ) - local coords = GetEntityCoords(targ) - TaskWanderInArea(targ, coords.x, coords.y, coords.z, 100.0, 2, 10.0) - Wait(10000) - DeletePed(targ) - targbusy = false - sold = true - active = false -end - -local function walkAway(targ) - FreezeEntityPosition(targ, false) - ClearPedTasks(targ) - local coords = GetEntityCoords(targ) - TaskWanderInArea(targ, coords.x, coords.y, coords.z, 100.0, 2, 10.0) - Wait(10000) - DeletePed(targ) - targbusy = false - active = false end local function sellDrug(item, amount, price, targ) - PoliceCall(20) - targbusy = true - if IsPedInAnyVehicle(PlayerPedId(), true) then - Notify(Lang.Cornerselling.inveh, 'error') - reset(targ) - return end - if not progressbar(string.format(Lang.Cornerselling.selling, GetLabel(item), price), 4000, 'uncuff') then return end + -- PoliceCall(20) + if ps.vehicleData() then + Notify(ps.lang('Cornerselling.inveh', 'error')) + walkAway(targ) + return + end + + if not ps.progressbar(string.format(ps.lang('Cornerselling.selling', GetLabel(item), price)), 4000, 'uncuff') then walkAway(targ) return end + buyers[targ] = 'sold' TriggerServerEvent('md-drugs:server:sellCornerDrugs', item, amount, price) - reset(targ) + walkAway(targ) end local function deny(targ) - PoliceCall(20) - targbusy = true - if not progressbar(Lang.Cornerselling.deny, 4000, 'argue5') then return end - reset(targ) + -- PoliceCall(20) + buyers[targ] = 'sold' + if not ps.progressbar(ps.lang('Cornerselling.deny'), 4000, 'argue5') then return end + walkAway(targ) +end + +local function findPed() + local targ = nil + repeat + Wait(100) + targ = ps.getNearestPed(GetEntityCoords(PlayerPedId()), 8) + + if IsPedInAnyVehicle(targ, false) or GetEntityHealth(targ) == 0 or not IsPedHuman(targ) then + targ = nil + end + if buyers[targ] then + targ = nil + end + if inZone then + targ = nil + end + until targ ~= nil + + buyers[targ] = true + ps.drawText('Waiting For Customer') + + repeat + Wait(1000) + TaskGoToCoordAnyMeans(targ, GetEntityCoords(PlayerPedId()), 1.0, 0, 0, 0, 0) + until #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(targ)) < 2.0 + + TaskTurnPedToFaceEntity(targ, PlayerPedId(), -1) + ps.hideText() + CreateThread(function() + Wait(45000) + walkAway(targ) + buyers[targ] = 'sold' + end) + return targ +end + +local function checkItems() + local count = 0 + for k, v in pairs (GlobalState.DrugNames) do + if ps.hasItem(v) then + count = count + 1 + break + end + end + if count == 0 then ps.notify(ps.lang('Cornerselling.nodrugs', 'error')) return false end + return true end function Cornersell() - if active then return false end - local targ = lib.GetClosestPed(GetEntityCoords(PlayerPedId()), 8) - if targ == nil then return end - if IsPedInAnyVehicle(targ, false) or GetEntityHealth(targ) == 0 or not IsPedHuman(targ) then return end - local data = ps.callback('md-drugs:server:cornerselling:getAvailableDrugs', false, targ) - if data.item == 'nothing' then Notify(Lang.Cornerselling.nodrugs, 'error') sell = false FreezeEntityPosition(targ, false) ClearPedTasks(targ) active = false return false end - TaskGoToCoordAnyMeans(targ, GetEntityCoords(PlayerPedId()), 1.0, 0, 0, 0, 0) - active = true - repeat - Wait(1000) - until #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(targ)) < 2.0 - lib.requestAnimDict("rcmme_tracey1") - TaskStartScenarioInPlace(targ, "WORLD_HUMAN_STAND_IMPATIENT_UPRIGHT", 0, false) FreezeEntityPosition(targ, true) - AddMultiModel(data.ped, { - { label = string.format(Lang.targets.CornerSell.sell, data.amount, GetLabel(data.item), data.price), icon ="fa-solid fa-money-bill", - action = function() sellDrug(data.item, data.amount, data.price, targ) end, - canInteract = function() - if not targbusy then return true end end, - }, - { label = Lang.targets.CornerSell.deny, icon = "fa-solid fa-person-harassing", - action = function() deny(targ) end, - canInteract = function() - if not targbusy then return true end end, + if inZone then sell = false return end + + if not sell then + return + end + + local hasDrugs = checkItems() + if not hasDrugs then + sell = false + return + end + + ps.drawText('Searching For Nearby Customers') + + local targ = findPed() + local data = ps.callback('md-drugs:server:cornerselling:getAvailableDrugs', targ) + + if data == false then + sell = false + return + end + + if data == 'robbed' then + TaskGoStraightToCoord(targ, -1858.232910, -1242.395630, 8.60510, 100.0, -1, 0.0, 0.0) + SetPedMoveRateOverride(targ, 10.0) + local got = false + ps.entityTarget(targ, { + { + label = "Take Back Drugs", + icon ="fa-solid fa-money-bill", + action = function() + got = true + TriggerServerEvent('md-drugs:server:getBackRobbed') + Cornersell() + end, + canInteract = function() + if IsEntityDead(targ) and not got then + return true + end + end, }}, nil) - local timer = 45 - repeat - Wait(1000) - timer = timer - 1 - until sold or timer == 0 - if sold then sold = false return true end - if timer == 0 then Notify(Lang.Cornerselling.timeout, 'error') targbusy = true walkAway(targ) return false end + else + ps.requestAnim("rcmme_tracey1") + TaskStartScenarioInPlace(targ, "WORLD_HUMAN_STAND_IMPATIENT_UPRIGHT", 0, false) + FreezeEntityPosition(targ, true) + ps.entityTarget(data.ped, { + { + label = string.format(ps.lang('targets.CornerSell.sell', data.amount, GetLabel(data.item), data.price)), + icon ="fa-solid fa-money-bill", + action = function() + sellDrug(data.item, data.amount, data.price, targ) + Cornersell() + end, + canInteract = function() + if buyers[targ] ~= 'sold' and sell then + return true + end + end, + }, + { + label = ps.lang('targets.CornerSell.deny'), + icon = "fa-solid fa-person-harassing", + action = function() + deny(targ) + walkAway(targ) + Cornersell() + end, + canInteract = function() + if buyers[targ] == true and sell then + return true + end + end + } + }) + end end RegisterNetEvent('md-drugs:client:cornerselling', function() - if not GetCops(QBConfig.MinimumDrugSalePolice) then return end - if inZone then Notify(Lang.Cornerselling.no, 'error') return end - local has = ps.callback('md-drugs:server:hasDrugs', false) - if has then - if sell then - TriggerServerEvent('md-drugs:server:cornerselling:stop') - Notify(Lang.Cornerselling.stop, 'error') - sell = false - active = false - else - sell = true - Notify(Lang.Cornerselling.start, 'success') - repeat - Wait(1000) - Cornersell() - until not sell - end + if sell then + sell = false + ps.hideText() + ps.notify(ps.lang('Cornerselling.stopped', 'error')) else - Notify(Lang.Cornerselling.nodrugs, 'error') + sell = true + ps.notify(ps.lang('Cornerselling.started', 'success')) + Cornersell() end end) CreateThread(function() -for k, v in pairs (QBConfig.NoSellZones) do - local box = lib.zones.box({ coords = v.loc, size = vec3(v.width, v.length, v.height), rotation = 180.0, debug = false, - onEnter = function() inZone = true end, onExit = function() inZone = false end}) -end -end) - -RegisterNetEvent('md-drugs:client:cornerselling:remove', function(ped) -DeletePed(ped) + for k, v in pairs (QBConfig.NoSellZones) do + local box = lib.zones.box({ coords = v.loc, size = vec3(v.width, v.length, v.height), rotation = 180.0, debug = false, + onEnter = function() inZone = true end, onExit = function() inZone = false end}) + end end) \ No newline at end of file diff --git a/client/heroin.lua b/client/heroin.lua index 716f175..98eaf5a 100644 --- a/client/heroin.lua +++ b/client/heroin.lua @@ -2,20 +2,79 @@ local PoppyPlants = {} local herointable = false local dirty = false +local function pickher(loc) + if not ps.progressbar(Lang.Heroin.pick, 4000, 'uncuff') then return end + TriggerServerEvent("heroin:pickupCane", loc) +end + +local function pickOps(loc) + return { + { + icon = "fa-solid fa-seedling", + label = ps.lang('Heroin.pick'), + action = function() pickher(loc) end + } + } +end + local function createLabKit(coord, head) local heroinlabkit = CreateObject("v_ret_ml_tablea", coord.x, coord.y, coord.z - 1, true, false,false) SetEntityHeading(heroinlabkit, head) PlaceObjectOnGroundProperly(heroinlabkit) - AddMultiModel(heroinlabkit, { - {data = heroinlabkit, event = "md-drugs:client:heatliquidheroin", icon = "fa-solid fa-temperature-high", label = Lang.targets.heroin.cook, canInteract = function() if not dirty then return true end end}, - {data = heroinlabkit, event = "md-drugs:client:getheroinkitback", icon = "fas fa-box-circle-check", label = Lang.targets.heroin.up, canInteract = function() if not dirty then return true end end}, - {data = heroinlabkit, event = "md-drugs:client:cleanheroinlabkit",icon = "fa-solid fa-hand-sparkles",label = Lang.targets.heroin.clean,canInteract = function() if dirty then return true end end}},heroinlabkit) + ps.entityTarget(heroinlabkit, { + { + icon = "fa-solid fa-temperature-high", + label = ps.lang('Heroin.cook'), + action = function() + if not ps.hasItem('emptyvial') then return end + if not minigame() then + dirty = true + TriggerServerEvent("md-drugs:server:failheatingheroin") + ps.requestPTFX("core") + local heroinkit = StartParticleFxLoopedOnEntity("exp_air_molotov", heroinlabkit, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.5, false, false, false) + SetParticleFxLoopedAlpha(heroinkit, 3.0) + SetPedToRagdoll(PlayerPedId(), 1300, 1300, 0, 0, 0, 0) + return end + if not ps.progressbar(ps.lang('Heroin.success'), 4000, 'uncuff') then return end + TriggerServerEvent("md-drugs:server:heatliquidheroin") + end, + canInteract = function() + if not dirty then return true end + return false + end + }, + { + icon = "fas fa-box-circle-check", + label = ps.lang('Heroin.up'), + action = function() + if not ps.progressbar(ps.lang('Heroin.pickup'), 4000, 'uncuff') then return end + herointable = false + DeleteObject(heroinlabkit) + TriggerServerEvent("md-drugs:server:getheroinlabkitback") + end, + canInteract = function() + if not dirty then return true end + return false + end + }, + { + event = "md-drugs:client:cleanheroinlabkit", + icon = "fa-solid fa-hand-sparkles", + label = ps.lang('Heroin.clean'), + action = function() + if not ps.hasItem('cleaningkit') then return end + if not ps.progressbar(ps.lang('Heroin.clean'), 4000, 'clean') then return end + local done = ps.callback('removeCleaningkit', false) + if done then dirty = false end + end, + canInteract = function() + if dirty then return true end + return false + end + }}) end -local function pickher(loc) - if not progressbar(Lang.Heroin.pick, 4000, 'uncuff') then return end - TriggerServerEvent("heroin:pickupCane", loc) -end + RegisterNetEvent('heroin:respawnCane', function(loc) local v = GlobalState.PoppyPlants[loc] @@ -23,7 +82,7 @@ RegisterNetEvent('heroin:respawnCane', function(loc) if not PoppyPlants[loc] then PoppyPlants[loc] = CreateObject(hash, v.location, false, true, true) Freeze(PoppyPlants[loc], true, v.heading) - AddSingleModel(PoppyPlants[loc], {icon = "fa-solid fa-seedling", label = Lang.targets.heroin.pick, action = function() pickher(loc) end}, loc ) + ps.entityTarget(PoppyPlants[loc], pickOps(loc), loc) end end) @@ -39,7 +98,7 @@ RegisterNetEvent("heroin:init", function() if not v.taken then PoppyPlants[k] = CreateObject(hash, v.location.x, v.location.y, v.location.z, false, true, true) Freeze(PoppyPlants[k], true, v.heading) - AddSingleModel(PoppyPlants[k], {icon = "fa-solid fa-seedling", label = Lang.targets.heroin.pick, action = function() pickher(k) end}, k ) + ps.entityTarget(PoppyPlants[k], pickOps(k)) end end end) @@ -55,73 +114,71 @@ end) end end) -RegisterNetEvent("md-drugs:client:dryplant", function(data) - if not progressbar(Lang.Heroin.dryout, 4000, 'uncuff') then return end - TriggerServerEvent("md-drugs:server:dryplant",data.data) -end) +for k, v in pairs (GlobalState.MDDrugsLocs.dryplant) do + ps.boxTarget('dryHeroin'..k, v.loc, {length = v.l, width = v.w, height = 1.0, rotation = v.rot}, { + { + label = ps.lang('targets.heroin.dry'), + icon = 'fa-solid fa-temperature-high', + action = function() + if not ps.progressbar(ps.lang('Heroin.dryout'), 4000, 'uncuff') then return end + TriggerServerEvent("md-drugs:server:dryplant", k) + end, + canInteract = function() + return handleGang(v.gang) + end + } + }) +end -RegisterNetEvent("md-drugs:client:cutheroin", function(data) - if not ItemCheck('bakingsoda') then return end - if not progressbar(Lang.Heroin.cutting, 4000, 'uncuff') then return end - TriggerServerEvent("md-drugs:server:cutheroin", data.data) -end) +for k, v in pairs (GlobalState.MDDrugsLocs.cutheroinone) do + ps.boxTarget('cutHeroin'..k, v.loc, {length = v.l, width = v.w, height = 1.0, rotation = v.rot}, { + { + label = ps.lang('targets.heroin.cut'), + icon = 'fa-solid fa-seedling', + action = function() + if not ps.hasItem('bakingsoda') then return end + if not ps.progressbar(ps.lang('Heroin.cutting'), 4000, 'uncuff') then return end + TriggerServerEvent("md-drugs:server:cutheroin", k) + end, + canInteract = function() + return handleGang(v.gang) + end + } + }) +end RegisterNetEvent("md-drugs:client:buyheroinlabkit", function() - if not progressbar(Lang.Heroin.secret, 4000, 'uncuff') then return end + if not ps.progressbar(ps.lang('Heroin.secret'), 4000, 'uncuff') then return end TriggerServerEvent("md-drugs:server:getheroinlabkit") end) ps.registerCallback("md-drugs:client:setheroinlabkit", function() - if herointable then - Notify(Lang.Heroin.tableout, 'error') + if herointable then + ps.notify(ps.lang('Heroin.tableout'), 'error') return false else herointable = true local location, head = StartRay() if not location then herointable = false return end - if not progressbar(Lang.Heroin.table, 4000, 'uncuff') then return end + if not ps.progressbar(ps.lang('Heroin.table'), 4000, 'uncuff') then return end createLabKit(location, head) return true, location end end) -RegisterNetEvent("md-drugs:client:heatliquidheroin", function(data) - local loc, head = GetEntityCoords(data.data), GetEntityHeading(data.data) - if not ItemCheck('emptyvial') then return end - if not minigame() then - dirty = true - TriggerServerEvent("md-drugs:server:failheatingheroin") - loadParticle("core") - local heroinkit = StartParticleFxLoopedOnEntity("exp_air_molotov", data.data, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.5, false, false, false) - SetParticleFxLoopedAlpha(heroinkit, 3.0) - SetPedToRagdoll(PlayerPedId(), 1300, 1300, 0, 0, 0, 0) - return end - if not progressbar(Lang.Heroin.success, 4000, 'uncuff') then return end - TriggerServerEvent("md-drugs:server:heatliquidheroin") -end) - -RegisterNetEvent("md-drugs:client:cleanheroinlabkit", function(data) - if not ItemCheck('cleaningkit') then return end - if not progressbar(Lang.Heroin.clean, 4000, 'clean') then return end - local done = ps.callback('removeCleaningkit', false) - if done then dirty = false end -end) - -RegisterNetEvent("md-drugs:client:deletedirtyheroin", function(data) - local location,head = GetEntityCoords(data), GetEntityHeading(data) - DeleteObject(data) - createLabKit(location, head) -end) - -RegisterNetEvent("md-drugs:client:getheroinkitback", function(data) - if not progressbar(Lang.Heroin.pickup, 4000, 'uncuff') then return end - herointable = false - DeleteObject(data.data) - TriggerServerEvent("md-drugs:server:getheroinlabkitback") -end) - -RegisterNetEvent("md-drugs:client:fillneedle", function(data) - if not minigame() then TriggerServerEvent("md-drugs:server:failheroin", data.data) return end - if not progressbar(Lang.Heroin.needles, 4000, 'uncuff') then return end - TriggerServerEvent("md-drugs:server:fillneedle", data.data) -end) \ No newline at end of file +for k, v in pairs (GlobalState.MDDrugsLocs.fillneedle) do + ps.boxTarget('fillNeedle'..k, v.loc, {length = v.l, width = v.w, height = 1.0, rotation = v.rot}, { + { + label = ps.lang('targets.heroin.fill'), + icon = 'fa-solid fa-syringe', + action = function() + if not minigame() then TriggerServerEvent("md-drugs:server:failheroin", k) return end + if not ps.progressbar(ps.lang('Heroin.needles'), 4000, 'uncuff') then return end + TriggerServerEvent("md-drugs:server:fillneedle", k) + end, + canInteract = function() + return handleGang(v.gang) + end + } + }) +end \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index 6720e30..e1709cf 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -12,6 +12,8 @@ client_scripts { server_scripts { 'server/functions.lua', + 'server/locations.lua', + 'server/recipes.lua', 'serverRun.lua', '@oxmysql/lib/MySQL.lua', } diff --git a/server/cornerselling.lua b/server/cornerselling.lua index 32f58e3..4dfa634 100644 --- a/server/cornerselling.lua +++ b/server/cornerselling.lua @@ -1,4 +1,4 @@ -local QBCore = exports['qb-core']:GetCoreObject() + local DrugDeals = {} local Drugs = { ["weed_white-widow"] = {rep = 1,min = 15, max = 24 }, @@ -121,75 +121,108 @@ local Drugs = { ["cupofdextro"] = {rep = 1,min = 18, max = 40}, } -ps.registerCallback('md-drugs:server:cornerselling:getAvailableDrugs', function(source, ped) - local Player = getPlayer(source) - local rep = getRep(source, 'cornerselling') - if not Player then return nil end - local type = 0 - for k, v in pairs(Drugs) do - local item = Player.Functions.GetItemByName(k) - if item and type == 0 then - type = type + 1 - Log(GetName(source) .. ' Allowed To Sell ' .. item.name .. '!' , 'cornerselling') - local amount = math.random(1,item.amount) - 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 = item.name, amount = amount, price = result, cid = Player.PlayerData.citizenid, ped = ped}) - return {item = item.name, amount = amount, price = result, ped = ped} +local drugsNames = {} +for k, v in pairs(Drugs) do + table.insert(drugsNames, k) +end +GlobalState.DrugNames = drugsNames +local robChance = 1 -- Chance To Be Robbed +local RobbedDrugs = {} + +local function beingRobbed(source, item, amount, ped) + local src = source + local math = math.random(1,100) + if math <= robChance then + ps.removeItem(src, item, amount) + ps.notify(src, 'You Got Robbed Nerd', 'error') + RobbedDrugs[ps.getIdentifier(source)] = {item = item, amount = amount, ped = ped} + return true + else + return false + end +end + +local function getDrugBack(source, item, amount) + local src = source + if RobbedDrugs[ps.getIdentifier(source)] then + if RobbedDrugs[ps.getIdentifier(source)].item == item and RobbedDrugs[ps.getIdentifier(source)].amount == amount then + ps.addItem(src, item, amount) + ps.notify(src, 'You Got Your Drugs Back', 'success') + RobbedDrugs[ps.getIdentifier(source)] = nil + return true end end - if type == 0 then - return {item = 'nothing', amount = 0, price = 0, ped = ped} +end + +ps.registerCallback('md-drugs:server:cornerselling:getAvailableDrugs', function(source, ped) + local Player = ps.getPlayer(source) + local rep = getRep(source, 'cornerselling') + if not Player then return nil end + for k, v in pairs(Drugs) do + local item = ps.getItemCount(source, k) or 0 + if item >= 1 then + local maths = math.random(1,100) + if maths <= robChance then + beingRobbed(source, k, item, ped) + return 'robbed' + else + if item > 15 then item = 15 end + local amount = math.random(1, item) + local price = (math.random(Drugs[k]['min'], Drugs[k]['max']) * amount) * rep.price + DrugDeals[ps.getIdentifier(source)] = {item = k, amount = amount, price = math.floor(price), ped = ped} + return DrugDeals[ps.getIdentifier(source)] + end + end end + return false end) ps.registerCallback('md-drugs:server:hasDrugs', function(source) - local Player = getPlayer(source) for k, v in pairs(Drugs) do - local item = Player.Functions.GetItemByName(k) - 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 == Player.PlayerData.citizenid then - if v.item == item then - if v.amount == amount then - if v.price == price then - if RemoveItem(src, item, amount) then - if QBConfig.MarkedBills then - local info = { - worth = price - } - Player.Functions.AddItem('markedbills', 1, false, info ) - elseif QBConfig.CustomDirtyMoney == true then - AddItem(src, QBConfig.CustomDirtyMoneyitem, price) - else - Player.Functions.AddMoney('cash', price) - end - 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 - end - end - end + if not isIn then return false end + + if DrugDeals[ps.getIdentifier(src)] then + if DrugDeals[ps.getIdentifier(src)].item == item and DrugDeals[ps.getIdentifier(src)].amount == amount and DrugDeals[ps.getIdentifier(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 not ps.removeItem(src, item, amount) then + ps.notify(src, 'You Do Not Have Enough Of This Item', 'error') + DrugDeals[ps.getIdentifier(src)] = nil + return + end + --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[ps.getIdentifier(src)] = nil + ps.addMoney(src, 'cash', price) + +end) + +RegisterNetEvent('md-drugs:server:getBackRobbed', function() + local tabl = RobbedDrugs[ps.getIdentifier(source)] + if tabl == nil then return end + getDrugBack(source, tabl.item, tabl.amount) + RobbedDrugs[ps.getIdentifier(source)] = nil end) lib.addCommand('cornersell', { @@ -198,18 +231,12 @@ 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 == Player.PlayerData.citizenid then - TriggerClientEvent('md-drugs:client:cornerselling:remove', src, DrugDeals[k].ped) - table.remove(DrugDeals, k) - end + if DrugDeals[ps.getIdentifier(src)] then + DrugDeals[ps.getIdentifier(src)] = nil end end) \ No newline at end of file diff --git a/server/functions.lua b/server/functions.lua index 4771245..da428b5 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -1,14 +1,25 @@ -local QBCore = exports['qb-core']:GetCoreObject() +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", "") local endpoint = 'https://api.fivemerr.com/v1/logs' local headers = { - ['Authorization'] = logapi, - ['Content-Type'] = 'application/json', - } + ['Authorization'] = logapi, + ['Content-Type'] = 'application/json', +} + +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 @@ -24,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 @@ -43,29 +48,62 @@ 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) +function getPlayer(source) local src = source - local Player = QBCore.Functions.GetPlayer(src) - return Player + if Config.Framework == 'qb' then + local Player = QBCore.Functions.GetPlayer(src) + return Player + 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 -function GetName(source) - local Player = getPlayer(source) - return Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname +function getPlayerByCid(cid) + if Config.Framework == 'qb' then + local Player = QBCore.Functions.GetPlayerByCitizenId(cid) + return Player + 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 + +function GetName(source) + local src = source + if Config.Framework == 'qb' then + local Player = getPlayer(src) + return Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname + 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) + local src = source + if Config.Framework == 'qb' then + local Player = getPlayer(src) + return Player.PlayerData.citizenid + 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) @@ -78,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) @@ -87,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 @@ -107,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 @@ -117,7 +156,13 @@ function GetLabels(item) end function CUI(item, useFunction) - QBCore.Functions.CreateUseableItem(item, useFunction) + if Config.Framework == 'qb' then + 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 function Itemcheck(source, item, amount) @@ -131,9 +176,9 @@ function Itemcheck(source, item, amount) return false end elseif inventory == 'ox' then - local items = exports.ox_inventory:GetItem(source, item, nil, false) + local items = exports.ox_inventory:GetItem(source, item, nil, false) if items.count >= amount then - return true + return true else Notifys(source, 'You Need ' .. amount .. ' Of ' .. GetLabels(item) .. ' To Do This', 'error') return false @@ -141,13 +186,55 @@ function Itemcheck(source, item, amount) end end +function hasItem(source, item, amount) + if inventory == 'qb' then + local Player = getPlayer(source) + local itemchecks = Player.Functions.GetItemByName(item) + if itemchecks and itemchecks.amount >= amount then + return true + else + return false + end + elseif inventory == 'ox' then + local items = exports.ox_inventory:GetItem(source, item, nil, false) + if items == nil then return false end + if items.count >= amount then + return true + else + return false + end + end +end + +function getItemCount(source, item) + if inventory == 'qb' then + local Player = getPlayer(source) + local itemchecks = Player.Functions.GetItemByName(item) + if itemchecks then + return itemchecks.amount + else + return false + end + elseif inventory == 'ox' then + local items = exports.ox_inventory:GetItem(source, item, nil, false) + if items == nil then + print('You are missing ' .. item) + return 0 + end + if items.count >= 1 then + return items.count + else + return 0 + end + end +end function RemoveItem(source, item, amount) if inventory == 'qb' then local Player = getPlayer(source) 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 @@ -162,16 +249,14 @@ end function AddItem(source, item, amount) if inventory == 'qb' then local Player = getPlayer(source) - if Player.Functions.AddItem(item, amount) then + if Player.Functions.AddItem(item, amount) then TriggerClientEvent(invname ..":client:ItemBox", source, QBCore.Shared.Items[item], "add", amount) return true - else + else print('Failed To Give Item: ' .. item .. ' Check Your qb-core/shared/items.lua') return false end else - local carry = exports.ox_inventory:CanCarryItem(source, item, amount) - if not carry then Notifys(source, 'You Cant Carry that Much Weight!', 'error') return false end if exports.ox_inventory:AddItem(source, item, amount) then return true else @@ -181,66 +266,85 @@ function AddItem(source, item, amount) end end +function addMoney(source, type, amount) + if Config.Framework == 'qb' then + local Player = getPlayer(source) + if Player.Functions.AddMoney(type, amount) then + return true + else + return false + end + elseif Config.Framework == 'esx' then + local Player = getPlayer(source) + if Player.addMoney(amount) then + return true + else + return false + end + elseif Config.Framework == 'qbx' then + if qbx:AddMoney(source, type, amount) then + return true + else + return false + end + end +end -function getRep(source, type) - local Player = getPlayer(source) - local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {Player.PlayerData.citizenid}) +function removeMoney(source, type, amount) + if Config.Framework == 'qb' then + local Player = getPlayer(source) + if Player.Functions.RemoveMoney(type, amount) then + return true + else + return false + end + elseif Config.Framework == 'esx' then + if type == 'bank' then + print('Does Not Support Bank Funds Removing From ESX Defaulted To Cash') + end + local Player = getPlayer(source) + if Player.getMoney() >= amount then + Player.removeMoney(amount) + return true + 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) + local table = json.encode({ + coke = 0,lsd = 0,heroin = 0,dealerrep = 0, + cornerselling = { price = QBConfig.SellLevel[1].price,rep = 0,label = QBConfig.SellLevel[1].label,level = 1} + }) + MySQL.insert('INSERT INTO drugrep SET cid = ?, drugrep = ?, name = ?', {getCid(source), table, GetName(source)}) + Wait(1000) + return json.decode(table) +end + +function getRep(source, type) + local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {getCid(source)}) if not sql[1] then - local table = json.encode({ - coke = Player.PlayerData.metadata.coke or 0, - lsd = Player.PlayerData.metadata.lsd or 0, - heroin = Player.PlayerData.metadata.heroin or 0, - dealerrep = Player.PlayerData.metadata.dealerrep or 0, - cornerselling = { - price = QBConfig.SellLevel[1].price, - rep = 0, - label = QBConfig.SellLevel[1].label, - level = 1 - } - }) - MySQL.insert('INSERT INTO drugrep SET cid = ?, drugrep = ?, name = ?', {Player.PlayerData.citizenid, table, GetName(source)}) - Wait(1000) - return json.decode(table) + local new = handleFresh(source) + return new[type] else local reps = json.decode(sql[1].drugrep) local rep = '' if reps.coke == nil then rep = reps[1] else rep = reps end - if type == 'coke' then - return rep.coke - elseif type == 'heroin' then - return rep.heroin - elseif type == 'lsd' then - return rep.lsd - elseif type == 'dealerrep' then - return rep.dealerrep - elseif type == 'cornerselling' then - return rep.cornerselling - else - print('^1 Error: No Valid Drug Rep Option Chosen') - end - return false + return rep[type] end end -function GetAllRep(source) - local Player = getPlayer(source) - local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {Player.PlayerData.citizenid}) +function GetAllRep(source) + local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {getCid(source)}) if not sql[1] then - local table = json.encode({ - coke = Player.PlayerData.metadata.coke or 0, - lsd = Player.PlayerData.metadata.lsd or 0, - heroin = Player.PlayerData.metadata.heroin or 0, - dealerrep = Player.PlayerData.metadata.dealerrep or 0, - cornerselling = { - price = QBConfig.SellLevel[1].price, - rep = 0, - label = QBConfig.SellLevel[1].label, - level = 1 - } - }) - MySQL.insert('INSERT INTO drugrep SET cid = ?, drugrep = ?, name = ?', {Player.PlayerData.citizenid, table, GetName(source)}) - Wait(1000) - return json.decode(table) + local new = handleFresh(source) + return new else local rep = json.decode(sql[1].drugrep) if rep.coke == nil then return rep[1] end @@ -248,10 +352,10 @@ 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 = ?', {Player.PlayerData.citizenid}) + local sql = MySQL.query.await('SELECT * FROM drugrep WHERE cid = ?', {getCid(source)}) local reps = json.decode(sql[1].drugrep) local update local rep = '' @@ -265,19 +369,15 @@ function AddRep(source, type, amount) update = json.encode({coke = rep.coke, heroin = rep.heroin, lsd = rep.lsd, dealerrep = rep.dealerrep, cornerselling = {label = v.label, price = v.price, rep = rep.cornerselling.rep + amount, level = k}}) end end - end - elseif type == 'coke' then - update = json.encode({coke = rep.coke + amount, heroin = rep.heroin, lsd = rep.lsd, dealerrep = rep.dealerrep, cornerselling = rep.cornerselling}) - elseif type == 'heroin' then - update = json.encode({coke = rep.coke, heroin = rep.heroin + amount, lsd = rep.lsd, dealerrep = rep.dealerrep, cornerselling = rep.cornerselling}) - elseif type == 'lsd' then - update = json.encode({coke = rep.coke, heroin = rep.heroin, lsd = rep.lsd +amount , dealerrep = rep.dealerrep, cornerselling = rep.cornerselling}) - elseif type == 'dealerrep' then - update = json.encode({coke = rep.coke, heroin = rep.heroin, lsd = rep.lsd, dealerrep = rep.dealerrep + amount, cornerselling = rep.cornerselling}) + end + if update == '' then return false end + MySQL.update('UPDATE drugrep SET drugrep = ? WHERE cid = ?', {update, getCid(source)}) + return true + else + rep[type] = rep[type] + amount + MySQL.update('UPDATE drugrep SET drugrep = ? WHERE cid = ?', {json.encode(rep), getCid(source)}) + return true end - if update == '' then return false end - MySQL.update('UPDATE drugrep SET drugrep = ? WHERE cid = ?', {update, Player.PlayerData.citizenid}) - return true end lib.addCommand('addCornerSellingTOREP', { @@ -290,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 @@ -314,39 +414,110 @@ end function getCops() 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 + if Config.Framework == 'qb' then + 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 + elseif Config.Framework == 'esx' then + local players = ESX.GetPlayers() + for k, v in pairs(players) do + local xPlayer = ESX.GetPlayerFromId(v) + if xPlayer.job.name == 'police' and xPlayer.job.onduty then + amount = amount + 1 + end + end + return amount + elseif Config.Framework == 'qbx' then + return qbx:GetDutyCountType('leo') end - return amount end -ps.registerCallback('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 +function getNear(src) + if Config.Framework == 'qb' then + local near = {} + local players = QBCore.Functions.GetPlayers() + for k, v in pairs (players) do + local targ = QBCore.Functions.GetPlayerByCitizenId(v.PlayerData.citizenid) + local tname = GetName(v.PlayerData.source) + local ped, tped = GetPlayerPed(src), GetPlayerPed(v.PlayerData.source) + local dist = #(GetEntityCoords(ped) - GetEntityCoords(tped)) + if dist < 5.0 then + table.insert(near, {label = tname, value = targ.PlayerData.citizenid}) + end + end + return near + elseif Config.Framework == 'esx' then + local near = {} + local players = ESX.GetPlayers() + for k, v in pairs (players) do + local targ = ESX.GetPlayerFromId(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 + 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 - return amount +end + +function handleCornersell(source, item, amount, price) + if RemoveItem(source, item, amount) then + if inventory == 'qb' then + local Player = getPlayer(source) + if QBConfig.MarkedBills == true then + Player.Functions.AddItem('markedbills',1,false, {worth = price}) + return true + end + if QBConfig.CustomDirtyMoney == true then + AddItem(source, QBConfig.CustomDirtyMoneyitem,price) + return true + end + Player.Functions.AddMoney('cash', price) + elseif inventory == 'ox' then + AddItem(source, 'black_money', price) + return true + end + else + return false + end +end + +lib.callback.register('md-drugs:server:GetCoppers', function(source, cb, args) + return getCops() end) -ps.registerCallback('md-drugs:server:GetRep', function(source, cb, args) - local src = source +lib.callback.register('md-drugs:server:GetRep', function(source, cb, args) 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) @@ -354,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/server/heroin.lua b/server/heroin.lua index efa3de1..9c41ccb 100644 --- a/server/heroin.lua +++ b/server/heroin.lua @@ -1,4 +1,5 @@ local QBCore = exports['qb-core']:GetCoreObject() + local prices = { heroinlabkitprice = 10000 } @@ -38,10 +39,9 @@ function heroinCooldown(loc) end ps.registerCallback('removeCleaningkit', function(source) - local Player = getPlayer(source) for k, v in pairs(heroinLabKits) do - if v.ownerid == Player.PlayerData.citizenid then - RemoveItem(source, 'cleaningkit', 1) + if v.ownerid == ps.getIdentifier(source) then + ps.removeItem(source, 'cleaningkit', 1) return true end end @@ -49,20 +49,21 @@ ps.registerCallback('removeCleaningkit', function(source) end) RegisterServerEvent("heroin:pickupCane", function(loc) - if CheckDist(source, h[loc].location) then return end + local src = source + if ps.checkDistance(src, h[loc].location, 3.0) then return end if not h[loc].taken then h[loc].taken = true GlobalState.PoppyPlants = h TriggerClientEvent("heroin:removeCane", -1, loc) heroinCooldown(loc) - AddItem(source, 'poppyresin', 1) + ps.addItem(src, 'poppyresin', 1) end end) RegisterServerEvent('md-drugs:server:dryplant', function(num) local src = source - if not checkLoc(source, 'dryplant', num) then return end - if not Itemcheck(source, 'poppyresin', 1) then return end + if not ps.checkDistance(src, GlobalState.MDDrugsLocs.dryplant[num].loc, 3.0) then return end + if not ps.hasItem(src, 'poppyresin', 1) then return end if Config.TierSystem then local heroin = getRep(src, 'heroin') if heroin <= Config.Tier1 then @@ -72,28 +73,28 @@ RegisterServerEvent('md-drugs:server:dryplant', function(num) else if not GetRecipe(src, 'heroin', 'dryheroin', 'tier3') then return end end - else - if not GetRecipe(src, 'heroin', 'dryheroin', 'tier1') then return end + return end + if not GetRecipe(src, 'heroin', 'dryheroin', 'tier1') then return end end) RegisterServerEvent('md-drugs:server:cutheroin', function(num) local src = source - local Player = getPlayer(src) - if not checkLoc(source, 'cutheroinone', num) then return end - if not Itemcheck(src, 'bakingsoda', 1) then return end + if not ps.checkDistance(src, GlobalState.MDDrugsLocs.cutheroinone[num].loc, 3.0) then return end + if not ps.hasItem(src, 'bakingsoda', 1) then return end if Config.TierSystem then - local rawh = Player.Functions.GetItemByName('heroin') - local rawh2 = Player.Functions.GetItemByName('heroinstagetwo') - local rawh3 = Player.Functions.GetItemByName('heroinstagethree') - if rawh then - if not GetRecipe(src, 'heroin', 'cutheroin', 'tier1') then return end - elseif rawh2 then - if not GetRecipe(src, 'heroin', 'cutheroin', 'tier2') then return end - elseif rawh3 then - if not GetRecipe(src, 'heroin', 'cutheroin', 'tier3') then return end - else - Notifys(src, Lang.Heroin.noheroin, "error") + local itemList = { + heroin = 'tier1', + heroinstagetwo = 'tier2', + heroinstagethree = 'tier3' + } + for k, v in pairs(itemList) do + local cuth = ps.hasItem(src, k) + if cuth then + if not GetRecipe(src, 'heroin', 'cutheroin', v) then return end + AddRep(src, 'heroin') + return + end end else if not GetRecipe(src, 'heroin', 'cutheroin', 'tier1') then return end @@ -102,22 +103,19 @@ end) RegisterServerEvent('md-drugs:server:getheroinlabkit', function() local src = source - local Player = getPlayer(src) - if not checkLoc(source, 'singleSpot', 'buyheroinlabkit') then return end - local has = Player.Functions.GetItemByName('heroinlabkit') - if has then Notifys(src, Lang.Heroin.haskit, 'error') return end - if Player.Functions.RemoveMoney('cash', prices.heroinlabkitprice) then - AddItem(src, 'heroinlabkit', 1) + if not ps.checkDistance(src, GlobalState.MDDrugsLocs.singleSpot.buyheroinlabkit, 3.0) then return end + local has = ps.hasItem(src, 'heroinlabkit') + if has then ps.notify(src, Lang.Heroin.haskit, 'error') return end + if ps.removeMoney(src, 'cash', prices.heroinlabkitprice) then + ps.addItem(src, 'heroinlabkit', 1) else - Notifys(src, 'You Need '.. prices.heroinlabkitprice .. ' In Cash For This', 'error') + ps.notify(src, 'You Need '.. prices.heroinlabkitprice .. ' In Cash For This', 'error') end end) local function hasHKit(src) - local src = source - local Player = getPlayer(src) for k, v in pairs(heroinLabKits) do - if v.ownerid == Player.PlayerData.citizenid then + if v.ownerid == ps.getIdentifier(src) then return true end end @@ -126,51 +124,49 @@ end RegisterServerEvent('md-drugs:server:getheroinlabkitback', function() local src = source - local Player = getPlayer(src) if not hasHKit(src) then return end for k, v in pairs (heroinLabKits) do - if v.ownerid == Player.PlayerData.citizenid then + if v.ownerid == ps.getIdentifier(src) then table.remove(heroinLabKits, k) - AddItem(src, 'heroinlabkit', 1) + ps.addItem(src, 'heroinlabkit', 1) end end end) -CUI('heroinlabkit', function(source, item) +ps.createUseable('heroinlabkit', function(source, item) local src = source - local Player = getPlayer(src) - if not Itemcheck(source, 'heroinlabkit', 1) then return end + if not ps.hasItem(src, 'heroinlabkit', 1) then return end local placed, loc = ps.callback('md-drugs:client:setheroinlabkit', src) if placed then - RemoveItem(src, 'heroinlabkit', 1) + ps.removeItem(src, 'heroinlabkit', 1) table.insert(heroinLabKits, { - src = src, - ownerid = Player.PlayerData.citizenid, + src = src, + ownerid = ps.getIdentifier(src), coords = loc, - name = GetName(src) + name = ps.getPlayerName(src) }) - Notifys(src, Lang.Heroin.placed, "success") + ps.notify(src, Lang.Heroin.placed, "success") end end) RegisterServerEvent('md-drugs:server:heatliquidheroin', function() -local src = source -local Player = getPlayer(src) + local src = source if not hasHKit(src) then return end - if not Itemcheck(source, 'emptyvial', 1) then return end + if not ps.itemCheck(src, 'emptyvial', 1) then return end if Config.TierSystem then - local cuth = Player.Functions.GetItemByName('heroincut') - local cuth2 = Player.Functions.GetItemByName('heroincutstagetwo') - local cuth3 = Player.Functions.GetItemByName('heroincutstagethree') - if cuth then - if not GetRecipe(src, 'heroin', 'fillvial', 'tier1') then return end - elseif cuth2 then - if not GetRecipe(src, 'heroin', 'fillvial', 'tier2') then return end - elseif cuth3 then - if not GetRecipe(src, 'heroin', 'fillvial', 'tier3') then return end - else - Notifys(src, 'no cut heroin', "error") + local itemList = { + heroincut = 'tier1', + heroincutstagetwo = 'tier2', + heroincutstagethree = 'tier3' + } + for k, v in pairs(itemList) do + local cuth = ps.hasItem(src, k) + if cuth then + if not GetRecipe(src, 'heroin', 'fillvial', v) then return end + AddRep(src, 'heroin') + return + end end else if not GetRecipe(src, 'heroin', 'fillvial', 'tier1') then return end @@ -178,46 +174,46 @@ local Player = getPlayer(src) end) RegisterServerEvent('md-drugs:server:failheatingheroin', function() -local src = source -local Player = getPlayer(src) -if not hasHKit(src) then return end -local cuth = Player.Functions.GetItemByName('heroincut') -local cuth2 = Player.Functions.GetItemByName('heroincutstagetwo') -local cuth3 = Player.Functions.GetItemByName('heroincutstagethree') - if cuth then - RemoveItem(src, 'heroincut', 1) - Notifys(src,Lang.Heroin.fail, "error") - elseif cuth2 then - RemoveItem(src, 'heroincutstagetwo', 1) - Notifys(src,Lang.Heroin.fail, "error") - elseif cuth3 then - RemoveItem(src, 'heroincutstagethree', 1) - Notifys(src,Lang.Heroin.fail, "error") + local src = source + if not hasHKit(src) then return end + local itemList = { + heroincut = 1, + heroincutstagetwo = 1, + heroincutstagethree = 1 + } + for k, v in pairs(itemList) do + local cuth = ps.hasItem(src, k) + if cuth then + ps.removeItem(src, k, v) + ps.notify(src, Lang.Heroin.fail, "error") + return + end end end) RegisterServerEvent('md-drugs:server:fillneedle', function(num) local src = source - local Player = getPlayer(src) - if not checkLoc(source, 'fillneedle', num) then return end - if not Itemcheck(src, 'needle', 1) then return end + if not ps.checkDistance(src, GlobalState.MDDrugsLocs.fillneedle[num].loc, 3.0) then + ps.notify(src, Lang.Heroin.noloc, 'error') + return + end + if not ps.hasItem(src, 'needle', 1) then return end if Config.TierSystem then - local heroin = getRep(src, 'heroin') - local vh = Player.Functions.GetItemByName('heroinvial') - local vh2 = Player.Functions.GetItemByName('heroinvialstagetwo') - local vh3 = Player.Functions.GetItemByName('heroinvialstagethree') - if vh then - if not GetRecipe(src, 'heroin', 'fillneedle', 'tier1') then return end - AddRep(src, 'heroin') - elseif vh2 then - if not GetRecipe(src, 'heroin', 'fillneedle', 'tier2') then return end - AddRep(src, 'heroin') - elseif vh3 then - if not GetRecipe(src, 'heroin', 'fillneedle', 'tier3') then return end - AddRep(src, 'heroin') - else - Notifys(src,Lang.Heroin.nofill, "error") + local itemList = { + {item = 'heroinvial', tier = 'tier1', log = ' Filled Heroin Needle'}, + {item = 'heroinvialstagetwo', tier = 'tier2', log = ' Filled Heroin Needle tier 2'}, + {item = 'heroinvialstagethree', tier = 'tier3', log = ' Filled Heroin Needle tier 3'} + } + for k, v in pairs(itemList) do + local vh = ps.hasItem(src, v.item) + if vh then + if not GetRecipe(src, 'heroin', 'fillneedle', v.tier) then return end + AddRep(src, 'heroin') + Log(ps.getPlayerName(src) .. v.log, 'heroin') + return + end end + ps.notify(src,Lang.Heroin.nofill, "error") else if not GetRecipe(src, 'heroin', 'fillneedle', 'tier1') then return end end @@ -225,28 +221,32 @@ end) RegisterServerEvent('md-drugs:server:failheroin', function() local src = source - local Player = getPlayer(src) - Log(GetName(src) ..' Sucks And Burned Their Heroin', 'heroin') + Log(ps.getPlayerName(src) ..' Sucks And Burned Their Heroin', 'heroin') if Config.TierSystem then - local vh = Player.Functions.GetItemByName('heroinvial') - local vh2 = Player.Functions.GetItemByName('heroinvialstagetwo') - local vh3 = Player.Functions.GetItemByName('heroinvialstagethree') - if vh then RemoveItem(src, 'heroinvialstagethree', 1 ) - elseif vh2 then RemoveItem(src, 'heroinvialstagetwo', 1) - elseif vh3 then RemoveItem(src, 'heroinvial', 1) + local itemList = { + heroinvial = 1, + heroinvialstagetwo = 1, + heroinvialstagethree = 1 + } + for k, v in pairs (itemList) do + local cuth = ps.hasItem(src, k) + if cuth then + ps.removeItem(src, k, v) + ps.notify(src, Lang.Heroin.failneedle, "error") + return + end end else - RemoveItem(src, 'heroinvial', 1) + ps.removeItem(src, 'heroinvial', 1) end end) AddEventHandler('playerDropped', function() local src = source - local Player = getPlayer(src) for k, v in pairs(heroinLabKits) do if v.src == src then table.remove(heroinLabKits, k) - AddItem(src, 'heroinlabkit', 1) + ps.addItem(src, 'heroinlabkit', 1) end end end) \ No newline at end of file diff --git a/shared/config.lua b/shared/config.lua index be46299..ada6c77 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -1,6 +1,6 @@ Config = {} --Ignore. ps = exports.ps_lib:init() -ps.insertLang("en") +ps.loadLangs("en") Config.respawnTime = 150 -- Seconds Config.Fuel = "LegacyFuel" -- type the name of script you use i.e. ps-fuel, cdn-fuel, LegacyFuel Config.TierSystem = true -- allows for three tiers of certain drugs ( coke, heroin, crack, lsd) @@ -54,8 +54,8 @@ Config.Drugs = { cocaine = true, consumables =false, crack = true, - cornerselling = false, - heroin = false, + cornerselling = true, + heroin = true, deliveries = false, lean = false, lsd = false,