Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Victory themes, by zxyspku and Lat'
- local cv_victorythemes = CV_RegisterVar({"victorythemes", "Off", 0, CV_OnOff})
- local victorythemes = {}
- local labels = {}
- -- we use a mapload hook to reset the var used below
- -- otherwise the finish music would never play again since it'd still be true :dying:
- addHook("MapLoad", function()
- for p in players.iterate
- p.vict_changedmusic = nil
- end
- end)
- local function DM_Vict_GetMusic(p, skin)
- victorythemes[skin] = $ ~= nil and $ or {} -- make sure this table is initialized
- if (p.kartstuff[k_position] == 1) -- first we check if we finished in first
- -- now we check for if the 1st place finish theme exists first (it's in the first index)
- if victorythemes[skin][1] -- check if it exists
- return victorythemes[skin][1] -- we found it, return it
- else -- it doesnt exist...
- -- for the convenience of the user, we'll attempt to fallback on the okay finish theme
- if victorythemes[skin][2] -- check if it exists again...
- return victorythemes[skin][2] -- we found our fallback, return it
- end
- end
- -- if we couldnt find anything after all that, we'll return the default KRWIN
- return "KRWIN"
- else
- -- we're gonna do the same as above, but now prioritizing the okay finish theme
- -- as well as defaulting to "KROK"
- if victorythemes[skin][2]
- return victorythemes[skin][2]
- else
- if victorythemes[skin][1]
- return victorythemes[skin][1]
- end
- end
- return "KROK"
- end
- end
- DM_FuckYou("addvictorytheme", function(player, skin, lump, label)
- if (player ~= consoleplayer) then return end
- if not (skin) then
- CONS_Printf(player, "addvictorytheme <skin> <lump>: 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
- -- when working with tables inside tables remember to do this
- -- this initializes the table so we can use it without anything breaking
- victorythemes[skin] = $ ~= nil and $ or {}
- -- we'll store this information in the first index of a table
- -- this creates a table in a table
- -- lua's greatest strength, tables in tables
- victorythemes[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)
- DM_FuckYou("addokayfinishtheme", function(player, skin, lump, label)
- if (player ~= consoleplayer) then return end
- if not (skin) then
- CONS_Printf(player, "addokayfinishtheme <skin> <lump>: 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
- victorythemes[skin] = $ ~= nil and $ or {}
- -- we'll store this in the second index, instead
- victorythemes[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 <skin>: Removes the currently set victory themes for the provided skin")
- return
- end
- victorythemes[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(victorythemes) == nil) then
- CONS_Printf(player, "Victory theme table is empty")
- return
- end
- CONS_Printf(player, "Victory Theme List")
- -- this loop goes through each index in victory themes
- -- k is the index (the skin we're checking)
- -- v is the table of the index (where our themes are stored)
- for k, v in pairs(victorythemes) 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 victorythemes[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("ThinkFrame", do
- -- we use this to check if the var is enabled
- -- if it was enabled, it'd return 1, which would make the condition true
- if not (cv_victorythemes.value) then return end
- -- this is just consoleplayer stuff copypasted from another script
- -- consoleplayers are the players that joined the game, and doesnt change
- -- of course, this means consoleplayers are different for each player and arent synched in netgames
- if not (consoleplayer) then return end
- local cp, cp2, cp3, cp4 = consoleplayer, secondarydisplayplayer, thirddisplayplayer, fourthdisplayplayer
- -- for all our player checks we need to check if .mo exists
- -- and for every player that isnt the first player we need to check if the splitplayer exists, too
- if (cp.mo and cp.exiting and not K_IsPlayerLosing(cp)) -- we want to know whether the player has finished the race and has won (isn't losing)
- or ((cp2 and cp2.mo) and cp2.exiting and not K_IsPlayerLosing(cp2)) -- copypaste the above condition for the second console player (splitscreen support)
- or ((cp3 and cp3.mo) and cp3.exiting and not K_IsPlayerLosing(cp3)) -- ditto, for the third consoleplayer
- or ((cp4 and cp4.mo) and cp4.exiting and not K_IsPlayerLosing(cp4)) -- ditto, for the fourth consoleplayer
- -- we dont want to change the music again if it's already changed
- -- this fixes finish music playing twice
- if (cp.vict_changedmusic) then return end
- -- splitscreen support (REALLY TEDIOUS)
- -- I dont recommend spltscreen support unless absolutely necessary
- -- for splitscreen we want to play the music of the first splitscreen player to finish
- -- we'll assume the starting index is 1 for non-splitscreen (first player)
- local vict_player = cp
- -- now we check for splitscreen players (while also making sure they exist in the first place)
- if ((cp2 and cp2.mo) and cp2.exiting and not K_IsPlayerLosing(cp2)) -- check if the second player finished first
- vict_player = cp2
- elseif ((cp2 and cp2.mo) and cp3.exiting and not K_IsPlayerLosing(cp3)) -- ditto, for the third player
- vict_player = cp3
- elseif ((cp2 and cp2.mo) and cp4.exiting and not K_IsPlayerLosing(cp4)) -- ditto, for the fourth player
- vict_player = cp4
- end
- -- we call the function here to quickly return what music we'll use
- -- the arguments the function needs are the player and what skin index to check
- -- we put vict_player.mo.skin in to return the skin index of the player we retrieved above
- -- mo.skin is the skin we're playing as, as text, so playing as Sonic returns "sonic"
- S_ChangeMusic(DM_Vict_GetMusic(vict_player, vict_player.mo.skin), true, cp)
- -- we set the var check here to trigger the return function at the start of the code block
- cp.vict_changedmusic = true
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement