Ah yeah. I updated it so that the new zones are stored in a table. The identifier will be the players source ID. If a player that already has a zone made tries to create a new one, the old one will be removed.
client.lua
local stoppedVehicles = {} -- Table to store stopped vehicles
-- New variables
local radiusBlip = {}
local locationBlip = {}
-- End new variables
-- Add blips when "bsc_conclusionzone:addZone" event is triggered
RegisterNetEvent("bsc_conclusionzone:addZone")
AddEventHandler("bsc_conclusionzone:addZone", function(blipcoords, radius, id)
-- Remove existing blips
if radiusBlip[id] ~= nil or locationBlip[id] ~= nil then
RemoveBlip(radiusBlip[id])
RemoveBlip(locationBlip[id])
end
-- Set default radius if none provided
radius = radius or blipRadius
-- Create location blip
locationBlip[id] = AddBlipForCoord(blipcoords.x, blipcoords.y, blipcoords.z)
SetBlipSprite(locationBlip[id], 161)
SetBlipAsShortRange(locationBlip[id], true)
SetBlipColour(locationBlip[id], Config.Color)
SetBlipScale(locationBlip[id], 1.0)
BeginTextCommandSetBlipName('STRING')
AddTextComponentString(Config.Blipname)
EndTextCommandSetBlipName(locationBlip[id])
-- Create radius blip
radiusBlip[id] = AddBlipForRadius(blipcoords.x, blipcoords.y, blipcoords.z, radius)
SetBlipAlpha(radiusBlip[id], 150)
SetBlipColour(radiusBlip[id], Config.Color)
-- Play sound
if Config.Sounds then
PlaySoundFrontend(-1, "BASE_JUMP_PASSED", "HUD_AWARDS", 0, 1)
end
-- Reset stopped vehicles
stoppedVehicles = {}
local currentLocationBlip = locationBlip[id]
CreateThread(function()
while true do
-- Check if locationBlip has changed
if locationBlip[id] ~= currentLocationBlip then
break
end
local vehicle = GetRandomVehicleInSphere(blipcoords.x, blipcoords.y, blipcoords.z, radius, 0, 70)
if DoesEntityExist(vehicle) then
local driver = GetPedInVehicleSeat(vehicle, -1)
if DoesEntityExist(driver) and not IsPedAPlayer(driver) then
TaskVehicleTempAction(driver, vehicle, 6, 1000)
table.insert(stoppedVehicles, { driver = driver, vehicle = vehicle }) -- Store stopped vehicle
end
end
Wait(5)
end
end)
end)
-- Clear blips when "bsc_conclusionzone:clearZone" event is triggered
RegisterNetEvent('bsc_conclusionzone:clearZone')
AddEventHandler("bsc_conclusionzone:clearZone", function(id)
if radiusBlip[id] ~= nil or locationBlip[id] ~= nil then
RemoveBlip(radiusBlip[id])
RemoveBlip(locationBlip[id])
end
for i, data in ipairs(stoppedVehicles) do
if DoesEntityExist(data.vehicle) then
if DoesEntityExist(data.driver) and not IsPedAPlayer(data.driver) then
TaskVehicleDriveWander(data.driver, data.vehicle, 20.0, 786603) -- Make NPC drive again
end
end
end
-- Play sound
if Config.Sounds then
PlaySoundFrontend(-1, "PEYOTE_COMPLETED", "HUD_AWARDS", 0, 1)
end
end)
server.lua
-- Handles the "zoneAdd" command
RegisterCommand(Config.CreateCommand, function(source, args, rawCommand)
-- Get the radius of the zone from the command arguments
local radius = tonumber(args[1])
local xPlayer = ESX.GetPlayerFromId(source)
if isallowed(source) then
local location = xPlayer.getCoords(true)
-- I commented out this event trigger since it's already being triggered in the for loop
--TriggerClientEvent("bsc_conclusionzone:addZone", -1, location, radius, source)
-- Show a notification to the player
TriggerClientEvent('esx:showAdvancedNotification', -1, Config.NotifyTitle, '~r~', Config.NotifyMessage, Config.NotifyPicture, 3)
--make same blip for all players under jobs in config.jobs
local xPlayers = ESX.GetPlayers()
for i=1, #xPlayers, 1 do
local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
xPlayer.triggerEvent('bsc_conclusionzone:addZone', location, radius, source)
end
end
end)
-- Handles the "zoneRemove" command
RegisterCommand(Config.RemoveCommand, function(source, args, rawCommand)
-- Get the player who sent the command
local xPlayer = ESX.GetPlayerFromId(source)
-- Check if the player has an allowed job
if isallowed(source) then
-- Trigger an event to remove the zone on the client
TriggerClientEvent("bsc_conclusionzone:clearZone", -1, source)
-- Show a notification to the player
TriggerClientEvent('esx:showAdvancedNotification', -1, Config.NotifyTitle, '~r~', Config.NotifyMessageRemoved, Config.NotifyPicture, 3)
end
end)
function isallowed(source)
local xPlayer = ESX.GetPlayerFromId(source)
local job = xPlayer.getJob().name
local allowed = false
for k,v in pairs(Config.Jobs) do
if job == v then
allowed = true
break
else
allowed = false
end
end
return allowed
end