-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.lua
More file actions
143 lines (128 loc) · 4.62 KB
/
server.lua
File metadata and controls
143 lines (128 loc) · 4.62 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
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
local Framework = nil
-- Framework Detection
local function InitializeFramework()
if GetResourceState('es_extended') == 'started' then
local success, result = pcall(function()
return exports["es_extended"]:getSharedObject()
end)
if success and result then
Framework = result
print('[Pause Menu] Server initialized with ESX framework')
return 'esx'
end
end
if GetResourceState('qb-core') == 'started' then
local success, result = pcall(function()
return exports['qb-core']:GetCoreObject()
end)
if success and result then
Framework = result
print('[Pause Menu] Server initialized with QBCore framework')
return 'qbcore'
end
end
print('[Pause Menu] WARNING: No compatible framework found on server side')
return nil
end
local frameworkName = InitializeFramework()
if not frameworkName then
print('[Pause Menu] ERROR: Failed to initialize any framework. Callbacks will not work!')
return
end
-- Server Info callback (works for both frameworks)
local function RegisterServerInfoCallback()
if frameworkName == 'esx' then
Framework.RegisterServerCallback('pausemenu:getServerInfo', function(source, cb)
local ping = GetPlayerPing(source)
if ping == nil or ping == -1 then ping = 0 end
cb({
players = #GetPlayers(),
maxPlayers = GetConvarInt('sv_maxclients', 32),
ping = ping
})
end)
elseif frameworkName == 'qbcore' then
Framework.Functions.CreateCallback('pausemenu:getServerInfo', function(source, cb)
local ping = GetPlayerPing(source)
if ping == nil or ping == -1 then ping = 0 end
cb({
players = #GetPlayers(),
maxPlayers = GetConvarInt('sv_maxclients', 32),
ping = ping
})
end)
end
end
-- Time and Date callback (works for both frameworks)
local function RegisterTimeCallback()
if frameworkName == 'esx' then
Framework.RegisterServerCallback('pausemenu:getTimeDate', function(source, cb)
cb({
time = os.date(Config.Components.datetime.format.time),
date = os.date(Config.Components.datetime.format.date)
})
end)
elseif frameworkName == 'qbcore' then
Framework.Functions.CreateCallback('pausemenu:getTimeDate', function(source, cb)
cb({
time = os.date(Config.Components.datetime.format.time),
date = os.date(Config.Components.datetime.format.date)
})
end)
end
end
-- Register callbacks
RegisterServerInfoCallback()
RegisterTimeCallback()
-- Framework-specific callbacks
if frameworkName == 'esx' then
Framework.RegisterServerCallback('pausemenu:getMoney', function(source, cb)
local xPlayer = Framework.GetPlayerFromId(source)
if xPlayer then
cb({
cash = xPlayer.getMoney(),
bank = xPlayer.getAccount('bank').money
})
else
cb({ cash = 0, bank = 0 })
end
end)
Framework.RegisterServerCallback('pausemenu:getPlayerName', function(source, cb)
local xPlayer = Framework.GetPlayerFromId(source)
if xPlayer then
local result = MySQL.query.await('SELECT firstname, lastname FROM users WHERE identifier = ?', {
xPlayer.identifier
})
if result and result[1] then
cb(string.format('%s %s', result[1].firstname, result[1].lastname))
else
cb(GetPlayerName(source))
end
else
cb(GetPlayerName(source))
end
end)
elseif frameworkName == 'qbcore' then
Framework.Functions.CreateCallback('pausemenu:getMoney', function(source, cb)
local Player = Framework.Functions.GetPlayer(source)
if Player then
cb({
cash = Player.PlayerData.money['cash'],
bank = Player.PlayerData.money['bank']
})
else
cb({ cash = 0, bank = 0 })
end
end)
Framework.Functions.CreateCallback('pausemenu:getPlayerName', function(source, cb)
local Player = Framework.Functions.GetPlayer(source)
if Player then
cb(string.format('%s %s',
Player.PlayerData.charinfo.firstname,
Player.PlayerData.charinfo.lastname
))
else
cb(GetPlayerName(source))
end
end)
end