forked from Project-Sloth/ps-hud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.lua
209 lines (176 loc) · 6.9 KB
/
server.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
local QBCore = exports['qb-core']:GetCoreObject()
local ResetStress = false
QBCore.Commands.Add('cash', Lang:t('info.check_cash_balance'), {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
local cashamount = Player.PlayerData.money.cash
TriggerClientEvent('hud:client:ShowAccounts', source, 'cash', cashamount)
end)
QBCore.Commands.Add('bank', Lang:t('info.check_bank_balance'), {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
local bankamount = Player.PlayerData.money.bank
TriggerClientEvent('hud:client:ShowAccounts', source, 'bank', bankamount)
end)
QBCore.Commands.Add("dev", Lang:t('info.toggle_dev_mode'), {}, false, function(source, args)
TriggerClientEvent("qb-admin:client:ToggleDevmode", source)
end, 'admin')
RegisterNetEvent('hud:server:GainStress', function(amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local newStress
if not Player or (Config.DisablePoliceStress and Player.PlayerData.job.type == 'leo') then return end
if not Player or (Config.DisableAmbulanceStress and (Player.PlayerData.job.name == 'ambulance' or Player.PlayerData.job.name == 'practitioner')) then return end
if not ResetStress then
if not Player.PlayerData.condition.stress then
Player.Functions.SetStress(0)
end
newStress = Player.PlayerData.condition.stress + amount
if newStress <= 0 then newStress = 0 end
else
newStress = 0
end
if newStress > 100 then
newStress = 100
end
Player.Functions.SetStress(newStress)
TriggerClientEvent('hud:client:UpdateStress', src, newStress)
TriggerClientEvent('QBCore:Notify', src, Lang:t("notify.stress_gain"), 'error', 1500)
end)
RegisterNetEvent('hud:server:RelieveStress', function(amount)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local newStress
if not Player then return end
if not ResetStress then
if not Player.PlayerData.condition.stress then
Player.PlayerData.condition.stress = 0
end
newStress = Player.PlayerData.condition.stress - amount
if newStress <= 0 then newStress = 0 end
else
newStress = 0
end
if newStress > 100 then
newStress = 100
end
Player.Functions.SetStress(newStress)
TriggerClientEvent('hud:client:UpdateStress', src, newStress)
TriggerClientEvent('QBCore:Notify', src, Lang:t("notify.stress_removed"))
end)
RegisterNetEvent('hud:server:saveUIData', function(data)
local src = source
-- Check Permissions
if not QBCore.Functions.HasPermission(src, 'admin') and not IsPlayerAceAllowed(src, 'command') then
return
end
-- Ensure a player is invoking this net event
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local uiConfigData = {}
uiConfigData.icons = {}
local path = GetResourcePath(GetCurrentResourceName())
path = path:gsub('//', '/')..'/uiconfig.lua'
local file = io.open(path, 'w+')
local heading = "UIConfig = {}\n"
file:write(heading)
-- write out icons
file:write("\nUIConfig.icons = {}\n")
-- Sort the icons so its easier to find in the config file
local iconKeys = {}
for k, _ in pairs(data.icons) do
table.insert(iconKeys, k)
end
table.sort(iconKeys)
for _, iconName in ipairs(iconKeys) do
uiConfigData.icons[iconName] = {}
local iconLabel = "\nUIConfig.icons['"..iconName.."'] = {"
file:write(iconLabel)
-- sort the values as well inside icons
local iconValues = {}
for k, _ in pairs(data.icons[iconName]) do
table.insert(iconValues, k)
end
table.sort(iconValues)
for _, iconValueName in ipairs(iconValues) do
local str
local v = data.icons[iconName][iconValueName]
uiConfigData.icons[iconName][iconValueName] = v
if type(v) == "string" then
str = ("\n %s = '%s',"):format(iconValueName, v)
else
str = ("\n %s = %s,"):format(iconValueName, v)
end
file:write(str)
end
file:write("\n}\n")
end
--local layoutLabel = "\nUIConfig.layout = '"..data.layout.."'\n"
local layoutLabel = "\nUIConfig.layout = {"
file:write(layoutLabel)
for layoutName, layoutVal in pairs(data.layout) do
local str
if type(layoutVal) == "string" then
str = ("\n %s = '%s',"):format(layoutName, layoutVal)
else
str = ("\n %s = %s,"):format(layoutName, layoutVal)
end
file:write(str)
end
file:write("\n}\n")
uiConfigData.layout = data.layout
-- write out color icons info
file:write("\nUIConfig.colors = {}\n")
uiConfigData.colors = {}
-- Sort the color keys
local colorKeys = {}
for k, _ in pairs(data.colors) do
table.insert(colorKeys, k)
end
table.sort(colorKeys)
for _, colorName in ipairs(colorKeys) do
uiConfigData.colors[colorName] = {}
uiConfigData.colors[colorName].colorEffects = {}
local colorLabel = "\nUIConfig.colors['"..colorName.."'] = {"
file:write(colorLabel)
local colorEffectsLabel = "\n colorEffects = {"
file:write(colorEffectsLabel)
for k, v in ipairs(data.colors[colorName].colorEffects) do
local colorEffectIndexLabel = "\n ["..k.."] = {"
file:write(colorEffectIndexLabel)
-- sort the values as well inside color effects
local colorEffect = data.colors[colorName].colorEffects[k]
local colorEffectkeys = {}
for scekey, _ in pairs(colorEffect) do
table.insert(colorEffectkeys, scekey)
end
table.sort(colorEffectkeys)
table.insert(uiConfigData.colors[colorName].colorEffects, colorEffect)
for _, CEKey in ipairs(colorEffectkeys) do
local str
if type(colorEffect[CEKey]) == "string" then
str = ("\n %s = '%s',"):format(CEKey, colorEffect[CEKey])
else
str = ("\n %s = %s,"):format(CEKey, colorEffect[CEKey])
end
file:write(str)
end
file:write("\n },")
end
file:write("\n },")
file:write("\n}\n")
end
file:close()
UIConfig = uiConfigData
-- -1 to send to all players
TriggerClientEvent('hud:client:UpdateUISettings', -1, uiConfigData)
end)
QBCore.Functions.CreateCallback('hud:server:getMenu', function(source, cb)
cb(Config.Menu)
end)
QBCore.Functions.CreateCallback('hud:server:getRank', function(source, cb)
local src = source
if QBCore.Functions.HasPermission(src, 'admin') or IsPlayerAceAllowed(src, 'command') then
cb(true)
else
cb(false)
end
end)