-
Notifications
You must be signed in to change notification settings - Fork 2
/
sv.lua
154 lines (142 loc) · 5.51 KB
/
sv.lua
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
local WEBHOOK = "YOUR_WEBHOOK_HERE"
local esx = GetResourceState('es_extended') == 'started'
local qb = GetResourceState('qb-core') == 'started'
local playersData = {}
local playersTime = {}
---Gets the license of a player
---@param playerId number
---@return string
---@return boolean
local function getLicense(playerId)
local identifiers = GetPlayerIdentifiers(playerId)
for i=1, #identifiers do
if identifiers[i]:match('license:') then
return identifiers[i]
end
end
return false
end
local function formatTime(seconds)
if not seconds then return 0 end
local status = {
hours = 0,
minutes = 0
}
status.hours = ("%02.f"):format(math.floor(seconds / 3600))
status.minutes = ("%02.f"):format(math.floor(seconds / 60 - (status.hours * 60)))
return status
end
local function getData(playerId)
local data = {
phone_number = 'No phone number',
connections = 0,
game_time = 0
}
if qb then
data.phone_number = QBCore.Functions.GetPlayer(playerId).PlayerData.charinfo.phone
else
data.phone_number = exports.oxmysql:singleSync('SELECT phone_number FROM users WHERE identifier = ?', {ESX.GetPlayerFromId(playerId).identifier}).phone_number
end
local license = getLicense(playerId)
if license then
local playerData = playersData[license]
if playerData then
data.connections = playerData.connections
data.game_time = formatTime(os.time() - playersTime[license] + playerData.gametime).hours
end
end
return data
end
local sendInfo = function(playerId)
if IsDuplicityVersion() then
if playerId then
local xPlayer = esx and ESX.GetPlayerFromId(playerId) or qb and QBCore.Functions.GetPlayer(playerId)
if not xPlayer or type(xPlayer) ~= "table" then
return print('Error loading player data')
end
local info = getData(playerId)
local data <const> = {
player = GetPlayerName(playerId) or 'No name',
identifier = GetPlayerIdentifier(playerId, 1) or 'No license',
name = esx and xPlayer.getName() or qb and (xPlayer.PlayerData.charinfo.firstname .. xPlayer.PlayerData.charinfo.lastname) or GetPlayerName(playerId) or 'No name',
job = esx and xPlayer.getJob().label or qb and xPlayer.PlayerData.job.label or 'No job',
height = esx and xPlayer.get('height') or qb and 'No height',
cash = esx and xPlayer.getMoney() or qb and xPlayer.PlayerData.money['money'] or 0,
bank = esx and xPlayer.getAccount('bank').money or qb and xPlayer.PlayerData.money['bank'] or 0,
dob = esx and xPlayer.get('dateofbirth') or qb and xPlayer.PlayerData.charinfo.birthdate,
phone_number = info.phone_number,
connections = info.connections,
game_time = info.game_time
}
if data and type(data) == "table" then
TriggerClientEvent('panel:setInfo', playerId, data)
end
end
end
end
local function sendDiscord(message)
local embeds = {
{
["title"] = 'User Panel Report',
["color"] = 123456,
["description"] = message
}
}
return PerformHttpRequest(WEBHOOK, function(err, text, headers) end, 'POST', json.encode({ username = username, embeds = embeds, avatar_url = avatar_url}), { ['Content-Type'] = 'application/json' })
end
AddEventHandler('playerDropped', function()
local playerId <const> = source
local license = getLicense(playerId)
local playerData = playersData[license]
if playerData then
exports.oxmysql:updateSync('UPDATE stats SET gametime = ?, connections = ? WHERE license = ? ', {os.time() - playersTime[license] + playerData.gametime, tonumber(playerData.connections) + 1, playerData.license})
playerData.connections = playerData.connections + 1
end
end)
AddEventHandler('onResourceStart', function(name)
if GetCurrentResourceName() == name then
local p = promise.new()
exports.oxmysql:execute('SELECT * FROM stats', {}, function(result)
if result and result[1] then
return p:resolve(result)
else
return p:resolve({})
end
end)
local result = Citizen.Await(p)
for i = 1, #result do
playersData[result[i].license] = result[i]
end
end
end)
RegisterNetEvent('ev:playerSet', function()
local playerId <const> = source
local license = getLicense(playerId)
if license then
local currentTime = os.time()
playersTime[license] = currentTime
local playerData = playersData[license]
if playerData then
return
end
local p = promise.new()
exports.oxmysql:insert('INSERT INTO stats (license, gametime, connections) VALUES (?, ?, ?) ', {license, '0', '0'}, function(id)
if id then
p:resolve({license = license, gametime = 0, connections = 0})
end
end)
local result = Citizen.Await(p)
playersData[result.license] = result
end
end)
RegisterNetEvent('ev:sendRequest', function(data)
if data and type(data) == "table" then
sendDiscord("```Title: " .. data.title .. "\nDescription: " .. data.desc .. "\n```")
end
end)
RegisterCommand('infoPanel', function(source)
local playerId <const> = source
if playerId > 0 then
sendInfo(playerId)
end
end)