forked from Simnation/Main
84 lines
2.3 KiB
Lua
84 lines
2.3 KiB
Lua
---@diagnostic disable: undefined-field
|
|
ESX = nil
|
|
QBCore = nil
|
|
|
|
if (GetResourceState('es_extended') == 'started') then
|
|
ESX = exports['es_extended']:getSharedObject()
|
|
elseif (GetResourceState('qb-core') == 'started') then
|
|
QBCore = exports['qb-core']:GetCoreObject()
|
|
end
|
|
|
|
Functions = {}
|
|
|
|
Functions.HasItem = function(playerId, itemName)
|
|
if ESX then
|
|
local xPlayer = ESX.GetPlayerFromId(playerId)
|
|
return xPlayer.getInventoryItem(itemName).count > 0
|
|
elseif QBCore then
|
|
local Player = QBCore.Functions.GetPlayer(playerId)
|
|
return Player.Functions.GetItemByName(itemName).amount > 0
|
|
end
|
|
end
|
|
|
|
Functions.RemoveItem = function(playerId, itemName, amount)
|
|
if ESX then
|
|
local xPlayer = ESX.GetPlayerFromId(playerId)
|
|
xPlayer.removeInventoryItem(itemName, amount)
|
|
elseif QBCore then
|
|
local Player = QBCore.Functions.GetPlayer(playerId)
|
|
Player.Functions.RemoveItem(itemName, amount)
|
|
end
|
|
end
|
|
|
|
Functions.GetPolicePlayers = function()
|
|
if not Config.allowedJobs then
|
|
return { -1 }
|
|
end
|
|
|
|
local jobs = {}
|
|
for jobName, _ in pairs(Config.allowedJobs) do
|
|
jobs[#jobs + 1] = jobName
|
|
end
|
|
|
|
local playerIds = {}
|
|
|
|
if ESX then
|
|
local result = ESX.GetExtendedPlayers('job', jobs)
|
|
for key, xPlayers in pairs(result) do
|
|
for i = 1, #xPlayers do
|
|
playerIds[#playerIds + 1] = xPlayers[i].source
|
|
end
|
|
end
|
|
elseif QBCore then
|
|
for jobName, _ in pairs(Config.allowedJobs) do
|
|
local players = QBCore.Functions.GetPlayersOnDuty(jobName)
|
|
for i = 1, #players do
|
|
playerIds[#playerIds + 1] = players[i]
|
|
end
|
|
end
|
|
end
|
|
|
|
return playerIds
|
|
end
|
|
|
|
--[[
|
|
-- If you are using an older version of ESX, and the blips are not showing up, you can use this function instead of the one above.
|
|
Functions.GetPolicePlayers = function()
|
|
local jobs = {}
|
|
for jobName, _ in pairs(Config.allowedJobs) do
|
|
jobs[#jobs + 1] = jobName
|
|
end
|
|
|
|
local playerIds = {}
|
|
|
|
for i = 1, #jobs do
|
|
local jobName = jobs[i]
|
|
local result = ESX.GetExtendedPlayers('job', jobName)
|
|
for key, xPlayer in pairs(result) do
|
|
playerIds[#playerIds + 1] = xPlayer.source
|
|
end
|
|
end
|
|
|
|
return playerIds
|
|
end
|
|
]]
|