-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimports.lua
More file actions
84 lines (77 loc) · 2.2 KB
/
imports.lua
File metadata and controls
84 lines (77 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
ESX = exports['es_extended']:getSharedObject()
if not IsDuplicityVersion() then
AddEventHandler('esx:setPlayerData', function(key, val)
if GetInvokingResource() == 'es_extended' then
ESX.PlayerData[key] = val
end
end)
else
local mapKeyMethods = {
job = 'getJob',
source = 'getSource',
playerId = 'getSource',
group = 'getGroup',
identifier = 'getIdentifier',
license = 'getIdentifier',
metadata = 'getMetadata',
accounts = 'getAccounts',
inventory = 'getInventory',
loadout = 'getLoadout',
admin = 'isAdmin',
name = 'getName',
coords = 'getCoords',
}
---@class (functions) DEX.Player.Functions : DEX.Player
---@param src number
---@return DEX.Player.Functions
local function createStaticPlayer(src)
return setmetatable({ src = src }, {
__index = function(self, key)
if mapKeyMethods[key] then
local methodName = mapKeyMethods[key]
return exports.es_extended:runStaticPlayerMethod(self.src, methodName)
end
return function(...)
return exports.es_extended:runStaticPlayerMethod(self.src, key, ...)
end
end,
})
end
---@param src number|string
---@return DEX.Player.Functions?
function ESX.Player(src)
if type(src) ~= 'number' then
src = ESX.GetPlayerIdFromIdentifier(src)
if not src then
return
end
elseif not ESX.IsPlayerLoaded(src) then
return
end
return createStaticPlayer(src)
end
---@param key? string
---@param val? string|string[]
---@return DEX.Player.Functions[] | table<any, DEX.Player.Functions[]>
function ESX.ExtendedPlayers(key, val)
local playerIds = ESX.GetExtendedPlayers(key, val, true)
if key and type(val) == 'table' then
---@cast playerIds table<any, number[]>
local retVal = {}
for group, ids in pairs(playerIds) do
retVal[group] = {}
for i = 1, #ids do
retVal[group][i] = createStaticPlayer(ids[i])
end
end
return retVal
else
---@cast playerIds number[]
local retVal = {}
for i = 1, #playerIds do
retVal[i] = createStaticPlayer(playerIds[i])
end
return retVal
end
end
end