mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(getCore/client): clean up hasGroup method and return values
This commit is contained in:
@@ -11,28 +11,30 @@ return function(resource)
|
|||||||
ESX.PlayerData.job = job
|
ESX.PlayerData.job = job
|
||||||
end)
|
end)
|
||||||
|
|
||||||
lib.addPlayerMethod('hasGroup', function(self, filter)
|
lib.addPlayerMethod('hasGroup', function(_, filter)
|
||||||
|
local data = ESX.PlayerData
|
||||||
local type = type(filter)
|
local type = type(filter)
|
||||||
|
|
||||||
if type == 'string' then
|
if type == 'string' then
|
||||||
return ESX.PlayerData.job.name == filter
|
if data.job.name == filter then
|
||||||
end
|
return data.job.name, data.job.grade
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local tabletype = table.type(filter)
|
||||||
|
|
||||||
local tabletype = table.type(filter)
|
if tabletype == 'hash' then
|
||||||
|
local grade = filter[data.job.name]
|
||||||
|
|
||||||
if tabletype == 'hash' then
|
if grade and grade <= data.job.grade then
|
||||||
local grade = filter[ESX.PlayerData.job.name]
|
return data.job.name, data.job.grade
|
||||||
return grade and grade <= ESX.PlayerData.job.grade
|
end
|
||||||
end
|
elseif tabletype == 'array' then
|
||||||
|
for i = 1, #filter do
|
||||||
if tabletype == 'array' then
|
if data.job.name == filter[i] then
|
||||||
for i = 1, #filter do
|
return data.job.name, data.job.grade
|
||||||
if ESX.PlayerData.job.name == filter[i] then
|
end
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -16,41 +16,44 @@ return function(resource)
|
|||||||
PlayerData.gang = gang
|
PlayerData.gang = gang
|
||||||
end)
|
end)
|
||||||
|
|
||||||
lib.addPlayerMethod('hasGroup', function(self, filter)
|
local groups = { 'job', 'gang' }
|
||||||
|
|
||||||
|
lib.addPlayerMethod('hasGroup', function(_, filter)
|
||||||
local type = type(filter)
|
local type = type(filter)
|
||||||
|
|
||||||
if type == 'string' then
|
if type == 'string' then
|
||||||
return PlayerData.job.name == filter or PlayerData.gang.name == filter
|
for i = 1, #groups do
|
||||||
end
|
local data = PlayerData[groups[i]]
|
||||||
|
|
||||||
local tabletype = table.type(filter)
|
if data.name == filter then
|
||||||
|
return data.name, data.grade.level
|
||||||
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
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local tabletype = table.type(filter)
|
||||||
|
|
||||||
return false
|
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.group.name, data.grade.level
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
2
init.lua
2
init.lua
@@ -158,6 +158,8 @@ local cache = setmetatable({}, {
|
|||||||
self.serverId = GetPlayerServerId(self.playerId)
|
self.serverId = GetPlayerServerId(self.playerId)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.resource = GetCurrentResourceName()
|
||||||
|
|
||||||
if ox.groups then
|
if ox.groups then
|
||||||
self.groups = setmetatable({}, {
|
self.groups = setmetatable({}, {
|
||||||
__index = function(groups, index)
|
__index = function(groups, index)
|
||||||
|
|||||||
Reference in New Issue
Block a user