PWAD¶-- Helper functions for Dynamic Music -- Includes Pseudorandom Numbers Library v1.0, by LJ Sonic -- THIS LUMP IS THE CLOSEST YOU'LL GET TO THE CODE VERSION OF THE ANTICHRIST -- rawset(_G, "DynMusic", {}) -- Global DynMusic table -- RNG Functions -- local t, x, y, z, w = 0, 6278, 975, 39207, 45678 DynMusic.N_Random = function() t = x ^^ (x << 11) x, y, z, w = y, z, w, w ^^ (w >> 19) ^^ t ^^ (t >> 8) return w end DynMusic.N_RandomKey = function(n) return abs(DynMusic.N_Random() % n) end DynMusic.N_RandomRange = function(a, b) return a + abs(DynMusic.N_Random() % (b - a + 1)) end -- Dynamic Music Common Functions -- local fucksgiven -- Don't ask. -- Alias to command table DynMusic.fuckstogive = {} -- Function for checking music on a specific map DynMusic.MapChecker = function(tbl) for k,v in pairs(tbl) do -- pairs because ipairs hates string keys if (G_BuildMapName(gamemap) == k) return true end end return false end -- Generic function to add music to a list -- The "map" param is optional, it maps the string provided to a level as a key. -- If "fuck" is 1, the table is two dimensional. Only to be used with the My Music module. -- This function is a piece of shit. I know. DynMusic.AddMusic = function(list, lump, map, fuck) lump = lump:upper() -- fuck you this saves time if (fuck == 1) then -- Do this shit first. This is the My Music logic if not (map) then return false -- No point in using this without supplying a map, dipshit. end -- If we've made it here, assume we have everything necessary. if not (list[map]) then list[map] = {} -- Not sure how necessary this is. end for k,v in ipairs(list[map]) do if (v == lump) then return false -- lump is already in the list end end table.insert(list[map], lump) return true -- lump was added elseif (fuck == 2) then if not (map) then return false end if (list[map] == lump) then return false -- YOU ALREADY ADDED THIS YA FUCKIN IDIOT else -- success, you're not an idiot list[map] = lump return true end end if not (map) then for k,v in ipairs(list) do if (v == lump) then return false -- lump is already in the list end end table.insert(list, lump) return true -- lump was added else -- map was provided, add the song to the list using that as the key list[map] = lump return true end end DynMusic.GetTracknumFromLump = function(track, list) for k,v in ipairs(list) do if (track:upper() == v) then return k -- return the key, it's the value we want end end return 0 -- we found nothing end -- Sound replacement function, used for custom global alarms -- Written by Namolos DynMusic.replaceSoundByMobj = function(mobj, oldsound, newsound) if (S_SoundPlaying(mobj, oldsound)) S_StopSoundByID(mobj, oldsound) S_StartSound(mobj, newsound) end end -- I hate the fact that this function needs to exist DynMusic.GetMyDamnShit = function (wtf) local shit = {} for s in wtf:gmatch("[^\x7F]+") do table.insert(shit, s) end return unpack(shit) end -- this is even worse than the last one dear god DynMusic.FuckMe = function (name, fn) CV_RegisterVar({ name, "", CV_CALL|CV_NOINIT, nil, function (cv) local s = cv.string if (s ~= "") then fn(consoleplayer, DynMusic.GetMyDamnShit(s)) COM_BufInsertText(consoleplayer, cv.name ..' ""') end end }) end -- Just use like COM_AddCommand DynMusic.FuckYou = function (name, ...) local dummyname = "_" .. name DynMusic.fuckstogive[name] = dummyname DynMusic.FuckMe(dummyname, ...) end addHook ("ThinkFrame", function () -- Register aliases to dummy commands because Lua commands get sent over the -- network as TEXTCMD. And that means you'll get NetXCmd full if you send -- too many. And that could very likely happen with config loading. if consoleplayer then if (not fucksgiven) then for name, dummyname in pairs (DynMusic.fuckstogive) do -- wait 2 because first run of command ticker -- counts it down before checking. -- fucking kill me already - wolfs COM_BufInsertText(consoleplayer, string.format( 'alias %s %s "'.. '$1\x7F$2\x7F$3\x7F'.. '$4\x7F$5\x7F$6\x7F'.. '$7\x7F$8\x7F$9\x7F', name, dummyname)) end COM_BufInsertText(consoleplayer, "exec dynmusic.cfg -noerror") -- might as well load global config here fucksgiven = true end end end) -- SRB2Kart Lua Script -- SPB Music -- Originally written by Sal and now by James. The new version has a cvar -- toggle, plays for spectating players, and is able to check for a music -- lump actually being present. -- Slightly expanded by wolfs. Includes blacklisting, randomized music, -- and map-specific SPB music. -- DynMusic.spbm = {} -- module namespace local spbm = DynMusic.spbm -- shorthand to prevent clusterfucks local starttime = 6*TICRATE + (3*TICRATE/4) local didcredit local wantcredit local pauselength = 3*TICRATE local oldmapmusname -- map music to restore it local newmapmusname -- spb music in case some outside force changes map music local gotmusic = {} -- Honestly not sure how necessary this is. local firstrun = 0 -- For loading spbmusic.cfg local fucksgiven = false -- For aliasing spbm.map_blacklist = {} -- Blacklist table spbm.music_list = {"SPBRUN"} -- Music list. Can be expanded, but always contains at least one entry. spbm.charmusic = {} spbm.map_music = {} -- Table for map-specific music local labels = {} -- Holds labels displayed when listing music, if present local preftracknum = 1 -- Preferred track number, set by the user. spbm.tracknum = 1 -- Actual track number, set by the script. spbm.tracklump = nil -- This is spaghetti, but this is the track lump to use if character-specific music is defined. spbm.cv_randomize = CV_RegisterVar({"spbrandomize", "Off", 0, CV_OnOff}) -- Randomizes which song plays during SPB rush -- Determines how crediting is handled. "Always" shows it every time, while "Once" displays it once per map. local cv_credit = CV_RegisterVar({"spbcredit", "Always", 0, {Never=0, Once=1, Always=2}}) -- Override cvar for map-specific SPB music. -- If enabled, your preferred track will always play, even on maps with specific music defined. local cv_override = CV_RegisterVar({"spbmapoverride", "Off", 0, CV_OnOff}) -- Helper function to check blacklisted maps. local function BlacklistChecker() for k,v in ipairs(spbm.map_blacklist) do if (G_BuildMapName(gamemap) == v) return true end end return false end -- Allows disabling SPB music on specific maps DynMusic.FuckYou("spbblacklist", function(player, map) if (player ~= consoleplayer) then return end if not (map) then CONS_Printf(player, "SPB Music Blacklist") if not (spbm.map_blacklist) then CONS_Printf(player, "-- Blacklist empty --") return else for k,v in ipairs(spbm.map_blacklist) do CONS_Printf(player, k..": "..v) end end return end for k,v in ipairs(spbm.map_blacklist) do if (v == map:upper()) then error("specified map ("..map..") is already blacklisted") return end end table.insert(spbm.map_blacklist, map:upper()) end) -- Adds SPB music to the list -- Limited error checking. Just don't be an idiot :V DynMusic.FuckYou("addspbmusic", function(player, mus, label) if (player ~= consoleplayer) then return end if not (mus) then CONS_Printf(player, "addspbmusic : Adds a music lump to the SPB music list") return end if (DynMusic.AddMusic(spbm.music_list, mus)) then CONS_Printf(player, "[SPB Music] Added track "..#spbm.music_list..": \x82"..mus:upper().."\x80") if (label) then labels[#spbm.music_list] = label end else error(mus.." is already in the list") end end) DynMusic.FuckYou("addcharspbmusic", function(player, skin, lump) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "addcharspbmusic : Sets the SPB music for the given skin to the provided lump") return end if not (lump) then error("no music lump provided") return end spbm.charmusic[skin] = lump CONS_Printf(player, "[SPB Music] SPB Music for \""..skin.."\" has been set to \x82"..lump.."\x80") end) COM_AddCommand("delspbmusic", function(player, mus) if (player ~= consoleplayer) then return end if not (mus) then CONS_Printf(player, "delspbmusic : Removes a music lump from the SPB music list") return end for k,v in ipairs(spbm.music_list) do if (v == mus:upper()) then if (preftracknum == k) then preftracknum = 1 -- I'm not gonna bother accounting for a completely empty list. That's your own problem. end if (spbm.tracknum == k) then spbm.tracknum = 1 end table.remove(spbm.music_list, k) if (labels[k]) then table.remove(labels, k) end CONS_Printf(player, "[SPB Music] Removed track: ".."\x82"..mus:upper().."\x80") return end end error(mus.." was not found") end) COM_AddCommand("delcharspbmusic", function(player, skin) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "delcharspbmusic : Removes the currently set SPB Music for the provided skin") return end spbm.charmusic[skin] = nil CONS_Printf(player, "[SPB Music] SPB Music for \""..skin.."\" removed") end) -- Lists the currently set SPB music lumps. -- Tells you your preferred track and if randomizer is set. COM_AddCommand("listspbmusic", function(player) if (player ~= consoleplayer) then return end local str = "" CONS_Printf(player, "SPB Music List") for k,v in ipairs(spbm.music_list) do str = k..": "..v if (labels[k]) then str = str.." - "..labels[k] end CONS_Printf(player, str) end if (spbm.cv_randomize.value) then CONS_Printf(player, "The current preferred track is \x82"..preftracknum.."\x80. Randomizer is enabled.") else CONS_Printf(player, "The current preferred track is \x82"..preftracknum.."\x80.") end end) COM_AddCommand("listcharspbmusic", function(player) if (player ~= consoleplayer) then return end local str = "" if not (next(spbm.charmusic)) then error("no character music defined") return end CONS_Printf("Character SPB Music List") for k,v in pairs(spbm.charmusic) do str = k..": "..v CONS_Printf(player, str) end end) -- Selects a song from the list for SPB rush. DynMusic.FuckYou("setspbmusic", function(player, track) if (player ~= consoleplayer) then return end if not track then CONS_Printf(player, "setspbmusic : Sets the preferred SPB music to the given track") return end if (tonumber(track)) then -- track provided is a number track = tonumber(track) if (track > #spbm.music_list) then error("track number exceeds music list") return end else -- track is a string, find the corresponding list entry track = DynMusic.GetTracknumFromLump(track, spbm.music_list) end if not (track) then error("invalid track lump provided, resetting to default") preftracknum = 1 return end preftracknum = track CONS_Printf(player, "SPB Music has been set to \x82"..spbm.music_list[preftracknum].."\x80.") end) -- Changes the default lump (SPBRUN) -- Now you'll never be subjected to someone else's taste! DynMusic.FuckYou("setspbdefault", function(player, lump) if (player ~= consoleplayer) then return end if not lump then CONS_Printf(player, "setspbdefault : Changes the default SPB music lump") return end spbm.music_list[1] = lump:upper() CONS_Printf(player, "Default SPB Music set to \x82"..lump.."\x80.") end) -- Defines SPB music for a given map -- Does not take effect if the randomizer is enabled -- I have no idea what the hell will happen if two songs are set to the same map DynMusic.FuckYou("mapspbmusic", function(player, map, track) if (player ~= consoleplayer) then return end if not map and not track then CONS_Printf(player, "mapspbmusic : Define a track number as the music for the given map") return end if not (track) then error([["]]..track..[[" is missing]]) return end if (tonumber(track)) then -- track provided is a number track = tonumber(track) if (track > #spbm.music_list) then error("track number exceeds music list") return end else -- track is a string, find the corresponding list entry track = DynMusic.GetTracknumFromLump(track, spbm.music_list) end if not (track) then error("invalid track lump provided") return end spbm.map_music[map] = track CONS_Printf(player, "SPB Music for \x82"..map.."\x80 has been set to \x82"..spbm.music_list[track].."\x80 (".."track "..track..")") end) local function SPBMusic_Queue (p, fn) if (spbm.cv_spbmusic.value) then if (spbm.map_blacklist and BlacklistChecker()) then return end -- don't play SPB music on blacklisted maps if (p.mo and p.mo.valid and spbm.charmusic[p.mo.skin]) then spbm.tracklump = spbm.charmusic[p.mo.skin] end if (spbm.cv_randomize.value) then spbm.tracknum = DynMusic.N_RandomRange(1, #spbm.music_list) -- randomizer shit elseif (spbm.map_music and DynMusic.MapChecker(spbm.map_music) and not (cv_override.value)) then spbm.tracknum = spbm.map_music[G_BuildMapName(gamemap)] -- This map uses a specific track, so set it else spbm.tracknum = preftracknum end if (gotmusic[spbm.tracknum] or gotmusic[spbm.tracklump]) then if (p == consoleplayer) then fn(p) end else if (spbm.charmusic[p.mo.skin] and S_MusicExists(spbm.charmusic[p.mo.skin]:lower())) then if (p == consoleplayer) then gotmusic[spbm.tracklump] = true fn(p) end elseif (S_MusicExists(spbm.music_list[spbm.tracknum]:lower())) then if (p == consoleplayer) then gotmusic[spbm.tracknum] = true fn(p) end end end end end local function SPBMusic_Change (p) -- map music changed by outside force, so revert to that if oldmapmusname == nil or (mapmusname ~= newmapmusname) then oldmapmusname = mapmusname end if (spbm.charmusic[p.mo.skin]) then newmapmusname = spbm.tracklump else newmapmusname = spbm.music_list[spbm.tracknum]:lower() end -- tunes means the music persists even after P_RestoreMusic COM_BufInsertText(p, 'tunes "' .. newmapmusname) if (not didcredit) and (cv_credit.value) then wantcredit = true end end local function SPBMusic_Restore (p) if (mapmusname == newmapmusname) then COM_BufInsertText(p, 'tunes "' .. oldmapmusname) else P_RestoreMusic(p) -- go back to whatever end oldmapmusname = nil newmapmusname = nil if (cv_credit.value == 2) then -- spbcredit is set to "Always" didcredit = nil end end local function SPBMusic_Pause (p) S_StopMusic(p) if (wantcredit) then wantcredit = nil end end local function SPBMusic_Auto (p) if (p.exiting or leveltime < starttime) then return end local position = p.kartstuff[k_position] local spbmusic = p.spbmusic if (position == spbplace) then if (spbm.cv_spbmusic.value) then if (spbmusic == pauselength) then SPBMusic_Change(p) elseif (spbmusic >= TICRATE) then SPBMusic_Pause(p) end else if (spbmusic >= TICRATE) then SPBMusic_Restore(p) end end else if (spbmusic == 0 or not spbm.cv_spbmusic.value) then SPBMusic_Restore(p) else SPBMusic_Pause(p) end end end local function SPBMusic_Think () for p in players.iterate do if p.spbmusic == nil then p.spbmusic = 0 end if (p.exiting or leveltime < starttime) then p.spbmusic = 0 return end local position = p.kartstuff[k_position] local spbmusic = p.spbmusic if (position == spbplace and spbmusic < pauselength) then p.spbmusic = $+1 if (p.spbmusic == pauselength) then SPBMusic_Queue(p, SPBMusic_Change) elseif (p.spbmusic == TICRATE) then SPBMusic_Queue(p, SPBMusic_Pause) end elseif (position ~= spbplace and spbmusic > 0) then if (p.spbmusic == 1) then SPBMusic_Queue(p, SPBMusic_Restore) elseif (p.spbmusic == pauselength) then SPBMusic_Queue(p, SPBMusic_Pause) end p.spbmusic = $-1 end --[[ -- Dead players get P_RestoreMusic set on them, and so may be fucked if (p.playerstate == PST_REBORN and p.spbmusic ~= spbmusic) then SPBMusic_Queue(p, SPBMusic_Auto) -- Hey, it's already there! end ]] end end spbm.cv_spbmusic = CV_RegisterVar( { "spbmusic", "Off", -- Defaults to off. Anyone who wants it can just set it in their config. CV_CALL|CV_NOINIT, CV_OnOff, function () -- Hey, are we actually playing? if consoleplayer ~= nil and (consoleplayer.valid) then SPBMusic_Queue(consoleplayer, SPBMusic_Auto) end end }) addHook ("ThinkFrame", SPBMusic_Think) addHook ("MapLoad", function () didcredit = nil end) hud.add (function (_,p) if (wantcredit) then S_ShowMusicCredit(consoleplayer) didcredit = true wantcredit = nil end end) -- Final Lap Music by Snu (This took too long) DynMusic.flm = {} -- module namespace local flm = DynMusic.flm -- shorthand to prevent clusterfucks flm.cv_flmusic = CV_RegisterVar({"finallapmusic", "Off", 0, CV_OnOff}) flm.list = {} -- all our final lap music goes in here addHook("MapLoad", function() for p in players.iterate -- reset final lap music related vars p.flm_mod, p.flm_t, p.flm_c = nil, nil, nil end end) -- function to trigger final lap music for mods that want to flm.TriggerFLM = function(timer) timer = $ and max(1, min(73, $)) or 1 local p = displayplayers[0] p.flm_mod = true -- this is important p.flm_c = nil -- remove this to retrigger it p.flm_t = timer -- set timer end DynMusic.FuckYou("addflmusic", function(p, lump, flmlump) if (p ~= consoleplayer) then return end if not (lump) then CONS_Printf(p, "addflmusic : Adds final lap music for a music lump.") return end if not (flmlump) then CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x83".."NOTICE:".."\x80".." No final lap music lump provided.") return end lump, flmlump = lump:upper(), flmlump:upper() -- uppercase the music lumps -- global flmusic if (lump == "GLOBALMUSIC") if (flm.list[6969696]) then CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x83".."NOTICE:".."\x80".." Global final lap music already exists: ".."\x82"..flm.list[6969696]) end CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x80"..(flm.list[6969696] and "Replaced" or "Added").." global final lap music: ".."\x82"..flmlump) flm.list[6969696] = flmlump -- music lumps cant be more than 6 characters so there's no way this can overwrite something... right? return end -- truncate lump names if they're too long if (lump:len() > 6) CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x83".."NOTICE:".."\x80".." Music name too long - truncated to six characters.") lump = lump:sub(1, 6) end if (flmlump:len() > 6) CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x83".."NOTICE:".."\x80".." Music name too long - truncated to six characters.") lump = flmlump:sub(1, 6) end if (flm.list[lump]) then CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x83".."NOTICE:".."\x80".." Final lap music for "..lump.." already exists: ".."\x82"..flm.list[lump]) end CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x80"..(flm.list[lump] and "Replaced" or "Added").." final lap music for "..lump..": ".."\x82"..flmlump) flm.list[lump] = flmlump end) COM_AddCommand("delflmusic", function(p, lump) if (p ~= consoleplayer) then return end if not (lump) then CONS_Printf(p, "delflmusic : Deletes final lap music from a music lump.") return end lump = lump:upper() -- uppercase the music lump -- global flmusic check if (lump == "GLOBALMUSIC") CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x80".."Removed global final lap music.") flm.list[6969696] = nil return end -- truncate lump name if it's too long if (lump:len() > 6) CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x83".."NOTICE:".."\x80".." Music name too long - truncated to six characters.") lump = lump:sub(1, 6) end CONS_Printf(p, "\x82".."[Final Lap Music] ".."\x80".."Removed final lap music from "..lump".") flm.list[lump] = nil end) -- Clears final lap music from all maps COM_AddCommand("clearflmusic", function(p) if (p ~= consoleplayer) then return end CONS_Printf(p, "\x82".."[Final Lap Music]".."\x80".." Cleared all final lap music.") flm.list = {} end) COM_AddCommand("listflmusic", function(p) if (p ~= consoleplayer) then return end if (next(flm.list) == nil) then CONS_Printf(p, "\x82".."[Final Lap Music]".."\x80".." No final lap music defined.") return end CONS_Printf(p, "\x82".."[Final Lap Music]".."\x80".." Final lap music list:") for k, v in pairs(flm.list) if (k == 6969696) then continue end -- we'll always print this last CONS_Printf(p, k..": ".."\x82"..v) end if flm.list[6969696] then CONS_Printf(p, "Global FLMusic: ".."\x82"..flm.list[6969696]) end end) -- sadly I cant just use MusicChange for this... the chad of all hooks... local flm_music addHook("ThinkFrame", do local p = displayplayers[0] for cp in displayplayers.iterate -- have I mentioned how much I love this if (((cp.laps+1) == numlaps) and (numlaps > 1) and flm.cv_flmusic.value) -- main trigger, final lap (with flmusic enabled) or (p.flm_mod) -- custom mod trigger if (p.flm_c) then return end -- music already triggered, stop functions -- get music here instead of later on -- S_MusicName() will technically return something else while we transition if flm.list[S_MusicName()] flm_music = flm.list[S_MusicName()] else -- cant find lump specific flmusic so check for global if flm.list[6969696] flm_music = flm.list[6969696] end end if (flm_music) -- we need to have music and not (cp.spbmusic or cp.kartstuff[k_invincibilitytimer] or (cp.kartstuff[k_growshrinktimer] > 0)) -- checks for spbmusic, invincibility and growth and not (cp.mo and cp.mo.tsr_ultimateon) -- tsr plug local flm_tune = (p.flm_t == 73) and flm_music or "-none" -- what we'll be setting it to COM_BufInsertText(p, "tunes "..flm_tune) if (p.flm_t == 73) -- 73 is when the music SHOULD trigger flm_music = nil -- reset the tune here p.flm_mod = nil -- reset this, just for convenience p.flm_c = true -- make sure nothing else happens S_ShowMusicCredit() end end -- increase timer when active p.flm_t = $ and min(73, p.flm_t+1) or 1 else -- reset flm_music here for weird cases (joining another server, map change, etc) flm_music = nil end end end)-- Megamix Themes, originally made by Dimpsuu, remade by Snu as a DynMusic module DynMusic.mmt = {} -- module namespace local mmt = DynMusic.mmt -- shorthand to prevent clusterfucks mmt.cv_megamixthemes = CV_RegisterVar({"megamixthemes", "Off", 0, CV_OnOff}) mmt.themes = {} local labels = {} -- 1: invincibility -- 2: growth mmt.GetMusic = function(skin, themetype) mmt.themes[skin] = $ ~= nil and $ or {} if (themetype == 1) and mmt.themes[skin][1] -- check for invincibility return mmt.themes[skin][1] elseif (themetype == 2) and mmt.themes[skin][2] -- check for growth return mmt.themes[skin][2] end -- they dont have anything return nil end DynMusic.FuckYou("addinvincibilitytheme", function(player, skin, lump, label) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "addinvincibilitytheme : Sets the invincibility theme for the given skin to the provided lump") return end if not (lump) then error("no music lump provided") return end mmt.themes[skin] = $ ~= nil and $ or {} mmt.themes[skin][1] = lump:upper() if (label) then -- initialize labels[skin] = $ ~= nil and $ or {} -- same with the labels table labels[skin][1] = label end CONS_Printf(player, "[Megamix Themes] Invincibility theme for \""..skin.."\" has been set to \x82"..lump.."\x80") end) DynMusic.FuckYou("addgrowththeme", function(player, skin, lump, label) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "addgrowththeme : Sets the growth theme for the given skin to the provided lump") return end if not (lump) then error("no music lump provided") return end mmt.themes[skin] = $ ~= nil and $ or {} mmt.themes[skin][2] = lump:upper() if (label) then -- initialize labels[skin] = $ ~= nil and $ or {} -- same with the labels table labels[skin][2] = label end CONS_Printf(player, "[Megamix Themes] Growth theme for \""..skin.."\" has been set to \x82"..lump.."\x80") end) COM_AddCommand("delmegamixthemes", function(player, skin) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "delmmt.themes : Removes the currently set megamix themes for the provided skin") return end mmt.themes[skin] = nil if (labels[skin]) then labels[skin] = nil end CONS_Printf(player, "[Megamix Themes] Megamix themes for \""..skin.."\" removed") end) COM_AddCommand("listmegamixthemes", function(player) if (player ~= consoleplayer) then return end if (next(mmt.themes) == nil) then CONS_Printf(player, "Megamix themes table is empty") return end CONS_Printf(player, "Megamix Theme List") for k, v in pairs(mmt.themes) do -- initialize tables v = $ ~= nil and $ or {} labels[k] = $ ~= nil and $ or {} -- create the starting string local str = "" -- check for invinc if v[1] str = k.." (Invincibility): "..v[1] if (labels[k][1]) then str = str.." - "..labels[k][1] end CONS_Printf(player, str) end -- check for growth if v[2] str = k.." (Growth): "..v[2] if (labels[k][2]) then str = str.." - "..labels[k][2] end CONS_Printf(player, str) end end end) addHook("MusicChange", function(oldmusic, newmusic, flags, looping) if not (mmt.cv_megamixthemes.value) then return end local index = (newmusic == "kinvnc") and 1 or 2 local mmt_player, mmt_best = nil, 0 -- slight hack to find the player for splitscreen support for cp in displayplayers.iterate -- this is my new favourite thing in 1.2 local mmt_checks = {k_invincibilitytimer, k_growshrinktimer} if not cp.kartstuff[mmt_checks[index]] then continue end -- check what displayplayer has the highest timer -- easy way of telling who just activated their item if (cp.kartstuff[mmt_checks[index]] > mmt_best) mmt_player = cp -- store them for later mmt_best = cp.kartstuff[mmt_checks[index]] end end -- if we got a player we do stuff if (mmt_player) local p = mmt_player if mmt.GetMusic(p.mo.skin, index) return mmt.GetMusic(p.mo.skin, index), flags, true end end end)-- My Music, by wolfs -- Includes Encore Music, by SteelT, for convenience -- This is a compendium of some of the shittiest code I've ever written. Don't be expecting quality here. DynMusic.mmus = {} -- Table for My Music module vars local mmus = DynMusic.mmus -- shorthand to prevent clusterfucks local starttime = 6*TICRATE + (3*TICRATE/4) mmus.music_list = {} mmus.encoremusic = {} local labels = {} local encorelabels = {} local rand, rand2, musname, mapname mmus.map_music = {} -- used with mmus.music_list, helps keep things clean mmus.defaults = {} -- Map music defaults mmus.votemusic = {} -- Stores additional voting music mmus.queue = {} mmus.queuesong = nil mmus.tracklump = nil mmus.randomized = false mmus.voterandomized = false mmus.queued = false mmus.cv_mymusic = CV_RegisterVar({"mymusic", "Off", 0, CV_OnOff}) mmus.cv_encoremusic = CV_RegisterVar({"encoremusic", "Off", 0, CV_OnOff}) -- Copy of "addspbmusic" -- Adds a song to the additional song table for a map DynMusic.FuckYou("addmapmusic", function(player, map, mus, label) if (player ~= consoleplayer) then return end if not (map) then CONS_Printf(player, "addmapmusic : Adds a music lump for the given map") return end map = map:upper() if not (mus) then error("no lump provided") return end if (DynMusic.AddMusic(mmus.music_list, mus, map, 1)) then CONS_Printf(player, "[My Music] Added track for "..map..": \x82"..mus:upper().."\x80") if (label) then if not (labels[map]) then labels[map] = {} end table.insert(labels[map], label) end else error(mus.." is already in the list for this map") end end) -- Adds a encore music for a specific map DynMusic.FuckYou("addencoremusic", function(p, map, muslump, label) if (p ~= consoleplayer) then return end local mapstr local muslumpstr if not (map) and not (muslump) then CONS_Printf(p, "addencoremusic : Adds a encore music lump for the specified map.") return end if not (muslump) then error("No music lump was provided") return end mapstr = map:upper() if mapstr:find("MAP") == nil then mapstr = "MAP"..$ -- prepend "MAP" to start of mapstr end muslumpstr = muslump:gsub("O_", "", 1) -- Remove O_ prefix mmus.encoremusic[mapstr] = muslumpstr if (label) encorelabels[mapstr] = label end CONS_Printf(p, "[Encore Music] Encore music for \x82"..mapstr.."\x80 has been set to track \x82"..muslumpstr.."\x80.") end) -- Command for changing default map music -- Used to get around custom levels going over your music wad and replacing your choices -- Label functionality removed here, because fuck you. DynMusic.FuckYou("setdefaultmapmusic", function(player, map, mus) if (player ~= consoleplayer) then return end if not (map) then CONS_Printf(player, "setdefaultmapmusic : Changes the default music choice for the given map") return end map = map:upper() if not (mus) then error("no lump provided") return end if (DynMusic.AddMusic(mmus.defaults, mus, map, 2)) then CONS_Printf(player, "[My Music] Changed default track for "..map..": \x82"..mus:upper().."\x80") else error(mus.." is already the default track for this map") end end) DynMusic.FuckYou("overrideintermission", function(player, mus) if (player ~= consoleplayer) then return end if not (mus) then CONS_Printf(player, "overrideintermission : Overrides the intermission music used. This is only heard while spectating.") if (mmus.intermissionoverride) then CONS_Printf(player, "The current intermission music override is: \x82"..mmus.intermissionoverride.."\x80") end return end -- Just set it flat out so it can be modified at runtime. No error checking because fuck you. mmus.intermissionoverride = mus CONS_Printf(player, "[My Music] Added intermission music override: \x82"..mmus.intermissionoverride:upper().."\x80") end) DynMusic.FuckYou("addvotemusic", function(player, vote, voteea, voteeb) if (player ~= consoleplayer) then return end local votemus = nil if not (vote) then CONS_Printf(player, "addvotemusic : Adds voting music to randomize between. Use the same lump for all three arguments to ignore VOTEEA and VOTEEB lumps") return end if not (voteea) or not (voteeb) then error("too few parameters") return end votemus = {vote, voteea, voteeb} table.insert(mmus.votemusic, votemus) CONS_Printf(player, "[My Music] Added vote music: \x82"..table.concat(votemus, ", "):upper().."\x80") end) DynMusic.FuckYou("setdefaultvotemusic", function(player, vote, voteea, voteeb) if (player ~= consoleplayer) then return end if not (vote) then CONS_Printf(player, "setdefaultvotemusic : Changes the default voting music used.") if (mmus.votedefault) then CONS_Printf(player, "The current default vote music is: \x82"..table.concat(mmus.votedefault, ", ").."\x80") end return end if not (voteea) or not (voteeb) then error("too few parameters") return end -- Just set it flat out so it can be modified at runtime. No error checking because fuck you. mmus.votedefault = {vote, voteea, voteeb} CONS_Printf(player, "[My Music] Changed default vote music: \x82"..table.concat(mmus.votedefault, ", "):upper().."\x80") end) COM_AddCommand("delmapmusic", function(player, map, mus) if (player ~= consoleplayer) then return end if not (map) then CONS_Printf(player, "delmapmusic : Removes a music lump from the given map") return end map = map:upper() if not (mus) then error("no lump provided") return end for k,v in ipairs(mmus.music_list[map]) do if (v == mus:upper()) then table.remove(mmus.music_list[map], k) if (labels[map][k]) then table.remove(labels[map], k) end CONS_Printf(player, "[My Music] Removed track for "..map..": \x82"..mus:upper().."\x80") return end end error(mus.." was not found") end) COM_AddCommand("delencoremusic", function(p, map) if (p ~= consoleplayer) then return end local mapstr if not (map) then CONS_Printf(p, "delencoremusic : Removes a encore music for the specified map.") return end mapstr = map:upper() if mapstr:find("MAP") == nil then mapstr = "MAP"..$ -- prepend "MAP" to start of mapstr end if (mmus.encoremusic[mapstr] == nil) then error("Encore music for "..mapstr.." does not exist") return end mmus.encoremusic[mapstr] = nil if (label) then encorelabels[mapstr] = nil end CONS_Printf(p, "[Encore Music] Encore music for \x82"..mapstr.."\x80 was removed.") end) COM_AddCommand("delmapdefault", function(player, map) if (player ~= consoleplayer) then return end if not (map) then CONS_Printf(player, "delmapdefault : Deletes custom default music for the given map") return end map = map:upper() if not (mmus.defaults[map]) then error(map.." has no custom default to delete") return end mmus.defaults[map] = nil CONS_Printf(player, "[My Music] Default for \x82"..map.."\x80 deleted.") end) COM_AddCommand("delvotemusic", function(player, key) if (player ~= consoleplayer) then return end if not (key) then CONS_Printf(player, "delvotemusic : Deletes a vote music entry from the list. Use \"listvotemusic\" to view the list") return end if not (mmus.votemusic[key]) then error("invalid key specified") return end table.remove(mmus.votemusic, key) CONS_Printf(player, "[My Music] Deleted vote music entry at key \x82"..key.."\x80.") end) COM_AddCommand("delintermissionoverride", function(player) if (player ~= consoleplayer) then return end mmus.intermissionoverride = nil CONS_Printf(player, "[My Music] Intermission music override deleted.") end) COM_AddCommand("delvotedefault", function(player) if (player ~= consoleplayer) then return end mmus.votedefault = nil CONS_Printf(player, "[My Music] Custom vote music default deleted.") end) -- Copy of "listspbmusic" -- Lists additional music defined for the specified map COM_AddCommand("listmapmusic", function(player, map) if (player ~= consoleplayer) then return end local str = "" if not (map) then CONS_Printf(player, "listmapmusic : Lists additional music defined for the given map") return end map = map:upper() if not (mmus.music_list[map]) then error("no music defined for "..map) return end CONS_Printf(player, map.." Additional Music List") for k,v in ipairs(mmus.music_list[map]) do str = k..": "..v if (labels[map][k]) then str = str.." - "..labels[map][k] end CONS_Printf(player, str) end end) COM_AddCommand("listencoremusic", function(p) if (p ~= consoleplayer) then return end local str = "" if (next(mmus.encoremusic) == nil) then CONS_Printf(p, "Encore music table is empty") return end CONS_Printf(p, "Encore Music List") for k,v in pairs(mmus.encoremusic) do str = k..": "..v if (encorelabels[k]) then str = str.." - "..encorelabels[k] end CONS_Printf(p, str) end end) COM_AddCommand("listmapdefaults", function(player) if (player ~= consoleplayer) then return end local str = "" if not (next(mmus.defaults)) then error("no custom defaults defined") return end CONS_Printf(player, "Default Map Music List") for k,v in pairs(mmus.defaults) do -- ipairs hates string keys str = k..": "..v CONS_Printf(player, str) end end) COM_AddCommand("listvotemusic", function(player) if (player ~= consoleplayer) then return end local str = "" if not (next(mmus.votemusic)) then error("no custom vote music defined") return end CONS_Printf(player, "Vote Music List") for k,v in ipairs(mmus.votemusic) do str = k..": "..v CONS_Printf(player, str) end end) COM_AddCommand("queue", function(player, ...) if (player ~= consoleplayer) then return end if not (...) then CONS_Printf(player, "queue : Determines which song will play next. Can be used with multiple songs to create playlists") return end mmus.queue = {...} CONS_Printf(player, "[My Music] Queued \x82"..table.concat({...}, ", ").."\x80 to play.") end) COM_AddCommand("listqueue", function(player) if (player ~= consoleplayer) then return end CONS_Printf(player, "Current song queue") if (mmus.queue ~= nil) then if not (#mmus.queue) then CONS_Printf(player, "Queue is empty") return end for k,v in ipairs(mmus.queue) do CONS_Printf(player, k..": "..v) end else error("queue undefined") end end) COM_AddCommand("clearqueue", function(player) if (player ~= consoleplayer) then return end mmus.queue = {} CONS_Printf(player, "[My Music] Queue cleared") end) -- PRIORITY LIST: -- 1. Queue -- 2. Encore Music -- 3. My Music/Music overrides addHook("MusicChange", function(oldmusic, newmusic, flags, looping) --print("Music change from "..oldmusic.." to "..newmusic) -- Shorthand for readability musname = mapheaderinfo[gamemap].musname mapname = G_BuildMapName(gamemap) -- Check if the next song is the map's default if (newmusic == musname) then -- Queue handling (works independently from rest of the module) if (mmus.queue and #mmus.queue) or (mmus.queuesong) then if not (mmus.queued) then mmus.queuesong = mmus.queue[1] table.remove(mmus.queue, 1) CONS_Printf(consoleplayer, "[My Music] Playing queued song: \x82"..mmus.queuesong.."\x80") if not (mmus.queue[1]) then CONS_Printf(consoleplayer, "[My Music] Reached the end of the queue") end mmus.queued = true end return mmus.queuesong, flags, true end -- Encore music handling if (encoremode and mmus.cv_encoremusic.value) then if (mmus.encoremusic and DynMusic.MapChecker(mmus.encoremusic)) then --print("Playing the encore music for "..mapname.." ("..mmus.encoremusic[mapname]..")") return mmus.encoremusic[mapname], flags, true end end end if (mmus.cv_mymusic.value) then -- Handle overrides first if (mmus.intermissionoverride) then if (newmusic == "racent") then return mmus.intermissionoverride:upper(), flags, true end end if (next(mmus.votemusic)) or (mmus.votedefault) then -- Handle randomization shit if (next(mmus.votemusic)) then if not (mmus.voterandomized) then rand2 = DynMusic.N_RandomRange(0, #mmus.votemusic) mmus.voterandomized = true end if (rand2 ~= 0) then -- I actually fucking hate this. if (newmusic == "vote") then return mmus.votemusic[rand2][1], flags, true elseif (newmusic == "voteea") then return mmus.votemusic[rand2][2], flags, true elseif (newmusic == "voteeb") then return mmus.votemusic[rand2][3], flags, true end else if (mmus.votedefault) then if (newmusic == "vote") then return mmus.votedefault[1], flags, true elseif (newmusic == "voteea") then return mmus.votedefault[2], flags, true elseif (newmusic == "voteeb") then return mmus.votedefault[3], flags, true end else return -- fall back to existing vote lumps end end end if (mmus.votedefault) then -- The fact that this exact block is used twice hurts my brain. if (newmusic == "vote") then return mmus.votedefault[1], flags, true elseif (newmusic == "voteea") then return mmus.votedefault[2], flags, true elseif (newmusic == "voteeb") then return mmus.votedefault[3], flags, true end end end if (newmusic == musname) then if (mmus.music_list[mapname]) then mmus.map_music = mmus.music_list[mapname] if not (mmus.randomized) then rand = DynMusic.N_RandomRange(0, #mmus.map_music) mmus.randomized = true end if (rand ~= 0) then mmus.tracklump = mmus.map_music[rand] return mmus.tracklump, flags, true else -- use the default music lump if (mmus.defaults[mapname]) then -- custom default is set, so use that mmus.tracklump = mmus.defaults[mapname] return mmus.tracklump, flags, true else mmus.tracklump = nil -- reset tracklump for unmodified music track return end end else -- WHOOPS, DUPLICATE THIS DUMB SHIT OR THE REPLACEMENT FUNCTIONALITY DOESN'T WORK UNLESS YOU HAVE MULTIPLE SONGS DEFINED if (mmus.defaults[mapname]) then mmus.tracklump = mmus.defaults[mapname] return mmus.tracklump, flags, true end end end end end) addHook("MapChange", function(mapnum) mmus.randomized = false mmus.voterandomized = false mmus.queued = false mmus.queuesong = nil end) -- Victory themes, by zxyspku and Lat' -- rewritten and probably ruined by Snu DynMusic.vict = {} -- module namespace local vict = DynMusic.vict -- shorthand to prevent clusterfucks vict.cv_victorythemes = CV_RegisterVar({"victorythemes", "Off", 0, CV_OnOff}) vict.themes = {} local labels = {} -- exposing this so modders can get victory themes vict.GetMusic = function(p) local skin = p.mo.skin vict.themes[skin] = $ ~= nil and $ or {} -- initialize if (p.kartstuff[k_position] == 1) if vict.themes[skin][1] return vict.themes[skin][1] else if vict.themes[skin][2] return vict.themes[skin][2] end end return "KRWIN" else if vict.themes[skin][2] return vict.themes[skin][2] else if vict.themes[skin][1] return vict.themes[skin][1] end end return "KROK" end end DynMusic.FuckYou("addvictorytheme", function(player, skin, lump, label) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "addvictorytheme : Sets the victory theme for the given skin to the provided lump") return end if not (lump) then error("no music lump provided") return end vict.themes[skin] = $ ~= nil and $ or {} vict.themes[skin][1] = lump:upper() if (label) then -- initialize labels[skin] = $ ~= nil and $ or {} -- same with the labels table labels[skin][1] = label end CONS_Printf(player, "[Victory Themes] Victory theme for \""..skin.."\" has been set to \x82"..lump.."\x80") end) DynMusic.FuckYou("addokayfinishtheme", function(player, skin, lump, label) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "addokayfinishtheme : Sets the okay victory theme for the given skin to the provided lump") return end if not (lump) then error("no music lump provided") return end vict.themes[skin] = $ ~= nil and $ or {} -- we'll store this in the second index, instead vict.themes[skin][2] = lump:upper() if (label) then labels[skin] = $ ~= nil and $ or {} labels[skin][2] = label end CONS_Printf(player, "[Victory Themes] Okay finish theme for \""..skin.."\" has been set to \x82"..lump.."\x80") end) COM_AddCommand("delvictorytheme", function(player, skin) if (player ~= consoleplayer) then return end if not (skin) then CONS_Printf(player, "delvictorytheme : Removes the currently set victory themes for the provided skin") return end vict.themes[skin] = nil if (labels[skin]) then labels[skin] = nil end CONS_Printf(player, "[Victory Themes] Victory themes for \""..skin.."\" removed") end) COM_AddCommand("listvictorythemes", function(player) if (player ~= consoleplayer) then return end if (next(vict.themes) == nil) then CONS_Printf(player, "Victory theme table is empty") return end CONS_Printf(player, "Victory Theme List") for k, v in pairs(vict.themes) do -- initialize tables v = $ ~= nil and $ or {} labels[k] = $ ~= nil and $ or {} -- create the starting string local str = "" -- check if 1st place victory theme exists if vict.themes[k][1] str = k.." (Victory): "..v[1] if (labels[k][1]) then str = str.." - "..labels[k][1] end CONS_Printf(player, str) end -- check if okay finish theme exists if v[2] str = k.." (Okay Finish): "..v[2] if (labels[k][2]) then str = str.." - "..labels[k][2] end CONS_Printf(player, str) end end end) addHook("MusicChange", function(oldmusic, newmusic, flags, looping) if not (vict.cv_victorythemes.value) then return end if not ((newmusic == "krwin") or (newmusic == "krok")) then return end local vict_player for cp in displayplayers.iterate if cp.exiting vict_player = cp end end if (vict_player) -- paranoia local p = vict_player if vict.GetMusic(p) return vict.GetMusic(p), flags, true end end end) æLUA_HLPRò92LUA_SPBM+DžLUA_FLMÉZ²LUA_MMT{kò:LUA_MMUSm¦°LUA_VICT