Files
md-drugs/client/cornerselling.lua
T

92 lines
3.5 KiB
Lua
Raw Normal View History

2024-01-13 22:23:17 -08:00
local QBCore = exports['qb-core']:GetCoreObject()
2024-05-02 18:34:14 -07:00
local sell = false
local sold = false
local targbusy = false
2024-10-28 14:35:47 -07:00
local inZone = false
local function reset(targ)
FreezeEntityPosition(targ, false)
ClearPedTasks(targ)
Wait(10000)
DeletePed(targ)
targbusy = false
sold = true
end
local function sellDrug(item, amount, price, targ)
PoliceCall(20)
targbusy = true
if IsPedInAnyVehicle(PlayerPedId(), true) then
2024-10-23 16:04:09 -07:00
Notify(Lang.Cornerselling.inveh, 'error')
reset(targ)
return end
2024-10-23 16:04:09 -07:00
if not progressbar(string.format(Lang.Cornerselling.selling, GetLabel(item), price), 4000, 'uncuff') then return end
TriggerServerEvent('md-drugs:server:sellCornerDrugs', item, amount, price)
reset(targ)
end
local function deny(targ)
PoliceCall(20)
targbusy = true
2024-10-23 16:04:09 -07:00
if not progressbar(Lang.Cornerselling.deny, 4000, 'argue5') then return end
reset(targ)
end
2024-05-02 18:34:14 -07:00
function Cornersell()
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
2024-05-02 18:34:14 -07:00
TaskGoToCoordAnyMeans(targ, GetEntityCoords(PlayerPedId()), 1.0, 0, 0, 0, 0)
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)
local item, amount, price = lib.callback.await('md-drugs:server:cornerselling:getAvailableDrugs', false)
2024-10-23 16:04:09 -07:00
if item == 'nothing' then Notify(Lang.Cornerselling.nodrugs, 'error') sell = false FreezeEntityPosition(targ, false) ClearPedTasks(targ) return false end
local options = {
2024-10-28 14:11:49 -07:00
{ label = string.format(Lang.targets.CornerSell.sell, amount, GetLabel(item), price), icon ="fa-solid fa-money-bill",
action = function() sellDrug(item, amount, price, targ) end,
canInteract = function()
if not targbusy then return true end end,
2024-05-02 18:34:14 -07:00
},
2024-10-28 14:35:47 -07:00
{ 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,
2024-05-02 18:34:14 -07:00
},
}
AddMultiModel(targ, options, nil)
2024-05-02 18:34:14 -07:00
repeat
Wait(1000)
until sold
2024-05-02 18:34:14 -07:00
if sold then sold = false return true end
2024-01-13 22:23:17 -08:00
end
RegisterNetEvent('md-drugs:client:cornerselling', function()
2024-05-04 10:56:00 -07:00
if not GetCops(QBConfig.MinimumDrugSalePolice) then return end
2024-10-28 14:35:47 -07:00
if inZone then Notify(Lang.Cornerselling.no, 'error') return end
local item, amount, price = lib.callback.await('md-drugs:server:cornerselling:getAvailableDrugs', false)
2024-05-02 18:34:14 -07:00
if item ~= 'nothing' then
if sell then
2024-10-23 16:04:09 -07:00
Notify(Lang.Cornerselling.stop, 'error')
2024-05-02 18:34:14 -07:00
sell = false
2024-01-13 22:23:17 -08:00
else
2024-05-02 18:34:14 -07:00
sell = true
2024-10-23 16:04:09 -07:00
Notify(Lang.Cornerselling.start, 'success')
2024-05-02 18:34:14 -07:00
repeat
Wait(1000)
if not Cornersell() then end
until not sell
2024-01-13 22:23:17 -08:00
end
2024-05-02 18:34:14 -07:00
else
2024-10-23 16:04:09 -07:00
Notify(Lang.Cornerselling.nodrugs, 'error')
2024-01-13 22:23:17 -08:00
end
2024-10-28 14:35:47 -07:00
end)
CreateThread(function()
for k, v in pairs (QBConfig.NoSellZones) do
2024-11-07 11:35:34 -08:00
local box = lib.zones.box({ coords = v.loc, size = vec3(v.width, v.length, v.height), rotation = 180.0, debug = false,
2024-10-28 14:35:47 -07:00
onEnter = function() inZone = true end, onExit = function() inZone = false end})
end
end)