mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
refactor: remove deprecated code
getCore and player modules were deprecated long ago and only used once.
This commit is contained in:
@@ -1,54 +0,0 @@
|
|||||||
if cache.game == 'redm' then return end
|
|
||||||
if not lib.player then lib.player() end
|
|
||||||
|
|
||||||
return function(resource)
|
|
||||||
local ESX = exports[resource]:getSharedObject()
|
|
||||||
|
|
||||||
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
|
|
||||||
ESX.PlayerData = xPlayer
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterNetEvent('esx:setJob', function(job)
|
|
||||||
ESX.PlayerData.job = job
|
|
||||||
end)
|
|
||||||
|
|
||||||
local CPlayer = lib.getPlayer()
|
|
||||||
|
|
||||||
function lib.getPlayer()
|
|
||||||
return setmetatable({
|
|
||||||
id = cache.playerId,
|
|
||||||
serverId = cache.serverId,
|
|
||||||
}, CPlayer)
|
|
||||||
end
|
|
||||||
|
|
||||||
function CPlayer:hasGroup(filter)
|
|
||||||
local data = ESX.PlayerData
|
|
||||||
local type = type(filter)
|
|
||||||
|
|
||||||
if type == 'string' then
|
|
||||||
if data.job.name == filter then
|
|
||||||
return data.job.name, data.job.grade
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local tabletype = table.type(filter)
|
|
||||||
|
|
||||||
if tabletype == 'hash' then
|
|
||||||
local grade = filter[data.job.name]
|
|
||||||
|
|
||||||
if grade and grade <= data.job.grade then
|
|
||||||
return data.job.name, data.job.grade
|
|
||||||
end
|
|
||||||
elseif tabletype == 'array' then
|
|
||||||
for i = 1, #filter do
|
|
||||||
if data.job.name == filter[i] then
|
|
||||||
return data.job.name, data.job.grade
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
player = lib.getPlayer()
|
|
||||||
|
|
||||||
return ESX
|
|
||||||
end
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
if cache.game == 'redm' then return end
|
|
||||||
if not lib.player then lib.player() end
|
|
||||||
|
|
||||||
return function(resource)
|
|
||||||
local ESX = exports[resource]:getSharedObject()
|
|
||||||
-- Eventually add some functions here to simplify the creation of framework-agnostic resources.
|
|
||||||
|
|
||||||
local CPlayer = lib.getPlayer()
|
|
||||||
|
|
||||||
function lib.getPlayer(player)
|
|
||||||
player = type(player) == 'table' and player.playerId or ESX.GetPlayerFromId(player)
|
|
||||||
|
|
||||||
if not player then
|
|
||||||
error(("'%s' is not a valid player"):format(player))
|
|
||||||
end
|
|
||||||
|
|
||||||
return setmetatable(player, CPlayer)
|
|
||||||
end
|
|
||||||
|
|
||||||
function CPlayer:hasGroup(filter)
|
|
||||||
local type = type(filter)
|
|
||||||
|
|
||||||
if type == 'string' then
|
|
||||||
if self.job.name == filter then
|
|
||||||
return self.job.name, self.job.grade
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local tabletype = table.type(filter)
|
|
||||||
|
|
||||||
if tabletype == 'hash' then
|
|
||||||
local grade = filter[self.job.name]
|
|
||||||
|
|
||||||
if grade and grade <= self.job.grade then
|
|
||||||
return self.job.name, self.job.grade
|
|
||||||
end
|
|
||||||
elseif tabletype == 'array' then
|
|
||||||
for i = 1, #filter do
|
|
||||||
if self.job.name == filter[i] then
|
|
||||||
return self.job.name, self.job.grade
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ESX
|
|
||||||
end
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
if cache.game == 'redm' then return end
|
|
||||||
if not lib.player then lib.player() end
|
|
||||||
|
|
||||||
return function(resource)
|
|
||||||
local QBCore = exports[resource]:GetCoreObject()
|
|
||||||
local PlayerData
|
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
|
||||||
PlayerData = QBCore.Functions.GetPlayerData()
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)
|
|
||||||
PlayerData.job = job
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnGangUpdate', function(gang)
|
|
||||||
PlayerData.gang = gang
|
|
||||||
end)
|
|
||||||
|
|
||||||
local CPlayer = lib.getPlayer()
|
|
||||||
|
|
||||||
function lib.getPlayer()
|
|
||||||
return setmetatable({
|
|
||||||
id = cache.playerId,
|
|
||||||
serverId = cache.serverId,
|
|
||||||
}, CPlayer)
|
|
||||||
end
|
|
||||||
|
|
||||||
local groups = { 'job', 'gang' }
|
|
||||||
|
|
||||||
function CPlayer:hasGroup(filter)
|
|
||||||
local type = type(filter)
|
|
||||||
|
|
||||||
if type == 'string' then
|
|
||||||
for i = 1, #groups do
|
|
||||||
local data = PlayerData[groups[i]]
|
|
||||||
|
|
||||||
if data.name == filter then
|
|
||||||
return data.name, data.grade.level
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local tabletype = table.type(filter)
|
|
||||||
|
|
||||||
if tabletype == 'hash' then
|
|
||||||
for i = 1, #groups do
|
|
||||||
local data = PlayerData[groups[i]]
|
|
||||||
local grade = filter[data.name]
|
|
||||||
|
|
||||||
if grade and grade <= data.grade.level then
|
|
||||||
return data.name, data.grade.level
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif tabletype == 'array' then
|
|
||||||
for i = 1, #filter do
|
|
||||||
local group = filter[i]
|
|
||||||
|
|
||||||
for j = 1, #groups do
|
|
||||||
local data = PlayerData[groups[j]]
|
|
||||||
|
|
||||||
if data.name == group then
|
|
||||||
return data.name, data.grade.level
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
player = lib.getPlayer()
|
|
||||||
|
|
||||||
return QBCore
|
|
||||||
end
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
if cache.game == 'redm' then return end
|
|
||||||
if not lib.player then lib.player() end
|
|
||||||
|
|
||||||
return function(resource)
|
|
||||||
local QBCore = exports[resource]:GetCoreObject()
|
|
||||||
-- Eventually add some functions here to simplify the creation of framework-agnostic resources.
|
|
||||||
|
|
||||||
local CPlayer = lib.getPlayer()
|
|
||||||
|
|
||||||
function lib.getPlayer(player)
|
|
||||||
player = type(player) == 'table' and player.playerId or QBCore.Functions.GetPlayer(player)
|
|
||||||
|
|
||||||
if not player then
|
|
||||||
error(("'%s' is not a valid player"):format(player))
|
|
||||||
end
|
|
||||||
|
|
||||||
return setmetatable(player, CPlayer)
|
|
||||||
end
|
|
||||||
|
|
||||||
local groups = { 'job', 'gang' }
|
|
||||||
|
|
||||||
function CPlayer:hasGroup(filter)
|
|
||||||
local type = type(filter)
|
|
||||||
|
|
||||||
if type == 'string' then
|
|
||||||
for i = 1, #groups do
|
|
||||||
local data = self.PlayerData[groups[i]]
|
|
||||||
|
|
||||||
if data.name == filter then
|
|
||||||
return data.name, data.grade.level
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local tabletype = table.type(filter)
|
|
||||||
|
|
||||||
if tabletype == 'hash' then
|
|
||||||
for i = 1, #groups do
|
|
||||||
local data = self.PlayerData[groups[i]]
|
|
||||||
local grade = filter[data.name]
|
|
||||||
|
|
||||||
if grade and grade <= data.grade.level then
|
|
||||||
return data.name, data.grade.level
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif tabletype == 'array' then
|
|
||||||
for i = 1, #filter do
|
|
||||||
local group = filter[i]
|
|
||||||
|
|
||||||
for j = 1, #groups do
|
|
||||||
local data = self.PlayerData[groups[j]]
|
|
||||||
|
|
||||||
if data.name == group then
|
|
||||||
return data.name, data.grade.level
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return QBCore
|
|
||||||
end
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
if cache.game == 'redm' then return end
|
|
||||||
--[[
|
|
||||||
This module was experimental and won't be worked on or used further.
|
|
||||||
May be removed in the future.
|
|
||||||
]]
|
|
||||||
|
|
||||||
local Core = {
|
|
||||||
Ox = 'ox_core',
|
|
||||||
QB = 'qb-core',
|
|
||||||
ESX = 'es_extended',
|
|
||||||
}
|
|
||||||
|
|
||||||
---@deprecated
|
|
||||||
function lib.getCore()
|
|
||||||
local result
|
|
||||||
|
|
||||||
Citizen.CreateThreadNow(function()
|
|
||||||
local framework = GetConvar('framework', '')
|
|
||||||
|
|
||||||
if framework == '' then
|
|
||||||
framework = GetResourceState(Core.Ox):find('start') and Core.Ox
|
|
||||||
or GetResourceState(Core.QB):find('start') and Core.QB
|
|
||||||
or GetResourceState(Core.ESX):find('start') and Core.ESX
|
|
||||||
|
|
||||||
if not framework then
|
|
||||||
error('Unable to determine framework (convar is not set, or resource was renamed)')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local success
|
|
||||||
local import
|
|
||||||
local resource
|
|
||||||
|
|
||||||
if framework == Core.Ox then
|
|
||||||
import = ('imports/%s.lua'):format(lib.context)
|
|
||||||
resource = Core.Ox
|
|
||||||
else
|
|
||||||
import = ('imports/getCore/%s/%s.lua'):format(framework, lib.context)
|
|
||||||
resource = lib.name
|
|
||||||
end
|
|
||||||
|
|
||||||
success, result = pcall(LoadResourceFile, resource, import)
|
|
||||||
|
|
||||||
if not result then
|
|
||||||
error(("Unable to load '@%s/%s'"):format(resource, import))
|
|
||||||
end
|
|
||||||
|
|
||||||
if not success then
|
|
||||||
error(result and result or ("Unable to load '@%s/%s'"):format(resource, import), 0)
|
|
||||||
end
|
|
||||||
|
|
||||||
success, result = load(result, ('@@%s/%s'):format(resource, import))
|
|
||||||
|
|
||||||
if not success then
|
|
||||||
error(result, 0)
|
|
||||||
end
|
|
||||||
|
|
||||||
success, result = pcall(success, framework)
|
|
||||||
|
|
||||||
if not success then error(result) end
|
|
||||||
|
|
||||||
if framework == Core.Ox then
|
|
||||||
---@diagnostic disable-next-line: undefined-global
|
|
||||||
result = Ox
|
|
||||||
end
|
|
||||||
|
|
||||||
if not result then
|
|
||||||
error(('no loader exists for %s'):format(framework))
|
|
||||||
elseif type(result) == 'function' then
|
|
||||||
result = result(framework)
|
|
||||||
end
|
|
||||||
|
|
||||||
result.resource = framework
|
|
||||||
end)
|
|
||||||
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
---@diagnostic disable-next-line: deprecated
|
|
||||||
return lib.getCore
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
--[[
|
|
||||||
This module was experimental and won't be worked on or used further.
|
|
||||||
May be removed in the future.
|
|
||||||
]]
|
|
||||||
|
|
||||||
local CPlayer = {}
|
|
||||||
|
|
||||||
function CPlayer:__index(index, ...)
|
|
||||||
local method = CPlayer[index]
|
|
||||||
|
|
||||||
if method then
|
|
||||||
return function(...)
|
|
||||||
return method(self, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function CPlayer:getCoords(update)
|
|
||||||
if update or not self.coords then
|
|
||||||
self.coords = GetEntityCoords(cache.ped)
|
|
||||||
end
|
|
||||||
|
|
||||||
return self.coords
|
|
||||||
end
|
|
||||||
|
|
||||||
function CPlayer:getDistance(coords)
|
|
||||||
return #(self:getCoords() - coords)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@deprecated
|
|
||||||
function lib.getPlayer()
|
|
||||||
return CPlayer
|
|
||||||
end
|
|
||||||
|
|
||||||
return lib.getPlayer
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
--[[
|
|
||||||
This module was experimental and won't be worked on or used further.
|
|
||||||
May be removed in the future.
|
|
||||||
]]
|
|
||||||
|
|
||||||
local CPlayer = {}
|
|
||||||
|
|
||||||
function CPlayer:__index(index, ...)
|
|
||||||
local method = CPlayer[index]
|
|
||||||
|
|
||||||
if method then
|
|
||||||
return function(...)
|
|
||||||
return method(self, ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function CPlayer:getCoords(update)
|
|
||||||
if update or not self.coords then
|
|
||||||
self.coords = GetEntityCoords(self.getPed())
|
|
||||||
end
|
|
||||||
|
|
||||||
return self.coords
|
|
||||||
end
|
|
||||||
|
|
||||||
function CPlayer:getDistance(coords)
|
|
||||||
return #(self:getCoords() - coords)
|
|
||||||
end
|
|
||||||
|
|
||||||
function CPlayer:getPed()
|
|
||||||
self.ped = GetPlayerPed(self.source)
|
|
||||||
return self.ped
|
|
||||||
end
|
|
||||||
|
|
||||||
---@deprecated
|
|
||||||
function lib.getPlayer()
|
|
||||||
return CPlayer
|
|
||||||
end
|
|
||||||
|
|
||||||
return lib.getPlayer
|
|
||||||
Reference in New Issue
Block a user