Files
md-drugs/client/cornerselling.lua
T

174 lines
4.9 KiB
Lua
Raw Normal View History

2024-05-02 18:34:14 -07:00
local sell = false
2024-10-28 14:35:47 -07:00
local inZone = false
2025-07-14 01:34:58 -07:00
local buyers = {}
2025-07-14 01:34:58 -07:00
local function walkAway(targ)
FreezeEntityPosition(targ, false)
ClearPedTasks(targ)
end
local function sellDrug(item, amount, price, targ)
2025-07-14 01:34:58 -07:00
-- PoliceCall(20)
if ps.vehicleData() then
2025-07-16 01:48:56 -07:00
ps.notify(ps.lang('Cornerselling.inveh', 'error'))
2025-07-14 01:34:58 -07:00
walkAway(targ)
return
end
2025-07-16 01:48:56 -07:00
if not ps.progressbar(string.format(ps.lang('Cornerselling.selling', ps.getLabel(item), price)), 4000, 'uncuff') then walkAway(targ) return end
2025-07-14 01:34:58 -07:00
buyers[targ] = 'sold'
TriggerServerEvent('md-drugs:server:sellCornerDrugs', item, amount, price)
2025-07-14 01:34:58 -07:00
walkAway(targ)
end
local function deny(targ)
2025-07-14 01:34:58 -07:00
-- PoliceCall(20)
buyers[targ] = 'sold'
if not ps.progressbar(ps.lang('Cornerselling.deny'), 4000, 'argue5') then return end
walkAway(targ)
end
2024-05-02 18:34:14 -07:00
2025-07-14 01:34:58 -07:00
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
2025-07-16 01:48:56 -07:00
2025-07-14 01:34:58 -07:00
ps.drawText('Waiting For Customer')
2024-05-02 18:34:14 -07:00
repeat
Wait(1000)
2025-07-14 01:34:58 -07:00
TaskGoToCoordAnyMeans(targ, GetEntityCoords(PlayerPedId()), 1.0, 0, 0, 0, 0)
2024-05-02 18:34:14 -07:00
until #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(targ)) < 2.0
2025-07-14 01:34:58 -07:00
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 inZone then sell = false return end
if not sell then
2025-07-16 01:48:56 -07:00
return
2025-07-14 01:34:58 -07:00
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,
2024-11-12 17:08:02 -08:00
}}, nil)
2025-07-14 01:34:58 -07:00
else
ps.requestAnim("rcmme_tracey1")
TaskStartScenarioInPlace(targ, "WORLD_HUMAN_STAND_IMPATIENT_UPRIGHT", 0, false)
FreezeEntityPosition(targ, true)
ps.entityTarget(data.ped, {
{
2025-07-16 01:48:56 -07:00
label = string.format(ps.lang('targets.CornerSell.sell', data.amount, ps.getLabel(data.item), data.price)),
2025-07-14 01:34:58 -07:00
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
2024-01-13 22:23:17 -08:00
end
RegisterNetEvent('md-drugs:client:cornerselling', function()
2025-07-14 01:34:58 -07:00
if sell then
sell = false
ps.hideText()
ps.notify(ps.lang('Cornerselling.stopped', 'error'))
2024-05-02 18:34:14 -07:00
else
2025-07-14 01:34:58 -07:00
sell = true
ps.notify(ps.lang('Cornerselling.started', 'success'))
Cornersell()
2024-01-13 22:23:17 -08:00
end
2024-10-28 14:35:47 -07:00
end)
CreateThread(function()
2025-07-14 01:34:58 -07:00
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)