-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
189 lines (170 loc) · 4.85 KB
/
client.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
local QBCore = exports['qb-core']:GetCoreObject()
local PlayerData
local display = false
local editing = false
-------------------------
--- Functions ---
-------------------------
local function formatNumber(num)
return string.format('%d', num):reverse():gsub('%d%d%d', '%1,'):reverse():gsub('^,', '')
end
local function isHudActive()
return display
end
exports('isHudActive', isHudActive)
--@param boolean | true/false to show/hide the display
local function ToggleHud(toggle)
if display then
SendNUIMessage({
action = 'toggleDisplay',
show = toggle
})
end
end
exports('ToggleHud', ToggleHud)
-------------------------
--- Commands ---
-------------------------
lib.addKeybind({
name = 'hud-toggle-move',
description = 'Toggle/Move the mini player hud',
defaultKey = Config.Command.toggleKey,
onPressed = function(self)
if IsControlPressed(1, 21) and display then
SendNUIMessage({
action = 'startMove',
status = true
})
SetNuiFocus(true, true)
editing = true
QBCore.Functions.Notify('Click and drag the hud to move the hud. (X) or Escape to stop.', 'primary', 10000, 'fas fa-exclamation-circle')
else
display = not display
SendNUIMessage({
action = 'toggleDisplay',
show = display
})
QBCore.Functions.Notify(display and 'Mini hud is now showing' or 'Mini hud is now hidden', 'primary', 5000, display and 'fas fa-eye' or 'fas fa-eye-slash')
end
end,
})
lib.addKeybind({
name = 'hud-reset-pos',
description = 'Reset mini player hud position',
defaultKey = Config.Command.resetKey,
onPressed = function(self)
local left = 20.50
local top = 80.50
SendNUIMessage({
action = 'setPosition',
left = left,
top = top
})
end,
})
-------------------------
--- NUI Callbacks ---
-------------------------
RegisterNUICallback('stopMove', function(data, cb)
editing = false
SetNuiFocus(false, false)
cb({})
end)
RegisterNUICallback('setDisplayState', function(data, cb)
display = data.displayState
cb({})
end)
-------------------------
--- Threads/Loops ---
-------------------------
CreateThread(function()
while true do
Wait(2000) -- 2 second loop, adjust as necessary
if (GetPauseMenuState() ~= 0 or IsNuiFocused()) and not editing then
ToggleHud(false)
elseif not editing then
ToggleHud(true)
end
end
end)
-------------------------
--- Base Events ---
-------------------------
RegisterNetEvent('QBCore:Client:OnMoneyChange', function(moneyType, _, changeType)
local playerData = QBCore.Functions.GetPlayerData()
local account, amount
if moneyType == 'cash' then
account = 'cash'
amount = formatNumber(playerData.money['cash'])
elseif moneyType == 'bank' then
account = 'bank'
amount = formatNumber(playerData.money['bank'])
end
if Config.Debug then print('OnMoneyChange', account, amount, changeType) end
if account and amount then
SendNUIMessage({
action = 'moneyChange',
account = account,
amount = amount,
changeType = changeType
})
end
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
if Config.Debug then QBCore.Debug(JobInfo) end
SendNUIMessage({
action = 'jobChange',
job = JobInfo.label
})
end)
RegisterNetEvent('QBCore:Client:OnGangUpdate', function(InfoGang)
if Config.Debug then QBCore.Debug(InfoGang) end
SendNUIMessage({
action = 'gangChange',
gang = InfoGang.label
})
end)
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function ()
Wait(2000)
PlayerData = QBCore.Functions.GetPlayerData()
local cash = formatNumber(PlayerData.money['cash'])
local bank = formatNumber(PlayerData.money['bank'])
if Config.Debug then print('OnPlayerLoaded', PlayerData.source, PlayerData.job.label, PlayerData.gang.label, cash, bank) end
SendNuiMessage(json.encode({
action = 'playerData',
id = PlayerData.source,
job = PlayerData.job.label,
gang = PlayerData.gang.label,
cash = cash,
bank = bank
}))
Wait(1000)
SendNUIMessage({
action = 'toggleDisplay',
init = true
})
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
PlayerData = {}
end)
AddEventHandler('onResourceStart', function(resource)
if resource ~= GetCurrentResourceName() then return end
Wait(1000)
PlayerData = QBCore.Functions.GetPlayerData()
local cash = formatNumber(PlayerData.money['cash'])
local bank = formatNumber(PlayerData.money['bank'])
if Config.Debug then print('onResourceStart', PlayerData.source, PlayerData.job.label, PlayerData.gang.label, cash, bank) end
SendNuiMessage(json.encode({
action = 'playerData',
id = PlayerData.source,
job = PlayerData.job.label,
gang = PlayerData.gang.label,
cash = cash,
bank = bank
}))
Wait(1000)
SendNUIMessage({
action = 'toggleDisplay',
init = true
})
end)