-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMuteBardsImproved.lua
More file actions
387 lines (341 loc) · 15.9 KB
/
MuteBardsImproved.lua
File metadata and controls
387 lines (341 loc) · 15.9 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
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
MBI = {
name = "MuteBardsImproved",
version = "1.0.0",
author = "psi-pisi"
};
VOLUME_TYPES = {
BARD = "bard";
MUSIC = "music";
}
local currentActiveZone;
local currentMainZone;
local defaultBardZones = {
"Mistral", -- Zone: Khenarthi's Roost Location: Mistral Bard: Eye-Fancy
"Skywatch Wayshrine", -- Zone: Auridon Location: Skywatch Bard: Annagail
"Skywatch", -- Zone: Auridon Location: Skywatch Bard: Lorais
"Firsthold", -- Zone: Auridon Location: Firsthold Bard: Ealare
"Elden Root", -- Zone: Grathwood Location: Elden Root Bard: Fasana
"Marbruk", -- Zone: Greenshade Location: Marbruk Bard: Elderien
"Woodhearth", -- Zone: Greenshade Location: Woodhearth Bard: Rendarion
"Velyn Harbor", -- Zone: Malabal Tor Location: Velyn Harbor Bard: Gilinora Birdsong
"Daggerfall Castle Town", -- Zone: Glenumbra Location: Daggerfall Bard: Axel Plourde
"Wayrest Residential District", -- Zone: Stormhaven Location: Wayrest Bard: Oceane Coravel
"Davon's Watch", -- Zone: Stonefalls Location: Davon's Watch Bard: Siriaki Black-Owl
"Ebonheart", -- Zone: Stonefalls Location: Ebonheart Bard: Helpirion
"Kragenmoor", -- Zone: Stonefalls Location: Kragenmoor Bard: Odrys Drim
"Mournhold Residential District", -- Zone: Deshaan Location: Mournhold Bard: Athanas Samori
"Mournhold Guild Plaza", -- Zone: Deshaan Location: Mournhold Bard: Ophalia Strong-Voice
"Riften", -- Zone: The Rift Location: Riften Bard: Anriel
"Nimalten", -- Zone: The Rift Location: Nimalten Bard: Enjaadia
"Ivarstead", -- Zone: The Rift Location: Ivarstead Bard: Eofel
"Windhelm", -- Zone: Eastmarch Location: Windhelm Bard: Arani Longhair & Garrimar & Nil the Bard & Fargurd
"Fort Amol", -- Zone: Eastmarch Location: Fort Amol Bard: Holsorr the Tuneful
"Stormhold", -- Zone: Shadowfen Location: Stormhold Bard: Littrel Green-Hilt
"Rawl'kha", -- Zone: Reaper's March Location: Rawl'kha Bard: No name
"Sentinel", -- Zone: Alik'r Dessert Location: Sentinel Bard: Serosh & Taralqua the Minstrel
"Evermore", -- Zone: Bangkorai Location: Evermore Bard: Nimirazan
"Belkarth", -- Zone: Craglorn Location: Belkarth Bard: Petronious Libo
"Dragonstar", -- Zone: Craglorn Location: Dragonstar Bard: Beritta Crow-Song
"Leyawiin", -- Zone: Blackwood Location: Leyawiin Bard: Audania Decanius
"Gideon", -- Zone: Blackwood Location: Gideon Bard: Haderus Vano
"Fargrave City District", -- Zone: The Deadlands Location: Fargrave Bard: Tirasie Mirel & Alain Caria
"Vastyr", -- Zone: Galen Location: Vastyr Bard: Luce Gemain
"Gonfalon Bay", -- Zone: High Isle Location: Gonfalon Bay Bard: Portic Boulat
"Lilmoth", -- Zone: Murkmire Location: Lilmoth Bard: Kalanu
"Bright-Throat Village", -- Zone: Murkmire Location: Bright-Throat Village Bard: Ah-Seshs
"Rimmen", -- Zone: Northern Elsweyr Location: Rimmen Bard: Daahin
"Senchal", -- Zone: Southern Elsweyr Location: Senchal Bard: Ja-zinki & Rakzzin
"Alinor", -- Zone: Summerset Location: Alinor Bard: Laeriwene
"Shimmerene", -- Zone: Summerset Location: Shimmerene Bard: Endolale
"Necrom", -- Zone: Telvanni Peninsula Location: Necrom Bard: Tolvise DoSWran
"Markarth", -- Zone: The Reach Location: Markarth Bard: Tisnevere
"Vivec City", -- Zone: Vvardenfell Location: Vivec City Bard: Mrylav Aralor & Altansawen
"Skingrad" -- Zone: West Weald Location: Skingrad Bard: Ita Dannus
}
MBI.AccountDefaults = {
currentActiveZone = '',
currentMainZone = '',
sfxVolume = 70,
musicVolume = 70,
printLogs = true,
mutedBardZones = {},
mutedMusicZones = {}
};
local isBardMuted = false
local isMusicMuted = false
local next = next
function table.removekey(table, key)
local element = table[key]
table[key] = nil
return element
end
local function getMutedBardZones(accountDefaults)
return accountDefaults and accountDefaults.mutedBardZones;
end
local function getMutedMusicZones(accountDefaults)
return accountDefaults and accountDefaults.mutedMusicZones;
end
local function setVolume(volume, type)
if (type == VOLUME_TYPES.BARD) then
SetSetting(SETTING_TYPE_AUDIO, AUDIO_SETTING_SFX_VOLUME, volume);
end
if (type == VOLUME_TYPES.MUSIC) then
SetSetting(SETTING_TYPE_AUDIO, AUDIO_SETTING_MUSIC_VOLUME, volume);
end
end
local function OnAddOnLoaded(addOnName)
if (addOnName ~= MBI.name) then
MBI:Initialize()
end
end
function MBI:Initialize()
--create the default table
--create the saved variable access object here and assign it to savedVars
MBI.SavedVariables = ZO_SavedVars:NewAccountWide("MuteBardsImproved_Settings", MBI.version, nil, MBI.AccountDefaults, GetWorldName());
-- if the addon is older version then need to create new variables and remove the old ones
if MBI.SavedVariables.currentZone ~= nil then
local zoneIndex = GetCurrentMapZoneIndex()
local mainZone = zo_strformat(SI_UNIT_NAME, GetZoneNameByIndex(zoneIndex))
MBI.AccountDefaults.currentActiveZone = MBI.SavedVariables.currentZone
MBI.AccountDefaults.currentMainZone = mainZone
MBI.AccountDefaults.sfxVolume = MBI.SavedVariables.volume
MBI.AccountDefaults.musicVolume = MBI.SavedVariables.volume
MBI.AccountDefaults.printLogs = MBI.SavedVariables.printLogs
if next(MBI.SavedVariables.mutedZones) == nil then
MBI.SavedVariables.mutedBardZones = defaultBardZones
MBI.AccountDefaults.mutedBardZones = defaultBardZones
else
for index, data in pairs(MBI.SavedVariables.mutedZones) do
MBI.AccountDefaults.mutedBardZones[index] = data
end
end
table.removekey(MBI.SavedVariables, "currentZone")
table.removekey(MBI.SavedVariables, "volume")
table.removekey(MBI.SavedVariables, "mutedZones")
end
if MBI.SavedVariables.currentActiveZone ~= nil then
MBI.AccountDefaults.currentActiveZone = MBI.SavedVariables.currentActiveZone
MBI.AccountDefaults.currentMainZone = MBI.SavedVariables.currentMainZone
MBI.AccountDefaults.sfxVolume = MBI.SavedVariables.sfxVolume
MBI.AccountDefaults.musicVolume = MBI.SavedVariables.musicVolume
MBI.AccountDefaults.printLogs = MBI.SavedVariables.printLogs
if next(MBI.SavedVariables.mutedBardZones) == nil then
MBI.SavedVariables.mutedBardZones = defaultBardZones
MBI.AccountDefaults.mutedBardZones = defaultBardZones
else
for index, data in pairs(MBI.SavedVariables.mutedBardZones) do
MBI.AccountDefaults.mutedBardZones[index] = data
end
end
if next(MBI.SavedVariables.mutedMusicZones) ~= nil then
for index, data in pairs(MBI.SavedVariables.mutedMusicZones) do
MBI.AccountDefaults.mutedMusicZones[index] = data
end
end
end
--Unregister Loaded Callback
EVENT_MANAGER:UnregisterForEvent(MBI.name, EVENT_ADD_ON_LOADED);
MBI:InitSettingsPanel(MBI.AccountDefaults);
MBI:Refresh();
end
function MBI:TogglePrintLogs(value)
MBI.AccountDefaults.printLogs = value
MBI.SavedVariables.printLogs = MBI.AccountDefaults.printLogs
end
function MBI:ChangeVolume(value, type)
if(type == VOLUME_TYPES.BARD) then
MBI.AccountDefaults.sfxVolume = value
MBI.SavedVariables.sfxVolume = MBI.AccountDefaults.sfxVolume
else
MBI.AccountDefaults.musicVolume = value
MBI.SavedVariables.musicVolume = MBI.AccountDefaults.musicVolume
end
end
function MBI:AddZone(zoneName, type, cb)
local result
if (type == VOLUME_TYPES.BARD) then
result = self:ContainsZone(zoneName, nil)
else
result = self:ContainsZone(nil, zoneName)
end
if (result ~= nil and result[type] == true) then
d(MBI.name .. '> Zone "' .. zoneName .. '" is already in the muted ' .. type .. ' zones list.');
return;
end
if (type == VOLUME_TYPES.BARD) then
d(MBI.name .. '> Adding zone "' .. zoneName .. '" to the muted ' .. type .. ' zones list.');
table.insert(MBI.AccountDefaults.mutedBardZones, zoneName);
MBI.SavedVariables.mutedBardZones = MBI.AccountDefaults.mutedBardZones
else
d(MBI.name .. '> Adding zone "' .. zoneName .. '" to the muted ' .. type .. ' zones list.');
table.insert(MBI.AccountDefaults.mutedMusicZones, zoneName);
MBI.SavedVariables.mutedMusicZones = MBI.AccountDefaults.mutedMusicZones
end
if (cb ~= nil) then
cb();
end
end
function MBI:RemoveZone(zoneName, type, cb)
local result
if (type == VOLUME_TYPES.BARD) then
result = self:ContainsZone(zoneName, nil)
else
result = self:ContainsZone(nil, zoneName)
end
if (result == nil or result[type] == false) then
return
end
if (type == VOLUME_TYPES.BARD) then
for i, v in pairs(getMutedBardZones(MBI.AccountDefaults)) do
if (v:lower() == zoneName:lower()) then
table.remove(MBI.AccountDefaults.mutedBardZones, i)
MBI.SavedVariables.mutedBardZones = MBI.AccountDefaults.mutedBardZones
d(MBI.name .. '> Zone "' .. zoneName .. '" is removed from the muted ' .. type .. ' zones list.');
if (cb ~= nil) then
cb();
end
return
end
end
else
for i, v in pairs(getMutedMusicZones(MBI.AccountDefaults)) do
if (v:lower() == zoneName:lower()) then
table.remove(MBI.AccountDefaults.mutedMusicZones, i)
MBI.SavedVariables.mutedMusicZones = MBI.AccountDefaults.mutedMusicZones
d(MBI.name .. '> Zone "' .. zoneName .. '" is removed from the muted ' .. type .. ' zones list.');
if (cb ~= nil) then
cb();
end
return
end
end
end
end
function MBI:ContainsZone(activeZone, mainZone)
local result = {
bard = false,
music = false
};
if(getMutedBardZones(MBI.AccountDefaults) ~= nil) then
for i, v in ipairs(getMutedBardZones(MBI.AccountDefaults)) do
if (v ~= nil and activeZone ~= nil) then -- protects against indexing nil on next line
if (v:lower() == activeZone:lower()) then
result.bard = true
end
end
end
end
if(getMutedMusicZones(MBI.AccountDefaults) ~= nil) then
for i, v in ipairs(getMutedMusicZones(MBI.AccountDefaults)) do
if (v ~= nil and mainZone ~= nil) then -- protects against indexing nil on next line
if (v:lower() == mainZone:lower()) then
result.music = true
end
end
end
end
return result;
end
function MBI:GetZoneNames()
local mapName = GetMapName()
local playerActiveSubzoneName = ZO_CachedStrFormat(SI_ZONE_NAME, GetPlayerActiveSubzoneName())
local zoneIndex = GetCurrentMapZoneIndex()
local zoneName = zo_strformat(SI_UNIT_NAME, GetZoneNameByIndex(zoneIndex))
currentMainZone = zoneName
--d('playerActiveSubzoneName: ' ..tostring(playerActiveSubzoneName))
--d('zoneName: ' ..tostring(zoneName))
--d('currentMainZone: ' .. currentMainZone)
if (playerActiveSubzoneName ~= nil and playerActiveSubzoneName ~= '') then
currentActiveZone = playerActiveSubzoneName
elseif (mapName ~= nil and mapName ~= '') then
currentActiveZone = mapName
else
currentActiveZone = zoneName
end
end
function MBI:PrintLog(event, type, volume)
if MBI.AccountDefaults.printLogs then
if (type == VOLUME_TYPES.BARD) then
if event == "zoneChange" then
if volume == 0 then
d(MBI.name .. '> There is a bard around, sound effects are muted.')
else
d(MBI.name .. '> No bard is around now, sound effects are unmuted.')
end
elseif event == "game" then
if volume == 0 then
d(MBI.name .. '> Game has ended, sound effects are muted.')
else
d(MBI.name .. '> Game has started, sound effects are unmuted.')
end
end
else
if volume == 0 then
d(MBI.name .. '> Game music is muted.')
else
d(MBI.name .. '> Game music is unmuted.')
end
end
end
end
function MBI.InCombatState(inCombat)
if inCombat then
setVolume(MBI.AccountDefaults.sfxVolume, VOLUME_TYPES.BARD);
setVolume(MBI.AccountDefaults.musicVolume, VOLUME_TYPES.MUSIC);
end
end
function MBI.OnAreaChange()
MBI:GetZoneNames()
--d('currentActiveZone ' .. currentActiveZone);
if (MBI.AccountDefaults ~= nil and MBI.SavedVariables ~= nil) then
MBI.AccountDefaults.currentActiveZone = currentActiveZone;
MBI.SavedVariables.currentActiveZone = MBI.AccountDefaults.currentActiveZone
MBI.AccountDefaults.currentMainZone = currentMainZone;
MBI.SavedVariables.currentMainZone = MBI.AccountDefaults.currentMainZone
--d('currentActiveZone: ' ..tostring(currentActiveZone))
--d('MBI.SavedVariables.currentActiveZone: ' ..tostring(MBI.SavedVariables.currentActiveZone))
local result = MBI:ContainsZone(currentActiveZone, currentMainZone)
if (result ~= nil and result.bard == true) then
MBI:PrintLog("zoneChange", VOLUME_TYPES.BARD, 0)
setVolume(0, VOLUME_TYPES.BARD);
isBardMuted = true
elseif isBardMuted then
MBI:PrintLog("zoneChange", VOLUME_TYPES.BARD, MBI.AccountDefaults.sfxVolume)
setVolume(MBI.AccountDefaults.sfxVolume, VOLUME_TYPES.BARD);
isBardMuted = false
end
if (result ~= nil and result.music == true) then
MBI:PrintLog("zoneChange", VOLUME_TYPES.MUSIC, 0)
setVolume(0, VOLUME_TYPES.MUSIC);
isMusicMuted = true
elseif isMusicMuted then
MBI:PrintLog("zoneChange", VOLUME_TYPES.MUSIC, MBI.AccountDefaults.musicVolume)
setVolume(MBI.AccountDefaults.musicVolume, VOLUME_TYPES.MUSIC);
isMusicMuted = false
end
end
end
function MBI.OnGameStateChange(_, flowState)
if (MBI:ContainsZone(currentActiveZone, nil)) then
if(flowState == 0) then
MBI:PrintLog("game", VOLUME_TYPES.BARD, 0)
setVolume(0, VOLUME_TYPES.BARD);
isBardMuted = true
else
if(flowState == 1) then
MBI:PrintLog("game", VOLUME_TYPES.BARD, MBI.AccountDefaults.sfxVolume)
end
setVolume(MBI.AccountDefaults.sfxVolume, VOLUME_TYPES.BARD);
isBardMuted = false
end
end
end
EVENT_MANAGER:RegisterForEvent(MBI.name..'InCombatState', EVENT_PLAYER_COMBAT_STATE, MBI.InCombatState)
EVENT_MANAGER:RegisterForEvent(MBI.name..'OnPlayerActivated', EVENT_PLAYER_ACTIVATED, MBI.OnAreaChange)
EVENT_MANAGER:RegisterForEvent(MBI.name..'OnZoneChange', EVENT_ZONE_CHANGED, MBI.OnAreaChange)
EVENT_MANAGER:RegisterForEvent(MBI.name..'OnGameStateChange', EVENT_TRIBUTE_GAME_FLOW_STATE_CHANGE, MBI.OnGameStateChange)
--Register Loaded Callback
EVENT_MANAGER:RegisterForEvent(MBI.name, EVENT_ADD_ON_LOADED, OnAddOnLoaded);
function MBI:Refresh()
MBI.OnAreaChange()
end