Help modifying a script to make it job specific

Hello i am using a vehicle spawner script and would like to know of a way to limit the spawning to a specific job at the moment only the map blips disappear for the people who don’t have the job i would like to make it so the spawn menu and circle is not visible thanks for any help

local Keys = {
  ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
  ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
  ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
  ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
  ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
  ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
  ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
  ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
  ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}

ESX = nil

local PlayerData              = {}
local BlipList                = {}
local HasAlreadyEnteredMarker = false
local LastZone                = nil
local CurrentAction           = nil
local CurrentActionMsg        = ''
local CurrentActionData       = {}
local spawnedVehicles         = {}
local this_Spawner            = {}

Citizen.CreateThread(function()
	while ESX == nil do
		TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
		Citizen.Wait(0)
	end
	
	while ESX.GetPlayerData().job == nil do
		Citizen.Wait(10)
	end

	ESX.PlayerData = ESX.GetPlayerData()
	refreshBlips()
end)

RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
	ESX.PlayerData = xPlayer
	refreshBlips()
end)

RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
	ESX.PlayerData.job = job
	deleteBlips()
	refreshBlips()
end)
-- Open Menu Spawner
function OpenMenuSpawner(PointType)
	ESX.UI.Menu.CloseAll()
	
	local elements = {}
	
	if PointType == 'spawner_point' then
		table.insert(elements, {label = _U('list_spawners'), value = 'list_spawners'})
	elseif PointType == 'deleter_point' then
		table.insert(elements, {label = _U('return_spawners'), value = 'return_spawners'})
	end
	
	ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'spawner_menu', {
		title    = _U('spawner'),
		align    = 'top-left',
		elements = elements
	}, function(data, menu)
		menu.close()
		local action = data.current.value
		
		if action == 'list_spawners' then
			ListMenuSpawner()
		elseif action == 'return_spawners' then
			ListMenuReturn()
		end
	end, function (data, menu)
		menu.close()
	end)
end

-- List Vehicles
function ListMenuSpawner()
	local elements = {
		{label = _U('dont_abuse')}
	}
	
	for i=1, #Config.Vehicles, 1 do
		table.insert(elements, {
			label = Config.Vehicles[i].label,
			model = Config.Vehicles[i].model
		})
	end
	
	ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_spawner', {
		title    = _U('vehicle_spawner'),
		align    = 'top-left',
		elements = elements
	}, function(data, menu)
		menu.close()
		SpawnVehicle(data.current.model)
	end, function(data, menu)
		menu.close()
	end)
end

function ListMenuReturn()
	local playerCoords = GetEntityCoords(PlayerPedId())
	
	vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 5.0)
	if #vehicles > 0 then
		for k,v in ipairs(vehicles) do
			ESX.Game.DeleteVehicle(v)
		end
	end
end

function SpawnVehicle(model)
	ESX.Game.SpawnVehicle(model, {
		x = this_Spawner.Spawner.x,
		y = this_Spawner.Spawner.y,
		z = this_Spawner.Spawner.z + 1
	}, this_Spawner.Spawner.h)
end

-- Entered Marker
AddEventHandler('esx_vehiclespawner:hasEnteredMarker', function(zone)
	if zone == 'spawner_point' then
		CurrentAction     = 'spawner_point'
		CurrentActionMsg  = _U('press_to_enter')
		CurrentActionData = {}
	elseif zone == 'deleter_point' then
		CurrentAction     = 'deleter_point'
		CurrentActionMsg  = _U('press_to_enter2')
		CurrentActionData = {}
	end
end)

-- Exited Marker
AddEventHandler('esx_vehiclespawner:hasExitedMarker', function()
	ESX.UI.Menu.CloseAll()
	CurrentAction = nil
end)

-- Draw Markers
Citizen.CreateThread(function()
	while true do
		Citizen.Wait(1)
		
		local playerPed = PlayerPedId()
		local coords    = GetEntityCoords(playerPed)
		local canSleep  = true
		
		for k,v in pairs(Config.SpawnerLocations) do
			if (GetDistanceBetweenCoords(coords, v.Marker.x, v.Marker.y, v.Marker.z, true) < Config.DrawDistance) then
				canSleep = false
				DrawMarker(Config.MarkerType, v.Marker.x, v.Marker.y, v.Marker.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.MarkerInfo.x, Config.MarkerInfo.y, Config.MarkerInfo.z, Config.MarkerInfo.r, Config.MarkerInfo.g, Config.MarkerInfo.b, 100, false, true, 2, false, false, false, false)	
				DrawMarker(Config.MarkerType, v.Deleter.x, v.Deleter.y, v.Deleter.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.MarkerInfo2.x, Config.MarkerInfo2.y, Config.MarkerInfo2.z, Config.MarkerInfo2.r, Config.MarkerInfo2.g, Config.MarkerInfo2.b, 100, false, true, 2, false, false, false, false)	
			end
		end
		
		if canSleep then
			Citizen.Wait(500)
		end
	end
end)

-- Activate Menu when in Markers
Citizen.CreateThread(function()
	local currentZone = ''
	while true do
		Citizen.Wait(1)
		
		local playerPed  = PlayerPedId()
		local coords     = GetEntityCoords(playerPed)
		local isInMarker = false
		
		for k,v in pairs(Config.SpawnerLocations) do
			if (GetDistanceBetweenCoords(coords, v.Marker.x, v.Marker.y, v.Marker.z, true) < Config.MarkerInfo.x) then
				isInMarker   = true
				this_Spawner = v
				currentZone  = 'spawner_point'
			end
			
			if(GetDistanceBetweenCoords(coords, v.Deleter.x, v.Deleter.y, v.Deleter.z, true) < Config.MarkerInfo2.x) then
				isInMarker   = true
				this_Spawner = v
				currentZone  = 'deleter_point'
			end
		end
		
		if isInMarker and not hasAlreadyEnteredMarker then
			hasAlreadyEnteredMarker = true
			LastZone                = currentZone
			TriggerEvent('esx_vehiclespawner:hasEnteredMarker', currentZone)
		end
		
		if not isInMarker and hasAlreadyEnteredMarker then
			hasAlreadyEnteredMarker = false
			TriggerEvent('esx_vehiclespawner:hasExitedMarker', LastZone)
		end
		
		if not isInMarker then
			Citizen.Wait(500)
		end
	end
end)

-- Key Controls
Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		
		if CurrentAction ~= nil then
			ESX.ShowHelpNotification(CurrentActionMsg)
			
			if IsControlJustReleased(0, Keys['E']) then
				if CurrentAction == 'spawner_point' then
					OpenMenuSpawner('spawner_point')
				elseif CurrentAction == 'deleter_point' then
					OpenMenuSpawner('deleter_point')
				end
				
				CurrentAction = nil
			end
		else
			Citizen.Wait(500)
		end
	end
end)

-- Blips
function deleteBlips()
	if BlipList[1] ~= nil then
		for i=1, #BlipList, 1 do
			RemoveBlip(BlipList[i])
			BlipList[i] = nil
		end
	end
end

function refreshBlips()
	if Config.EnableBlips then
		if Config.EnableSpecificOnly then
			if ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'police' or ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'gang' or ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'fisherman' or ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'fueler' or ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'lumberjack' or ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'miner' or ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'butcher' then
				for k,v in pairs(Config.SpawnerLocations) do
					local blip = AddBlipForCoord(v.Marker.x, v.Marker.y)

					SetBlipSprite (blip, Config.BlipSpawner.Sprite)
					SetBlipDisplay(blip, Config.BlipSpawner.Display)
					SetBlipScale  (blip, Config.BlipSpawner.Scale)
					SetBlipColour (blip, Config.BlipSpawner.Color)
					SetBlipAsShortRange(blip, true)

					BeginTextCommandSetBlipName("STRING")
					AddTextComponentString(_U('blip_spawner'))
					EndTextCommandSetBlipName(blip)
					table.insert(BlipList, blip)
				end
			end
		else
			for k,v in pairs(Config.SpawnerLocations) do
				local blip = AddBlipForCoord(v.Marker.x, v.Marker.y)

				SetBlipSprite (blip, Config.BlipSpawner.Sprite)
				SetBlipDisplay(blip, Config.BlipSpawner.Display)
				SetBlipScale  (blip, Config.BlipSpawner.Scale)
				SetBlipColour (blip, Config.BlipSpawner.Color)
				SetBlipAsShortRange(blip, true)

				BeginTextCommandSetBlipName("STRING")
				AddTextComponentString(_U('blip_spawner'))
				EndTextCommandSetBlipName(blip)
				table.insert(BlipList, blip)
			end
		end
	end
end

If i am understanding what your seeing adding a job check in this EventHandler should remove the circle and menu when you press the right button for just the police

SpikE

So i add the job check before this?

so something like this

if ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == ‘police’ then

I would think adding a job check after that line would make the circles and open to open menu only show for police.

tried this get an error on line 137

Just put your code in visual studio and that EventHandler is what looks like draws the circle when someone enters the are. but you need to do the job check before you send a call to that eventhandler… just a quick glance at the code… and i would say the function that starts at line 170 is where the current script is sending the request to that event handler… would need to add that if statement… and make sure you end it.

The following code is line 170 - 210 is 2 extra lines then you currently have so just need to replace 170 -208

Citizen.CreateThread(function()
    local currentZone = ''
	while true do
    Citizen.Wait(1)
        
        if ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == ‘police’ then
	    	local playerPed  = PlayerPedId()
		    local coords     = GetEntityCoords(playerPed)
		    local isInMarker = false
		
    		for k,v in pairs(Config.SpawnerLocations) do
	    		if (GetDistanceBetweenCoords(coords, v.Marker.x, v.Marker.y, v.Marker.z, true) < Config.MarkerInfo.x) then
		    		isInMarker   = true
			    	this_Spawner = v
				    currentZone  = 'spawner_point'
                end
                
		    	if(GetDistanceBetweenCoords(coords, v.Deleter.x, v.Deleter.y, v.Deleter.z, true) < Config.MarkerInfo2.x) then
			    	isInMarker   = true
			    	this_Spawner = v
			    	currentZone  = 'deleter_point'
			    end
		    end
		
    		if isInMarker and not hasAlreadyEnteredMarker then
	    		hasAlreadyEnteredMarker = true
	    		LastZone                = currentZone
	    		TriggerEvent('esx_vehiclespawner:hasEnteredMarker', currentZone)
	    	end
            
		    if not isInMarker and hasAlreadyEnteredMarker then
		    	hasAlreadyEnteredMarker = false
		    	TriggerEvent('esx_vehiclespawner:hasExitedMarker', LastZone)
		    end
		
    		if not isInMarker then
	    		Citizen.Wait(500)
            end
        end
	end
end)

Edited the orginal code i sent:

Just looked at the code i posted and i had the job check outside of the loop so would only have checked once. this puts it in the loop so will check before it trys to send to the event handler.

thank you so much for your help its working as i wanted it now

Since this is a EventHandler… make sure anything you might have done didn’t mess up any other vehile spawner locations. I wouldn’t expect it to from what I see… but best to check now while it is fresh in your head… to revert back in need be.

My other scrips appear to be working. On another note do you how to make a spawned vehicle come back to a person as currently the owner is unknown

Not sure what you mean. Are you trying to find the owner of a vehicle? or the vehicle disappeared?

i mean when i spawn the vehicle from the circle the owner comes back as unknown is it possible to have it come back to the person who spawned it

For that I wouldn’t know how to set the owner of a vehicle on spawn.