+
Skip to content

Added QBCore #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
104 changes: 84 additions & 20 deletions server/units.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载