-- In case addon loaded multiple times (when bundled with character addons, for -- instance) if dub_loaded then return end rawset(_G, "dub_loaded", true) local dub = {} local skinsounds = { SKSKWIN, SKSKLOSE, SKSKPAN1, SKSKPAN2, SKSKATK1, SKSKATK2, SKSKBST1, SKSKBST2, SKSKSLOW, SKSKHITM, SKSKPOWR, } local dub_enabled = CV_RegisterVar({ name = "dub_enabled", defaultvalue = "On", possiblevalue = CV_OnOff, }) local dub_soundoffhack = CV_RegisterVar({ name = "dub_soundoffhack", defaultvalue = "On", possiblevalue = CV_OnOff, }) COM_AddCommand("dub", function(player, skin, choice) if player.dub_choice == nil then player.dub_choice = {} end if skin == nil then CONS_Printf(player, "Usage: \129dub\128 <\130skin\128> [\131dub\128]") CONS_Printf(player, "Check \129dub_list\128 for all aviable dubs") elseif choice == nil then if dub[skin] == nil then CONS_Printf(player, "\134This skin does not have any custom dub") return end local skin_dubs = {"default"} for dubname, _ in pairs(dub[skin]) do table.insert(skin_dubs, dubname) end CONS_Printf(player, "Aviable dubs for skin \130"..skin.."\128: \131"..table.concat(skin_dubs, ", ")) else if dub[skin] == nil then CONS_Printf(player, "\134This skin does not have any custom dub") return end if choice == "default" then player.dub_choice[skin] = nil CONS_Printf(player, "Custom dub for skin \130"..skin.." \133disabled") return end if dub[skin][choice] == nil then CONS_Printf(player, "Dub \131"..choice.." \133does not exist\128 for skin \130"..skin) return end player.dub_choice[skin] = choice CONS_Printf(player, "Set dub \131"..choice.."\128 for skin \130"..skin) end end) COM_AddCommand("dub_list", function(player) local dubs = {"Skins with custom dubs:"} for skin, _ in pairs(dub) do local skin_dubs = {} for dubname, _ in pairs(dub[skin]) do table.insert(skin_dubs, dubname) end table.insert(dubs, "\130"..skin.."\128: \131"..table.concat(skin_dubs, ", ")) end if #dubs == 1 then CONS_Printf(player, "\134There are no dubs yet...") else CONS_Printf(player, table.concat(dubs, "\n")) end end) rawset(_G, "DUB_RegisterDub", function(skin, dubname, dubvoices) if dubname == "default" then error("dub name 'default' is reserved") end if dub[skin] == nil then dub[skin] = {} end dub[skin][dubname] = {} for soundid, soundname in pairs(dubvoices) do -- Do not freeslot sounds if they already are dub[skin][dubname][soundid] = _G[soundname] or freeslot(soundname) end end) addHook("ThinkFrame", function() if not dub_enabled.value then return end for player in players.iterate do if player.mo ~= nil and player.mo.valid and player.dub_choice ~= nil and player.dub_choice[player.mo.skin] ~= nil then local pdub = dub[player.mo.skin][player.dub_choice[player.mo.skin]] local psounds = skins[player.mo.skin].soundsid for _, sound in ipairs(skinsounds) do if pdub[sound] ~= nil then if S_SoundPlaying(player.mo, psounds[sound]) then S_StopSoundByID(player.mo, psounds[sound]) S_StartSound(player.mo, pdub[sound]) end end end if dub_soundoffhack.value then if pdub[SKSKWIN] ~= nil and S_IdPlaying(psounds[SKSKWIN]) then -- This is disgusting. I hate srb2[kart] lua api. -- (this is what i have to do to stop winning sound from playing) COM_BufInsertText(consoleplayer, "sounds Off; sounds On") S_StartSound(nil, pdub[SKSKWIN], consoleplayer) end if pdub[SKSKLOSE] ~= nil and S_IdPlaying(psounds[SKSKLOSE]) then COM_BufInsertText(consoleplayer, "sounds Off; sounds On") S_StartSound(nil, pdub[SKSKLOSE], consoleplayer) end end end end end)