Files
md-drugs/client/cornerselling.lua
T

225 lines
6.6 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-08-09 23:58:38 -06:00
PoliceCall(20)
2026-01-16 02:57:26 -07:00
if IsPedInAnyVehicle(PlayerPedId(), true) then
Bridge.Notify.SendNotify(Bridge.Language.Locale('Cornerselling.inVeh'), 'error')
2025-07-14 01:34:58 -07:00
walkAway(targ)
return
end
2026-01-21 21:27:08 -07:00
if not progressbar(Bridge.Language.Locale('Cornerselling.selling', Bridge.Inventory.GetItemInfo(item).label, price)) then
2026-01-16 02:57:26 -07:00
walkAway(targ)
return
end
2025-07-14 01:34:58 -07:00
buyers[targ] = 'sold'
2026-01-16 02:57:26 -07:00
TriggerServerEvent('md-drugs:server:sellCornerDrugs', item, amount, price, NetworkGetNetworkIdFromEntity(targ))
2025-07-14 01:34:58 -07:00
walkAway(targ)
end
local function deny(targ)
2026-01-16 02:57:26 -07:00
PoliceCall(20)
2025-07-14 01:34:58 -07:00
buyers[targ] = 'sold'
2026-01-21 21:27:08 -07:00
if not progressbar(Bridge.Language.Locale('Cornerselling.deny'), 4000, {
dict = 'anim@amb@casino@brawl@fights@argue@',
clip = 'arguement_loop_mp_m_brawler_01',
flag = 49
}) then return end
2025-07-14 01:34:58 -07:00
walkAway(targ)
end
2024-05-02 18:34:14 -07:00
2026-01-16 02:57:26 -07:00
local function getClosestPed()
2026-01-21 21:27:08 -07:00
local coords = GetEntityCoords(PlayerPedId())
local distance = 10.0
local pedList = GetGamePool('CPed')
local closestDistance = 1000.0
local PED = nil
for i = 1, #pedList do
local ped = pedList[i]
if ped ~= PlayerPedId() then
local pedCoords = GetEntityCoords(ped)
local dist = #(coords - pedCoords)
if dist < closestDistance then
PED = ped
closestDistance = dist
2026-01-16 02:57:26 -07:00
end
end
2026-01-21 21:27:08 -07:00
end
if PED and closestDistance < distance then
return PED, closestDistance
else
return nil
end
2026-01-16 02:57:26 -07:00
end
2026-01-21 21:27:08 -07:00
2025-07-14 01:34:58 -07:00
local function findPed()
local targ = nil
2026-01-21 21:27:08 -07:00
2025-07-14 01:34:58 -07:00
repeat
Wait(100)
2026-01-16 02:57:26 -07:00
targ = getClosestPed()
2025-07-14 01:34:58 -07:00
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
2025-09-08 00:06:28 -07:00
until targ ~= nil or sell == false
2026-01-21 21:27:08 -07:00
2025-09-08 00:06:28 -07:00
if not sell then return end
2025-07-14 01:34:58 -07:00
buyers[targ] = true
2025-07-16 01:48:56 -07:00
2026-01-16 02:57:26 -07:00
Bridge.HelpText.ShowHelpText(Bridge.Language.Locale('Cornerselling.wait'))
2025-07-14 01:34:58 -07:00
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)
2025-09-08 00:06:28 -07:00
until #(GetEntityCoords(PlayerPedId()) - GetEntityCoords(targ)) < 2.0 or sell == false or inZone
2026-01-16 02:57:26 -07:00
2025-09-08 00:06:28 -07:00
if not sell then return end
2026-01-16 02:57:26 -07:00
2025-07-14 01:34:58 -07:00
TaskTurnPedToFaceEntity(targ, PlayerPedId(), -1)
2026-01-16 02:57:26 -07:00
Bridge.HelpText.HideHelpText()
2025-07-14 01:34:58 -07:00
CreateThread(function()
Wait(45000)
walkAway(targ)
buyers[targ] = 'sold'
end)
return targ
end
local function checkItems()
2026-01-16 02:57:26 -07:00
local has = false
2025-07-14 01:34:58 -07:00
for k, v in pairs (GlobalState.DrugNames) do
2026-01-16 02:57:26 -07:00
if Bridge.Inventory.HasItem(v) then
has = true
2025-07-14 01:34:58 -07:00
break
end
end
2026-01-16 02:57:26 -07:00
if not has then
Bridge.Notify.SendNotify(Bridge.Language.Locale('Cornerselling.nodrugs', 'error'))
return false
end
2025-07-14 01:34:58 -07:00
return true
end
2025-07-18 01:19:12 -07:00
local function Cornersell()
2025-07-14 01:34:58 -07:00
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
2026-01-16 02:57:26 -07:00
Bridge.HelpText.ShowHelpText(Bridge.Language.Locale('Cornerselling.searching'))
2025-09-08 00:06:28 -07:00
2025-07-14 01:34:58 -07:00
local targ = findPed()
2026-01-16 02:57:26 -07:00
local data = Bridge.Callback.Trigger('md-drugs:server:cornerselling:getAvailableDrugs', NetworkGetNetworkIdFromEntity(targ))
2025-07-14 01:34:58 -07:00
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
2026-01-16 02:57:26 -07:00
Bridge.Target.AddLocalEntity(targ, {
2025-07-14 01:34:58 -07:00
{
2026-01-16 02:57:26 -07:00
label = Bridge.Language.Locale('Cornerselling.targetTakeBack'),
2026-01-21 21:27:08 -07:00
icon = Bridge.Language.Locale("Cornerselling.targetTakeBackIcon"),
2025-07-14 01:34:58 -07:00
action = function()
got = true
2026-01-16 02:57:26 -07:00
TriggerServerEvent('md-drugs:server:getBackRobbed', NetworkGetNetworkIdFromEntity(targ))
2025-07-14 01:34:58 -07:00
Cornersell()
end,
canInteract = function()
if IsEntityDead(targ) and not got then
return true
end
end,
2026-01-16 02:57:26 -07:00
}
})
2025-07-14 01:34:58 -07:00
else
2026-01-16 02:57:26 -07:00
Bridge.Anim.RequestDict("rcmme_tracey1")
2025-07-14 01:34:58 -07:00
TaskStartScenarioInPlace(targ, "WORLD_HUMAN_STAND_IMPATIENT_UPRIGHT", 0, false)
FreezeEntityPosition(targ, true)
2026-01-16 02:57:26 -07:00
Bridge.Target.AddLocalEntity(targ, {
2025-07-14 01:34:58 -07:00
{
2026-01-16 02:57:26 -07:00
label = Bridge.Language.Locale('Cornerselling.targetSell', data.amount, Bridge.Inventory.GetItemInfo(data.item).label, data.price),
2026-01-21 21:27:08 -07:00
icon = Bridge.Language.Locale("Cornerselling.targetSellIcon"),
2025-07-14 01:34:58 -07:00
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,
},
{
2026-01-16 02:57:26 -07:00
label = Bridge.Language.Locale('Cornerselling.targetDeny'),
2026-01-21 21:27:08 -07:00
icon = Bridge.Language.Locale("Cornerselling.targetDenyIcon"),
2025-07-14 01:34:58 -07:00
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()
2026-01-19 00:38:01 -07:00
if inZone then
Bridge.Notify.SendNotify(Bridge.Language.Locale('Cornerselling.inNoSellZone'), 'error')
return
end
2025-07-14 01:34:58 -07:00
if sell then
sell = false
2026-01-16 02:57:26 -07:00
Bridge.HelpText.HideHelpText()
Bridge.Notify.SendNotify(Bridge.Language.Locale('Cornerselling.stopped'), 'error')
2024-05-02 18:34:14 -07:00
else
2025-07-14 01:34:58 -07:00
sell = true
2026-01-16 02:57:26 -07:00
Bridge.Notify.SendNotify(Bridge.Language.Locale('Cornerselling.start'), 'success')
2025-07-14 01:34:58 -07:00
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
2026-01-19 00:38:01 -07:00
Bridge.Point.Register(
'MDDRUGNOSELLZONE'..k,
v.loc,
(v.width or 10.0 + v.length or 10.0) / 2,
nil,
function()
inZone = true
end,
function(point, data)
inZone = false
end
)
2025-07-14 01:34:58 -07:00
end
2026-01-16 02:57:26 -07:00
end)