-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.lua
More file actions
105 lines (87 loc) · 2.87 KB
/
utils.lua
File metadata and controls
105 lines (87 loc) · 2.87 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Framework = Config.CoreExport()
local Names = {}
function triggerServerCallback(...)
if Config.Framework == "qb" then
Framework.Functions.TriggerCallback(...)
else
Framework.TriggerServerCallback(...)
end
end
function registerServerCallback(...)
if Config.Framework == "qb" then
Framework.Functions.CreateCallback(...)
else
Framework.RegisterServerCallback(...)
end
end
function getExtendedPlayer(src)
if Config.Framework == "qb" then
return Framework.Functions.GetPlayer(src)
elseif Config.Framework == "esx" then
return Framework.GetPlayerFromId(src)
end
end
function getPlayerLicense(player)
if Config.Framework == "qb" then
return player.PlayerData.citizenid
elseif Config.Framework == "esx" then
return player.getIdentifier()
end
end
function getMoney(player, moneyType)
if Config.Framework == "qb" then
return player.Functions.GetMoney(moneyType == "money" and "cash" or "bank")
elseif Config.Framework == "esx" then
return player.getAccount(moneyType).money
end
end
function getPlayerName(player)
if Config.Framework == "qb" then
return player.PlayerData.charinfo.firstname .. " " .. player.PlayerData.charinfo.lastname
elseif Config.Framework == "esx" then
return player.getName()
end
end
function getPlayerJob(src)
local player = getExtendedPlayer(src)
while player == nil do
Citizen.Wait(100)
player = getExtendedPlayer(src)
end
if Config.Framework == "qb" then
return { name = player.PlayerData.job.label, grade = player.PlayerData.job.grade.name }
elseif Config.Framework == "esx" then
return { name = player.job.label, grade = player.job.grade_label }
end
end
function getPlayerDiscord(src)
if not Names[src] then
local identifiers = {}
local discord = nil
for i = 0, GetNumPlayerIdentifiers(src) - 1 do
local license = GetPlayerIdentifier(src, i)
if string.sub(license, 1, string.len("discord:")) == "discord:" then
discord = license
end
end
local name = nil
if discord then
discord = string.sub(discord, 9, string.len(discord))
local p = promise.new()
PerformHttpRequest("https://discordapp.com/api/users/" .. discord, function(statusCode, data)
if statusCode == 200 then
data = json.decode(data or "{}")
if data.global_name then
name = data.global_name
end
end
p:resolve()
end, "GET", "", {
Authorization = "Bot " .. Config.DiscordBotToken
})
Citizen.Await(p)
end
Names[src] = name or "Sconosciuto"
end
return Names[src]
end