-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmenu.lua
335 lines (311 loc) · 11 KB
/
menu.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
local STATE_MESSAGE = {
[-1] = {msg = "~m~(MISSING)", desc = "The resource could not be found, likely due to a change of name."},
[0] = {msg = "~r~(STOPPED)", desc = "The resource was found but not running."},
[1] = {msg = "~g~(RUNNING)", desc = "The resource was found and running."}
}
local SAS_STATE = -1
local WMSS_STATE = -1
local USE_SUBMENUS = false
local SAS_DEPARTMENTS = { }
local WMSS_REFS = { }
local REQD_AUDIO_BANKS = { }
local DEBUG_MODE = false
local NOTIFIED = false
--MENUS
RMenu.Add('SSAT', 'main', RageUI.CreateMenu("Server Side Audio Tester", "Main Menu"))
RMenu.Add('SSAT', 'sas', RageUI.CreateSubMenu(RMenu:Get('SSAT', 'main'),"Server Side Audio Tester", "Server Sided Sounds and Sirens (SAS)"))
RMenu.Add('SSAT', 'wmss', RageUI.CreateSubMenu(RMenu:Get('SSAT', 'main'),"Server Side Audio Tester", "WM-ServerSirens (WM-SS)"))
RMenu:Get('SSAT', 'main'):SetTotalItemsPerPage(13)
RMenu:Get('SSAT', 'main'):DisplayGlare(false)
RMenu:Get('SSAT', 'sas'):DisplayGlare(false)
RMenu:Get('SSAT', 'wmss'):DisplayGlare(false)
RegisterCommand("ssat", function(source, args)
RageUI.Visible(RMenu:Get('SSAT', 'main'), not RageUI.Visible(RMenu:Get('SSAT', 'main')))
if not NOTIFIED then
--HUD Notification
AddTextEntry("SSAT_Start","~b~SSAT~s~: Remember, ~y~server side audio is only loaded at join~s~. In order for changes to take effect please restart the resource and rejoin.")
SetNotificationTextEntry("SSAT_Start")
DrawNotification(false, true)
--Chat Notification
TriggerEvent('chat:addMessage', {
multiline = true,
args = {"~b~SSAT~s~", "Remember, ~y~server side audio is only loaded at join~s~. In order for changes to take effect please restart the resource and rejoin."}
})
NOTIFIED = true
end
end)
RegisterCommand("ssatdebug", function(source, args)
DEBUG_MODE = not DEBUG_MODE
print("DEBUG_MODE: ",DEBUG_MODE)
end)
--print function based on debug_mode state
function PRINT(text)
if DEBUG_MODE then
print(text)
end
end
--FIFO Audio Banks, adds and requests audio banks up to 7 then releases oldest
function ReqNewAudioBank(bank)
print(bank)
while #REQD_AUDIO_BANKS > 6 do
ReleaseNamedScriptAudioBank(REQD_AUDIO_BANKS[7])
ReleaseScriptAudioBank()
table.remove(REQD_AUDIO_BANKS, 7)
end
for i,v in ipairs(REQD_AUDIO_BANKS) do
if v == bank then
return
end
end
RequestScriptAudioBank(bank)
Citizen.Wait(50)
table.insert(REQD_AUDIO_BANKS, 1, bank)
end
--Returns true if any menu is open
function IsMenuOpen()
local submenu_open = false
for i,dept in ipairs(SAS_DEPARTMENTS) do
if RageUI.Visible(RMenu:Get('SSAT', dept)) then
submenu_open = true
end
end
for i,ref in ipairs(WMSS_REFS) do
if RageUI.Visible(RMenu:Get('SSAT', ref)) then
submenu_open = true
end
end
return RageUI.Visible(RMenu:Get('SSAT', 'main')) or
RageUI.Visible(RMenu:Get('SSAT', 'sas')) or
RageUI.Visible(RMenu:Get('SSAT', 'wmss')) or
submenu_open
end
--Handle Disabling Controls while menu open
Citizen.CreateThread(function()
Citizen.Wait(1000)
while true do
while IsMenuOpen() do
DisableControlAction(0, 27, true)
DisableControlAction(0, 99, true)
DisableControlAction(0, 172, true)
DisableControlAction(0, 173, true)
DisableControlAction(0, 174, true)
DisableControlAction(0, 175, true)
Citizen.Wait(0)
end
Citizen.Wait(100)
end
end)
Citizen.CreateThread(function()
--Build submenus dynamically for submenu organization (USE_SUBMENUS)
for i,soundset in ipairs(SAS_STRING_REF) do
ref = soundset[1]
bank_substring = string.sub(ref,1,-10)
dept = string.sub(bank_substring,17,-1)
RMenu.Add('SSAT', dept, RageUI.CreateSubMenu(RMenu:Get('SSAT', 'sas'), "Server Side Audio Tester", bank_substring))
RMenu:Get('SSAT', dept):DisplayGlare(false)
end
for i,soundset in ipairs(SAS_STRING_REF) do
ref = soundset[1]
bank_substring = string.sub(ref,1,-10)
dept = string.sub(bank_substring,17,-1)
table.insert(SAS_DEPARTMENTS, dept)
end
for i,soundset in ipairs(WMSS_STRING_REF) do
ref = soundset[1]
RMenu.Add('SSAT', ref, RageUI.CreateSubMenu(RMenu:Get('SSAT', 'wmss'), "Server Side Audio Tester", ref))
RMenu:Get('SSAT', ref):DisplayGlare(false)
end
for i,soundset in ipairs(WMSS_STRING_REF) do
ref = soundset[1]
table.insert(WMSS_REFS, ref)
end
--Resource state checking, are the resources even running?
local SAS_STATE_STRING = ""
local WMSS_STATE_STRING = ""
while true do
Citizen.Wait(1000)
SAS_STATE_STRING = GetResourceState(SAS_RESOURCE_NAME)
WMSS_STATE_STRING = GetResourceState(WMSS_RESOURCE_NAME)
if SAS_STATE_STRING == "started" or SAS_STATE_STRING == "starting" then
SAS_STATE = 1
elseif SAS_STATE_STRING == "stopped" or SAS_STATE_STRING == "stopping" then
SAS_STATE = 0
else
SAS_STATE = -1
end
if WMSS_STATE_STRING == "started" or WMSS_STATE_STRING == "starting" then
WMSS_STATE = 1
elseif WMSS_STATE_STRING == "stopped" or WMSS_STATE_STRING == "stopping" then
WMSS_STATE = 0
else
WMSS_STATE = -1
end
end
end)
Citizen.CreateThread(function()
local sound_id, siren_name, bank_substring, dept, bank, ref
local last_siren
while true do
--Main Menu Visible
RageUI.IsVisible(RMenu:Get('SSAT', 'main'), function()
RageUI.Separator("Resource Status")
RageUI.Button('SAS Resource State', STATE_MESSAGE[SAS_STATE].desc, {RightLabel = STATE_MESSAGE[SAS_STATE].msg}, true, {
onSelected = function()
end,
})
RageUI.Button('WM-SS Resource State', STATE_MESSAGE[WMSS_STATE].desc, {RightLabel = STATE_MESSAGE[WMSS_STATE].msg}, true, {
onSelected = function()
end,
})
RageUI.Checkbox('Submenu Organization', "Toggles whether to list all sirens on one page or to sort them into submenus.", USE_SUBMENUS, {}, {
onChecked = function()
USE_SUBMENUS = true
end,
onUnChecked = function()
USE_SUBMENUS = false
end,
})
RageUI.Button('Server Sided Sounds and Sirens (SAS)', "Test the 'Server Sided Sounds and Sirens' resource.", {RightLabel = "→→→"}, SAS_STATE == 1, {
}, RMenu:Get('SSAT', 'sas'))
RageUI.Button('WM-ServerSirens (WM-SS)', "Test the 'WM-ServerSirens' resource.", {RightLabel = "→→→"}, WMSS_STATE == 1, {
onSelected = function()
for i,bank in ipairs(WMSS_BANKS) do
ReqNewAudioBank(bank)
end
end,
}, RMenu:Get('SSAT', 'wmss'))
end)
---------------------------------------------------------------------
-------------------------------SAS MENUS-----------------------------
---------------------------------------------------------------------
if not USE_SUBMENUS then
--LIST OF TONES NOT ORGANIZED
RageUI.IsVisible(RMenu:Get('SSAT', 'sas'), function()
for i,soundset in ipairs(SAS_STRING_REF) do
ref = soundset[1]
bank_substring = string.sub(ref,1,-10)
dept = string.sub(bank_substring,17,-1)
RageUI.Separator(dept)
for i, string in ipairs(soundset[2]) do
siren_name = string.sub(string,17,-1)
RageUI.Button(siren_name, "Play OISS_SSA_VEHAUD_"..siren_name, {RightLabel = "→→→"}, true, {
onSelected = function()
bank = string.format("DLC_SERVERSIDEAUDIO\\%s", bank_substring)
ReqNewAudioBank(bank)
StopSound(sound_id)
ReleaseSoundId(sound_id)
if siren_name ~= last_siren then
sound_id = GetSoundId()
last_siren = siren_name
PlaySoundFrontend(sound_id, string, ref, 0)
PRINT(string.format("Playing from BANK: \"%s\" STRING: \"%s\" REF: \"%s\"", bank, string, ref))
else
last_siren = nil
end
end,
})
end
end
end)
else
--BUTTON DISPLAY FOR SUBMENUS btn->audioref submenu
RageUI.IsVisible(RMenu:Get('SSAT', 'sas'), function()
for i,soundset in ipairs(SAS_STRING_REF) do
ref = soundset[1]
bank_substring = string.sub(ref,1,-10)
dept = string.sub(bank_substring,17,-1)
RageUI.Button(dept, "Open tones for \""..dept.."\".", {RightLabel = "→→→"}, true, {
}, RMenu:Get('SSAT', dept))
end
end)
--AUDIOREF ORGANIZED SUBMENUS
for i,dept in ipairs(SAS_DEPARTMENTS) do
RageUI.IsVisible(RMenu:Get('SSAT', dept), function()
for _, string in ipairs(SAS_STRING_REF[i][2]) do
siren_name = string.sub(string,17,-1)
RageUI.Button(siren_name, "Play OISS_SSA_VEHAUD_"..siren_name, {RightLabel = "→→→"}, true, {
onSelected = function()
bank_substring = string.sub(SAS_STRING_REF[i][1],1,-10)
bank = string.format("DLC_SERVERSIDEAUDIO\\%s", bank_substring)
ReqNewAudioBank(bank)
StopSound(sound_id)
ReleaseSoundId(sound_id)
if siren_name ~= last_siren then
sound_id = GetSoundId()
last_siren = siren_name
PlaySoundFrontend(sound_id, string, SAS_STRING_REF[i][1], 0)
PRINT(string.format("Playing from BANK: \"%s\" STRING: \"%s\" REF: \"%s\"", bank, string, SAS_STRING_REF[i][1]))
else
last_siren = nil
end
end,
})
end
end)
end
end
---------------------------------------------------------------------
-------------------------------WMSS MENUS-----------------------------
---------------------------------------------------------------------
if not USE_SUBMENUS then
--LIST OF TONES NOT ORGANIZED
RageUI.IsVisible(RMenu:Get('SSAT', 'wmss'), function()
for i,soundset in ipairs(WMSS_STRING_REF) do
ref = soundset[1]
if i == 1 then
RageUI.Separator(ref)
else
RageUI.Separator(ref.." (PAID)")
end
for i, string in ipairs(soundset[2]) do
RageUI.Button(string, "Play "..ref.."_"..string, {RightLabel = "→→→"}, true, {
onSelected = function()
StopSound(sound_id)
ReleaseSoundId(sound_id)
if string ~= last_siren then
sound_id = GetSoundId()
last_siren = string
PlaySoundFrontend(sound_id, string, ref, 0)
PRINT(string.format("Playing from BANK: \"%s\" STRING: \"%s\" REF: \"%s\"", bank, string, ref))
else
last_siren = nil
end
end,
})
end
end
end)
else
--BUTTON DISPLAY FOR SUBMENUS btn->audioref submenu
RageUI.IsVisible(RMenu:Get('SSAT', 'wmss'), function()
for i,soundset in ipairs(WMSS_STRING_REF) do
ref = soundset[1]
RageUI.Button(ref, "Open tones for \""..ref.."\".", {RightLabel = "→→→"}, true, {
}, RMenu:Get('SSAT', ref))
end
end)
--AUDIOREF ORGANIZED SUBMENUS
for i,ref in ipairs(WMSS_REFS) do
RageUI.IsVisible(RMenu:Get('SSAT', ref), function()
for _, string in ipairs(WMSS_STRING_REF[i][2]) do
RageUI.Button(string, "Play "..ref.."_"..string, {RightLabel = "→→→"}, true, {
onSelected = function()
StopSound(sound_id)
ReleaseSoundId(sound_id)
if string ~= last_siren then
sound_id = GetSoundId()
last_siren = string
PlaySoundFrontend(sound_id, string, ref, 0)
PRINT(string.format("Playing from BANK: \"%s\" STRING: \"%s\" REF: \"%s\"", bank, string, ref))
else
last_siren = nil
end
end,
})
end
end)
end
end
Citizen.Wait(0)
end
end)