Advertisement
Guest User

setbgm addon with random track selection

a guest
Feb 26th, 2022
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.90 KB | None | 0 0
  1. --[[
  2. Copyright © 2014, Seth VanHeulen
  3. All rights reserved.
  4.  
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are
  7. met:
  8.  
  9. 1. Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11.  
  12. 2. Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15.  
  16. 3. Neither the name of the copyright holder nor the names of its
  17. contributors may be used to endorse or promote products derived from
  18. this software without specific prior written permission.
  19.  
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21. IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  23. PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  26. TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. --]]
  32.  
  33. _addon.name = 'setbgm'
  34. _addon.version = '1.2.3'
  35. _addon.command = 'setbgm'
  36. _addon.author = 'Seth VanHeulen (Acacia@Odin)'
  37.  
  38. require('chat')
  39. require('pack')
  40.  
  41. music_types = {
  42.     [0]='Idle (Day)',
  43.     [1]='Idle (Night)',
  44.     [2]='Battle (Solo)',
  45.     [3]='Battle (Party)',
  46.     [4]='Chocobo',
  47.     [5]='Death',
  48.     [6]='Mog House',
  49.     [7]='Fishing'
  50. }
  51.  
  52. songs = {
  53.     [25]='Voracious Resurgence Unknown 1', [26]='Voracious Resurgence Unknown 2', [27]='Voracious Resurgence Unknown 3', [28]='Voracious Resurgence Unknown 4', [29]="Devils' Delight",  [30]="Odyssey - Bumba", [31]='Voracious Resurgence Unknown 5', [32]='Voracious Resurgence Unknown 6', [33]='Voracious Resurgence Unknown 7',
  54.     [40]='Cloister of Time and Souls', [41]='Royal Wanderlust', [42]='Snowdrift Waltz', [43]='Troubled Shadows', [44]='Where Lords Rule Not', [45]='Summers Lost', [46]='Goddess Divine', [47]='Echoes of Creation', [48]='Main Theme', [49]='Luck of the Mog',
  55.     [50]='Feast of the Ladies', [51]='Abyssea - Scarlet Skies, Shadowed Plains', [52]='Melodies Errant', [53]='Shinryu', [54]='Everlasting Bonds', [55]='Provenance Watcher', [56]='Where it All Begins', [57]='Steel Sings, Blades Dance', [58]='A New Direction', [59]='The Pioneers',
  56.     [60]='Into Lands Primeval - Ulbuka', [61]="Water's Umbral Knell", [62]='Keepers of the Wild', [63]='The Sacred City of Adoulin', [64]='Breaking Ground', [65]='Hades', [66]='Arciela', [67]='Mog Resort', [68]='Worlds Away', [69]="Distant Worlds (Nanaa Mihgo's version)",
  57.     [70]='Monstrosity', [71]="The Pioneers (Nanaa Mihgo's version)", [72]='The Serpentine Labyrinth', [73]='The Divine', [74]='Clouds Over Ulbuka', [75]='The Price', [76]='Forever Today', [77]='Distant Worlds (Instrumental)', [78]='Forever Today (Instrumental)', [79]='Iroha',
  58.     [80]='The Boundless Black', [81]='Isle of the Gods', [82]='Wail of the Void', [83]="Rhapsodies of Vana'diel", [84]="Full Speed Ahead!", [85]="Times Grow Tense", [86]="Shadow Lord (Record Keeper Remix)", [87]="For a Friend", [88]="Between Dreams and Reality", [89]="Disjoined One", [90]="Winds of Change",
  59.     [101]='Battle Theme', [102]='Battle in the Dungeon #2', [103]='Battle Theme #2', [104]='A Road Once Traveled', [105]='Mhaura', [106]='Voyager', [107]="The Kingdom of San d'Oria", [108]="Vana'diel March", [109]='Ronfaure',
  60.     [110]='The Grand Duchy of Jeuno', [111]='Blackout', [112]='Selbina', [113]='Sarutabaruta', [114]='Batallia Downs', [115]='Battle in the Dungeon', [116]='Gustaberg', [117]="Ru'Lude Gardens", [118]='Rolanberry Fields', [119]='Awakening',
  61.     [120]="Vana'diel March #2", [121]='Shadow Lord', [122]='One Last Time', [123]='Hopelessness', [124]='Recollection', [125]='Tough Battle', [126]='Mog House', [127]='Anxiety', [128]='Airship', [129]='Hook, Line and Sinker',
  62.     [130]='Tarutaru Female', [131]='Elvaan Female', [132]='Elvaan Male', [133]='Hume Male', [134]='Yuhtunga Jungle', [135]='Kazham', [136]='The Big One', [137]='A Realm of Emptiness', [138]="Mercenaries' Delight", [139]='Delve',
  63.     [140]='Wings of the Goddess', [141]='The Cosmic Wheel', [142]='Fated Strife -Besieged-', [143]='Hellriders', [144]='Rapid Onslaught -Assault-', [145]='Encampment Dreams', [146]='The Colosseum', [147]='Eastward Bound...', [148]='Forbidden Seal', [149]='Jeweled Boughs',
  64.     [150]='Ululations from Beyond', [151]='The Federation of Windurst', [152]='The Republic of Bastok', [153]='Prelude', [154]='Metalworks', [155]='Castle Zvahl', [156]="Chateau d'Oraguille", [157]='Fury', [158]='Sauromugue Champaign', [159]='Sorrow',
  65.     [160]='Repression (Memoro de la Stono)', [161]='Despair (Memoro de la Stono)', [162]='Heavens Tower', [163]='Sometime, Somewhere', [164]='Xarcabard', [165]='Galka', [166]='Mithra', [167]='Tarutaru Male', [168]='Hume Female', [169]='Regeneracy',
  66.     [170]='Buccaneers', [171]='Altepa Desert', [172]='Black Coffin', [173]='Illusions in the Mist', [174]='Whispers of the Gods', [175]="Bandits' Market", [176]='Circuit de Chocobo', [177]='Run Chocobo, Run!', [178]='Bustle of the Capital', [179]="Vana'diel March #4",
  67.     [180]='Thunder of the March', [181]='Dash de Chocobo (Low Quality)', [182]='Stargazing', [183]="A Puppet's Slumber", [184]='Eternal Gravestone', [185]='Ever-Turning Wheels', [186]='Iron Colossus', [187]='Ragnarok', [188]='Choc-a-bye Baby', [189]='An Invisible Crown',
  68.     [190]="The Sanctuary of Zi'Tah", [191]='Battle Theme #3', [192]='Battle in the Dungeon #3', [193]='Tough Battle #2', [194]='Bloody Promises', [195]='Belief', [196]='Fighters of the Crystal', [197]='To the Heavens', [198]="Eald'narche", [199]="Grav'iton",
  69.     [200]='Hidden Truths', [201]='End Theme', [202]='Moongate (Memoro de la Stono)', [203]='Ancient Verse of Uggalepih', [204]="Ancient Verse of Ro'Maeve", [205]='Ancient Verse of Altepa', [206]='Revenant Maiden', [207]="Ve'Lugannon Palace", [208]='Rabao', [209]='Norg',
  70.     [210]="Tu'Lia", [211]="Ro'Maeve", [212]='Dash de Chocobo', [213]='Hall of the Gods', [214]='Eternal Oath', [215]='Clash of Standards', [216]='On this Blade', [217]='Kindred Cry', [218]='Depths of the Soul', [219]='Onslaught',
  71.     [220]='Turmoil', [221]='Moblin Menagerie - Movalpolos', [222]='Faded Memories - Promyvion', [223]='Conflict: March of the Hero', [224]='Dusk and Dawn', [225]="Words Unspoken - Pso'Xja", [226]='Conflict: You Want to Live Forever?', [227]='Sunbreeze Shuffle', [228]="Gates of Paradise - The Garden of Ru'Hmet", [229]='Currents of Time',
  72.     [230]='A New Horizon - Tavnazian Archipelago', [231]='Celestial Thunder', [232]='The Ruler of the Skies', [233]="The Celestial Capital - Al'Taieu", [234]='Happily Ever After', [235]='First Ode: Nocturne of the Gods', [236]='Fourth Ode: Clouded Dawn', [237]='Third Ode: Memoria de la Stona', [238]='A New Morning', [239]='Jeuno -Starlight Celebration-',
  73.     [240]='Second Ode: Distant Promises', [241]='Fifth Ode: A Time for Prayer', [242]='Unity', [243]="Grav'iton", [244]='Revenant Maiden', [245]='The Forgotten City - Tavnazian Safehold', [246]='March of the Allied Forces', [247]='Roar of the Battle Drums', [248]='Young Griffons in Flight', [249]='Run Maggot, Run!',
  74.     [250]='Under a Clouded Moon', [251]='Autumn Footfalls', [252]='Flowers on the Battlefield', [253]='Echoes of a Zypher', [254]='Griffons Never Die',
  75.     [900]='Distant Worlds'
  76. }
  77.  
  78. song_ids = {}
  79. for id in pairs(songs) do
  80.     table.insert(song_ids, id)
  81. end
  82.  
  83. math.randomseed(os.time())
  84.  
  85. function set_music(music_type, song)
  86.     if music_type then
  87.         local m = tonumber(music_type)
  88.         if music_types[m] then
  89.             local s = tonumber(song)
  90.             if songs[s] then
  91.                 windower.add_to_chat(207, 'Setting %s music: %s':format(music_types[m], songs[s]:color(200)))
  92.                 windower.packets.inject_incoming(0x05F, 'IHH':pack(0x45F, m, s))
  93.             else
  94.                 windower.add_to_chat(167, 'Invalid song: %s':format(song))
  95.             end
  96.         else
  97.             windower.add_to_chat(167, 'Invalid music type: %s':format(music_type))
  98.         end
  99.     else
  100.         local s = tonumber(song)
  101.         if songs[s] then
  102.             windower.add_to_chat(207, 'Setting all music: %s':format(songs[s]:color(200)))
  103.             for music_type=0,7 do
  104.                 windower.packets.inject_incoming(0x05F, 'IHH':pack(0x45F, music_type, s))
  105.             end
  106.         else
  107.             windower.add_to_chat(167, 'Invalid song: %s':format(song))
  108.         end
  109.     end
  110. end
  111.  
  112. function display_songs()
  113.     windower.add_to_chat(207, 'Available songs:')
  114.     for id=25,900,5 do
  115.         local output = '  '
  116.         for i=0,4 do
  117.             if songs[id+i] then
  118.                 output = output .. '  %s: %s':format(tostring(id+i):color(204), songs[id+i])
  119.             end
  120.         end
  121.         if output ~= '  ' then
  122.             windower.add_to_chat(207, output)
  123.         end
  124.     end
  125. end
  126.  
  127. function display_music_types()
  128.     windower.add_to_chat(207, 'Available music types:')
  129.     local output = '  '
  130.     for music_type=0,7 do
  131.         output = output .. '  %s: %s':format(tostring(music_type):color(204), music_types[music_type])
  132.     end
  133.     windower.add_to_chat(207, output)
  134. end
  135.  
  136. function display_help()
  137.     windower.add_to_chat(167, 'Command usage:')
  138.     windower.add_to_chat(167, '    setbgm list [music|type]')
  139.     windower.add_to_chat(167, '    setbgm <song id> [<music type id>]')
  140.     windower.add_to_chat(167, '    setbgm <song id> <song id> <song id> <song id> <song id> <song id> <song id> <song id>')
  141. end
  142.  
  143. function setbgm_command(...)
  144.     local arg = {...}
  145.     if #arg == 1 and arg[1]:lower() == 'random' then
  146.         local song_id = song_ids[math.ceil(math.random() * #song_ids)]
  147.         set_music(nil, song_id)
  148.         return
  149.     elseif #arg == 1 and arg[1]:lower() == 'list' then
  150.         display_songs()
  151.         return
  152.     elseif #arg == 2 and arg[1]:lower() == 'list' and arg[2]:lower() == 'music' then
  153.         display_songs()
  154.         return
  155.     elseif #arg == 2 and arg[1]:lower() == 'list' and arg[2]:lower() == 'type' then
  156.         display_music_types()
  157.         return
  158.     elseif #arg == 1 then
  159.         set_music(nil, arg[1])
  160.         return
  161.     elseif #arg == 2 then
  162.         set_music(arg[2], arg[1])
  163.         return
  164.     elseif #arg == 8 then
  165.         set_music(0, arg[1])
  166.         set_music(1, arg[2])
  167.         set_music(2, arg[3])
  168.         set_music(3, arg[4])
  169.         set_music(4, arg[5])
  170.         set_music(5, arg[6])
  171.         set_music(6, arg[7])
  172.         set_music(7, arg[8])
  173.         return
  174.     end
  175.     display_help()
  176. end
  177.  
  178. windower.register_event('addon command', setbgm_command)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement