From bda68610405718a7009a59aae2b02f97f7c380bb Mon Sep 17 00:00:00 2001 From: Focking Mikkel Date: Wed, 4 Jan 2023 01:33:38 +0100 Subject: [PATCH] Added QBCore Added QBCore, but had to make som changes in the config for it to look better. (Not my best code ever) I have not tested if the item works but everything else does I have not tested ESX after the changes but that should work, it wasn't major changes. --- config.lua | 12 +++++- server/units.lua | 104 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 94 insertions(+), 22 deletions(-) diff --git a/config.lua b/config.lua index 65e4a93..1dcedce 100644 --- a/config.lua +++ b/config.lua @@ -35,8 +35,16 @@ Config.UnitsRadar = { 65 }, panicColor = 10, -- The color of the route to a panic - set to false or nil if you don't want to enable /panic; See "HUD Colors" (https://wiki.rage.mp/index.php?title=Fonts_and_Colors) - enableESX = "police", -- Set to false if you don't want to use ESX jobs, if you do you can change this to the name of your police job; Can be a table containing a list of allowed jobs - for example {'police', 'ambulance'} - requireItem = false, -- Enabled only if you're using ESX (enableESX must be filled in); Sets the required item for the dispatch to register officers onto the map, registers it as usable -> officers may use the item to turn the radar on if it wasn't turned on automatically + ESXJobs = false, -- Set to false if you don't want to use ESX jobs, if you do you can change this to the name of your police job; Can be a table containing a list of allowed jobs - for example {'police', 'ambulance'} + ESXrequireItem = false, -- Enabled only if you're using ESX (enableESX must be filled in); Sets the required item for the dispatch to register officers onto the map, registers it as usable -> officers may use the item to turn the radar on if it wasn't turned on automatically + --QBCORE-- + QBCoreJobs = { + 'police', + }, + QBCorerequireItem = 'pdtracker', + QBCoreitemname = 'Police Tracker', + QBCoreImageName = 'tunerchip.png', + --QBCORE-- bigmapKey = false, -- Set to a specific key to automatically bind the extend / shrink functionality of the minimap; Set to false if you don't want to use the functionality; Set to true if you don't want to set default keybind usePlayerBlips = true, -- When true, the script will only show blips for distant players (OneSync Infinity/Beyond) announceDuty = true -- Set to true if you want to send every unit a message about other units going on/off duty diff --git a/server/units.lua b/server/units.lua index c5ecf6e..cbb76b5 100644 --- a/server/units.lua +++ b/server/units.lua @@ -352,31 +352,27 @@ RegisterCommand( -- AUTO-SUBSCRIBE -- --================================-- -if Config.UnitsRadar.enableESX then - ESX = nil +if Config.UnitsRadar.ESXJobs then + ESX = exports['es_extended']:getSharedObject() - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - - Config.UnitsRadar.requireItem = Config.UnitsRadar.requireItem and tostring(Config.UnitsRadar.requireItem) or false + Config.UnitsRadar.ESXrequireItem = Config.UnitsRadar.ESXrequireItem and tostring(Config.UnitsRadar.ESXrequireItem) or false local allowedJobs = {} - if type(Config.UnitsRadar.enableESX) == "table" then - for k, v in pairs(Config.UnitsRadar.enableESX) do + if type(Config.UnitsRadar.ESXJobs) == "table" then + for k, v in pairs(Config.UnitsRadar.ESXJobs) do allowedJobs[v] = true end else - allowedJobs[Config.UnitsRadar.enableESX] = true + allowedJobs[Config.UnitsRadar.ESXJobs] = true end RegisterNetEvent("esx:setJob") - AddEventHandler( - "esx:setJob", - function(playerId) + AddEventHandler("esx:setJob", function(playerId) local xPlayer = ESX.GetPlayerFromId(playerId) if xPlayer then - local hasItem = Config.UnitsRadar.requireItem and xPlayer.getInventoryItem(Config.UnitsRadar.requireItem).count > 0 or true + local hasItem = Config.UnitsRadar.ESXrequireItem and xPlayer.getInventoryItem(Config.UnitsRadar.ESXrequireItem).count > 0 or true if allowedJobs[xPlayer.job.name] and hasItem then UnitsRadar:addUnit(playerId) @@ -388,13 +384,11 @@ if Config.UnitsRadar.enableESX then ) RegisterNetEvent("esx:playerLoaded") - AddEventHandler( - "esx:playerLoaded", - function(playerId) + AddEventHandler("esx:playerLoaded", function(playerId) local xPlayer = ESX.GetPlayerFromId(playerId) if xPlayer then - local hasItem = Config.UnitsRadar.requireItem and xPlayer.getInventoryItem(Config.UnitsRadar.requireItem).count > 0 or true + local hasItem = Config.UnitsRadar.ESXrequireItem and xPlayer.getInventoryItem(Config.UnitsRadar.ESXrequireItem).count > 0 or true if allowedJobs[xPlayer.job.name] and hasItem then UnitsRadar:addUnit(playerId) @@ -405,10 +399,8 @@ if Config.UnitsRadar.enableESX then end ) - if Config.UnitsRadar.requireItem then - ESX.RegisterUsableItem( - Config.UnitsRadar.requireItem, - function(source) + if Config.UnitsRadar.ESXrequireItem then + ESX.RegisterUsableItem(Config.UnitsRadar.ESXrequireItem, function(source) local xPlayer = ESX.GetPlayerFromId(source) if allowedJobs[xPlayer.job.name] and not UnitsRadar.active[source] then @@ -419,4 +411,76 @@ if Config.UnitsRadar.enableESX then end ) end +end + +if Config.UnitsRadar.QBCoreJobs then + QBCore = exports['qb-core']:GetCoreObject() + + Config.UnitsRadar.QBCorerequireItem = Config.UnitsRadar.QBCorerequireItem and tostring(Config.UnitsRadar.QBCorerequireItem) or false + + local allowedJobs = {} + + if type(Config.UnitsRadar.QBCoreJobs) == "table" then + for k, v in pairs(Config.UnitsRadar.QBCoreJobs) do + allowedJobs[v] = true + end + else + allowedJobs[Config.UnitsRadar.QBCoreJobs] = true + end + + RegisterNetEvent("QBCore:Client:OnJobUpdate") + AddEventHandler("QBCore:Client:OnJobUpdate", function(playerId) + local xPlayer = QBCore.Functions.GetPlayer(playerId) + + if xPlayer then + local hasItem = Config.UnitsRadar.QBCorerequireItem and xPlayer.getInventoryItem(Config.UnitsRadar.QBCorerequireItem).count > 0 or true + + if allowedJobs[xPlayer.job.name] and hasItem then + UnitsRadar:addUnit(playerId) + elseif UnitsRadar.active[playerId] then + UnitsRadar:removeUnit(playerId) + end + end + end + ) + + RegisterNetEvent("QBCore:Client:OnPlayerLoaded") + AddEventHandler("QBCore:Client:OnPlayerLoaded", function(playerId) + local xPlayer = QBCore.Functions.GetPlayer(playerId) + + if xPlayer then + local hasItem = Config.UnitsRadar.QBCorerequireItem and xPlayer.getInventoryItem(Config.UnitsRadar.QBCorerequireItem).count > 0 or true + + if allowedJobs[xPlayer.job.name] and hasItem then + UnitsRadar:addUnit(playerId) + elseif UnitsRadar.active[playerId] then + UnitsRadar:removeUnit(playerId) + end + end + end + ) + + if Config.UnitsRadar.QBCorerequireItem then + QBCore.Functions.AddItem(Config.UnitsRadar.QBCorerequireItem, { + name = Config.UnitsRadar.QBCorerequireItem, + label = Config.UnitsRadar.QBCoreitemname, + weight = 2, + type = 'item', + image = Config.UnitsRadar.QBCoreImageName, + unique = false, + useable = true, + shouldClose = true, + combinable = nil, + description = 'Tracker for the police' + }) + local canUse = QBCore.Functions.CanUseItem(Config.UnitsRadar.QBCorerequireItem) + if not canUse then return end + local xPlayer = QBCore.Functions.GetPlayer(source) + + if allowedJobs[xPlayer.job.name] and not UnitsRadar.active[source] then + UnitsRadar:addUnit(source) + elseif UnitsRadar.active[source] then + UnitsRadar:removeUnit(source) + end + end end \ No newline at end of file