--Script which replaces sector spring sounds with one defined in a map's Lua.altspring.
local function springreplace(mo)
	if not mapheaderinfo[gamemap].altspring return end
		if (((GetSecSpecial(mo.subsector.sector.special,3) == 1) or (GetSecSpecial(mo.subsector.sector.special,3) == 3)) and P_IsObjectOnGround(mo))
		or (P_ThingOnSpecial3DFloor(mo) and (GetSecSpecial(P_ThingOnSpecial3DFloor(mo).special,3) == 1)) or (P_ThingOnSpecial3DFloor(mo) and (GetSecSpecial(P_ThingOnSpecial3DFloor(mo).special,3) == 3))
			S_StopSoundByID(mo,sfx_kc2f)
			S_StartSound(mo,_G[mapheaderinfo[gamemap].altspring])
		end
end

addHook("MobjThinker", springreplace , MT_PLAYER)
addHook("MobjThinker", springreplace , MT_ORBINAUT)
addHook("MobjThinker", springreplace , MT_JAWZ)
addHook("MobjThinker", springreplace , MT_JAWZ_DUD)

--Prevents spring sounds from leaking through.
addHook("ThinkFrame", function ()
if not mapheaderinfo[gamemap].altspring return end
	for mobj in thinkers.iterate("mobj")
		--if mobj.type != MT_PLAYER or mobj.type != MT_ORBINAUT or mobj.type != MT_JAWZ or mobj.type != MT_JAWZ_DUD return end 
		if (GetSecSpecial(mobj.subsector.sector.special,3) == 1) or (GetSecSpecial(mobj.subsector.sector.special,3) == 3)
		or (P_ThingOnSpecial3DFloor(mobj) and (GetSecSpecial(P_ThingOnSpecial3DFloor(mobj).special,3) == 1)) or (P_ThingOnSpecial3DFloor(mobj) and (GetSecSpecial(P_ThingOnSpecial3DFloor(mobj).special,3) == 3))
			S_StopSoundByID(mobj,sfx_kc2f)
		end
	end
end)