Quantcast
WoWInterface - View Single Post - Picking a random entry out of a table/list?
View Single Post
12-17-20, 12:39 PM   #7
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 402
I grouped up duplicates and removed the repetitive stuff ("sounds\\", ".ogg"):
Lua Code:
  1. local sounds
  2. if UnitExists("boss1") then
  3.     local bossHP = UnitHealth("boss1") / UnitHealthMax("boss1")
  4.     if bossHP > 0.8 then
  5.         sounds = {
  6.             "01-Rising-Dragon",
  7.             "02-Cometh",
  8.             "03-Gothams-Reckoning",
  9.             "06-the-battle-is-to-the-strong",
  10.             "06-the-battle-is-to-the-strong-2",
  11.             "07-Kakuzu",
  12.             "07-The-Fire-Rises",
  13.             "08-Prominence",
  14.             "10-Fear-Will-Find-You",
  15.             "10-Silver-for-Monsters",
  16.             "10-Silver-for-Monsters",
  17.             "13-Imagine-The-Fire",
  18.             "15-Divinity",
  19.             "16-tatakau",
  20.             "17-No-Stone-Unturned",
  21.             "17-No-Stone-Unturned-2",
  22.             "19-a-chaser",
  23.             "19-Steel-for-Humans.ogg",
  24.             "35-Hunt-Or-Be-Hunted",
  25.             "35-Hunt-Or-Be-Hunted",
  26.             "35-Hunt-Or-Be-Hunted.ogg",
  27.             "129-truth-behind-the-project",
  28.             "bloodborne-ludwig-1",
  29.             "bloodborne-ludwig-2",
  30.             "FFXV-1",
  31.             "FFXV-4",
  32.             "Twilight-of-the-Gods",
  33.             "ubw-06-souls",
  34.             "ubw-06-souls-2",
  35.             "ubw-18-fist",
  36.             "ubw-23-each",
  37.             "ubw2-05-overcome",
  38.             "ubw2-06-bluered",
  39.             "ubw2-18-excalibur",
  40.             "ubw2-23-music",
  41.  
  42.             "10-Silver-for-Monsters",
  43.             "80percentplus-06-the-battle-is-to-the-strong",
  44.             "pull-Edge-of-Green.ogg",
  45.         }
  46.     elseif bossHP > 0.4 then
  47.         sounds = {
  48.             "01-Rising-Dragon",
  49.             "02-Cometh",
  50.             "03-Gothams-Reckoning",
  51.             "06-the-battle-is-to-the-strong",
  52.             "06-the-battle-is-to-the-strong-2",
  53.             "07-Kakuzu",
  54.             "07-The-Fire-Rises",
  55.             "08-Prominence",
  56.             "10-Fear-Will-Find-You",
  57.             "10-Silver-for-Monsters",
  58.             "10-Silver-for-Monsters",
  59.             "13-Imagine-The-Fire",
  60.             "15-Divinity",
  61.             "16-tatakau",
  62.             "17-No-Stone-Unturned",
  63.             "17-No-Stone-Unturned-2",
  64.             "19-a-chaser",
  65.             "19-Steel-for-Humans.ogg",
  66.             "35-Hunt-Or-Be-Hunted",
  67.             "35-Hunt-Or-Be-Hunted",
  68.             "35-Hunt-Or-Be-Hunted.ogg",
  69.             "129-truth-behind-the-project",
  70.             "bloodborne-ludwig-1",
  71.             "bloodborne-ludwig-2",
  72.             "FFXV-1",
  73.             "FFXV-4",
  74.             "Twilight-of-the-Gods",
  75.             "ubw-06-souls",
  76.             "ubw-06-souls-2",
  77.             "ubw-18-fist",
  78.             "ubw-23-each",
  79.             "ubw2-05-overcome",
  80.             "ubw2-06-bluered",
  81.             "ubw2-18-excalibur",
  82.             "ubw2-23-music",
  83.  
  84.             "01-Rising-Dragon",
  85. --          "06-Raido-2",
  86.             "18-Dark-Spot",
  87.         }
  88.     else
  89.         sounds = {
  90.             "bloodborne-ludwig-1",
  91.             "bloodborne-ludwig-1",
  92.             "execute06-Raido",
  93.             "execute-09-Incantation",
  94.             "execute-17-sara-ni-tatakau-2",
  95.             "FFXV-3",
  96.             "Twilight-of-the-Gods",
  97.             "ubw2-05-overcome-execute",
  98.         }
  99.     end
  100. elseif IsInInstance() then
  101.     sounds = {
  102.         "19-a-chaser",
  103.         "FFXV-4",
  104.         "old-18-Risen-From-Darkness",
  105.     }
  106. else
  107.     sounds = {
  108.         "world-Edge-of-Green",
  109.         "world-Edge-of-Green",
  110.         "world-Edge-of-Green",
  111.     }
  112. end
  113.  
  114. local originalCVar = GetCVar("Sound_EnableMusic")
  115. SetCVar("Sound_EnableMusic", 0)
  116.  
  117. PlaySoundFile(("sound\\%s.ogg"):format(sounds[math.random(#sounds)]), "Master")
  118.  
  119. C_Timer.After(40, function()
  120.     SetCVar("Sound_EnableMusic", originalCVar)
  121. end)
Anything with an ".ogg" still had two to begin with (not sure if intended or not). The commented out "06-Raido-2" is because it wasn't reachable with your original code.
  Reply With Quote