mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
feat(getCore/client): load and extend player class
This commit is contained in:
@@ -1,5 +1,40 @@
|
|||||||
|
if not lib.player then lib.player() end
|
||||||
|
|
||||||
return function(resource)
|
return function(resource)
|
||||||
local ESX = exports[resource]:getSharedObject()
|
local ESX = exports[resource]:getSharedObject()
|
||||||
-- Eventually add some functions here to simplify the creation of framework-agnostic resources.
|
|
||||||
|
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
|
||||||
|
ESX.PlayerData = xPlayer
|
||||||
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent('esx:setJob', function(job)
|
||||||
|
ESX.PlayerData.job = job
|
||||||
|
end)
|
||||||
|
|
||||||
|
lib.addPlayerMethod('hasGroup', function(self, filter)
|
||||||
|
local type = type(filter)
|
||||||
|
|
||||||
|
if type == 'string' then
|
||||||
|
return ESX.PlayerData.job.name == filter
|
||||||
|
end
|
||||||
|
|
||||||
|
local tabletype = table.type(filter)
|
||||||
|
|
||||||
|
if tabletype == 'hash' then
|
||||||
|
local grade = filter[ESX.PlayerData.job.name]
|
||||||
|
return grade and grade <= ESX.PlayerData.job.grade
|
||||||
|
end
|
||||||
|
|
||||||
|
if tabletype == 'array' then
|
||||||
|
for i = 1, #filter do
|
||||||
|
if ESX.PlayerData.job.name == filter[i] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
return ESX
|
return ESX
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,58 @@
|
|||||||
|
if not lib.player then lib.player() end
|
||||||
|
|
||||||
return function(resource)
|
return function(resource)
|
||||||
local QBCore = exports[resource]:GetCoreObject()
|
local QBCore = exports[resource]:GetCoreObject()
|
||||||
-- Eventually add some functions here to simplify the creation of framework-agnostic resources.
|
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)
|
||||||
|
|
||||||
|
lib.addPlayerMethod('hasGroup', function(self, filter)
|
||||||
|
local type = type(filter)
|
||||||
|
|
||||||
|
if type == 'string' then
|
||||||
|
return PlayerData.job.name == filter or PlayerData.gang.name == filter
|
||||||
|
end
|
||||||
|
|
||||||
|
local tabletype = table.type(filter)
|
||||||
|
|
||||||
|
if tabletype == 'hash' then
|
||||||
|
local jobGrade = filter[PlayerData.job.name]
|
||||||
|
|
||||||
|
if jobGrade then
|
||||||
|
return jobGrade <= PlayerData.job.grade
|
||||||
|
end
|
||||||
|
|
||||||
|
local gangGrade = filter[PlayerData.gang.name]
|
||||||
|
|
||||||
|
if gangGrade then
|
||||||
|
return gangGrade <= PlayerData.gang.grade
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if tabletype == 'array' then
|
||||||
|
for i = 1, #filter do
|
||||||
|
local group = filter[i]
|
||||||
|
|
||||||
|
if PlayerData.job.name == group or PlayerData.gang.name == group then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
return QBCore
|
return QBCore
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user