Files
md-drugs/client/cornerselling.lua
T

100 lines
3.6 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
2024-11-12 17:08:02 -08:00
local active = false
local function reset(targ)
FreezeEntityPosition(targ, false)
ClearPedTasks(targ)
Wait(10000)
DeletePed(targ)
targbusy = false
sold = true
2024-11-12 17:08:02 -08:00
active = false
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()
2024-11-12 17:08:02 -08:00
if active then return false end
2024-05-02 18:34:14 -07:00
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-11-12 17:08:02 -08:00
local data = lib.callback.await('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
2024-05-02 18:34:14 -07:00
TaskGoToCoordAnyMeans(targ, GetEntityCoords(PlayerPedId()), 1.0, 0, 0, 0, 0)
2024-11-12 17:08:02 -08:00
active = true
2024-05-02 18:34:14 -07:00
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)
2024-11-12 17:08:02 -08:00
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,
}}, 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
2024-11-12 17:08:02 -08:00
local has = lib.callback.await('md-drugs:server:hasDrugs', false)
if has then
if sell then
2024-11-12 17:08:02 -08:00
TriggerServerEvent('md-drugs:server:cornerselling:stop')
2024-10-23 16:04:09 -07:00
Notify(Lang.Cornerselling.stop, 'error')
2024-05-02 18:34:14 -07:00
sell = false
2024-11-12 17:08:02 -08:00
active = 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)
2024-11-12 17:08:02 -08:00
Cornersell()
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
2024-11-12 17:08:02 -08:00
end)
RegisterNetEvent('md-drugs:client:cornerselling:remove', function(ped)
DeletePed(ped)
end)