Target
The PBlackMarket already includes ox-target and drawmarker, and you can also add your own target system to the script by editing the following file:
editable/interaction/custom.lua
Custom target folder.
Here is the custom configuration to add your own target system to the script.
InteractionHandler = {}
function InteractionHandler.Init()
print('[PBlackMarket] ^3Custom interaction system loaded^7')
print('[PBlackMarket] ^3Please implement your custom interaction logic here^7')
end
function InteractionHandler.Refresh()
end
function InteractionHandler.Cleanup()
end
Ox_target folder.
Here is the ox_target configuration for the script.
InteractionHandler = {}
local targetZones = {}
local isInitialized = false
function InteractionHandler.Init()
InteractionHandler.Cleanup()
Citizen.Wait(500)
InteractionHandler.Refresh()
isInitialized = true
end
function InteractionHandler.Refresh()
InteractionHandler.Cleanup()
Citizen.Wait(200)
for i, npcConfig in pairs(Config.NPCs) do
local zoneName = 'blackmarket_npc_' .. i
if targetZones[i] then
pcall(function()
exports.ox_target:removeZone(targetZones[i])
end)
targetZones[i] = nil
end
local ok = pcall(function()
exports.ox_target:addSphereZone({
name = zoneName,
coords = vector3(npcConfig.coords.x, npcConfig.coords.y, npcConfig.coords.z),
radius = Config.InteractionDistance,
debug = false,
options = {
{
name = 'open_blackmarket_' .. i,
icon = 'fas fa-shopping-bag',
label = npcConfig.blip.label or 'Black Market',
canInteract = function()
return not uiOpen and HasAccess(npcConfig)
end,
onSelect = function()
if not uiOpen and HasAccess(npcConfig) then
currentNPC = npcConfig
OpenBlackMarket()
end
end
}
}
})
end)
if ok then
targetZones[i] = zoneName
end
end
end
function InteractionHandler.Cleanup()
for i, zoneName in pairs(targetZones) do
pcall(function()
exports.ox_target:removeZone(zoneName)
end)
Citizen.Wait(30)
end
targetZones = {}
end
Drawmarker folder.
And here is the drawmarker configuration.
InteractionHandler = {}
function InteractionHandler.Init()
Citizen.CreateThread(function()
local isNearAnyNPC = false
while true do
local sleep = 1000
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local foundNearby = false
for _, npcConfig in pairs(Config.NPCs) do
local dist = #(coords - vector3(npcConfig.coords.x, npcConfig.coords.y, npcConfig.coords.z))
if dist < Config.MarkerDrawDistance then
foundNearby = true
break
end
end
if foundNearby and not isNearAnyNPC then
isNearAnyNPC = true
InteractionHandler.StartMarkerThread()
elseif not foundNearby and isNearAnyNPC then
isNearAnyNPC = false
end
Citizen.Wait(sleep)
end
end)
end
function InteractionHandler.StartMarkerThread()
Citizen.CreateThread(function()
while true do
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local nearMarker = false
local nearNPC = false
for i, npcConfig in pairs(Config.NPCs) do
local dist = #(coords - vector3(npcConfig.coords.x, npcConfig.coords.y, npcConfig.coords.z))
if dist < Config.MarkerDrawDistance then
nearMarker = true
if npcConfig.marker.enabled then
DrawMarker(
npcConfig.marker.type,
npcConfig.coords.x, npcConfig.coords.y, npcConfig.coords.z - 1.0,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0,
npcConfig.marker.scale.x, npcConfig.marker.scale.y, npcConfig.marker.scale.z,
npcConfig.marker.color.r, npcConfig.marker.color.g, npcConfig.marker.color.b, npcConfig.marker.color.a,
false, false, 2, false, nil, nil, false
)
end
end
if dist < Config.InteractionDistance then
nearNPC = true
isNearMarker = true
currentNPC = npcConfig
if not uiOpen then
ShowHelpNotification(_U('press_to_open'))
end
if IsControlJustReleased(0, Config.Keybind) and not uiOpen then
if HasAccess(npcConfig) then
OpenBlackMarket()
end
end
end
end
if not nearNPC then
isNearMarker = false
currentNPC = nil
end
if not nearMarker then
break
end
Citizen.Wait(0)
end
end)
end
function InteractionHandler.Refresh()
end
function InteractionHandler.Cleanup()
endLast updated