local _a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l,_m,_n,_o,_p,_q,_r,_s,v
local function fs_abl(u)
	local player = u
	if ((player.panim == PA_RUN) or (player.panim == PA_ROLL) or (player.panim == PA_ABILITY) or (player.pflags & PF_STARTDASH))
	and (player.cmd.forwardmove) then
		local direction = (player.cmd.forwardmove > 0) and 1 or -1
		player.fs_totalmovespeed = ($ or 0)+(FRACUNIT/4)
		P_Thrust(player.mo, player.mo.angle, player.fs_totalmovespeed*direction)
	else
		player.fs_totalmovespeed = 0
	end
	if (player.mo.health-1 >= 60)
		if (player.mo.fs_sequence == 1056) then
			if (not player.mo.fs_scramble) then
				for player2 in players.iterate do
					S_StartSound(nil, sfx_bnce1, player2)
					if player2 ~= player then
						player.charability = P_RandomRange(CA_THOK, CA_JUMPTHOK)
					end
					P_StartQuake(10*FRACUNIT, 4)
				end
				player.mo.fs_scramble = true
				u.fss = nil
			end
		else
			local e="f"
			local f=(-u.cmd.forwardmove<0)
			local b=(-u.cmd.forwardmove>0)
			local rl=(-u.cmd.sidemove<0)
			local rr=(-u.cmd.sidemove>0)
			local c=(u.cmd.buttons&(1<<11))
			local i=(u.cmd.buttons&(1<<7))
			if not u.fss u.fss = {} u.fss2 = {} end
			local s = u.fss
			local t = u.fss2
			v=16<<4
			if f t[v]=($ or 0)+1 else t[v]=0 end
			v=16<<5
			if b t[v]=($ or 0)+1 else t[v]=0 end
			v=16<<7
			if rr t[v]=($ or 0)+1 else t[v]=0 end
			v=16<<6
			if rl t[v]=($ or 0)+1 else t[v]=0 end
			v=16<<3
			if c t[v]=($ or 0)+1 else t[v]=0 end
			v=16<<2;if i t[v]=($ or 0)+1 else t[v]=0 end
			if t[8*8]==1 table.insert(s,((64/50)*10)-3) end
			if t[8*8*2]==1 table.insert(s,((64/50)*10)-4) end
			if t[8*8*2*2]==1 table.insert(s,(64/50)*10) end
			if t[8*8*2*2*2]==1 table.insert(s,((64/50)*10)+1) end
			if t[8*8*2*2*2*2]==1 table.insert(s,((64/50)*10)+4) end
			if t[8*8*2*2*2*2*2]==1 table.insert(s,((64/50)*10)+5) end
			v=1
			while v<11 if s[v] e=e+tostring(s[v]) end v=v+1 end
			player.fs_seq2 = e
			f = #e
			_a = ""
			_b = ""
			_c = ""
			_d = ""
			_e = ""
			_f = ""
			_g = ""
			_h = ""
			_i = ""
			_j = ""
			_k = ""
			_l = ""
			_m = ""
			_n = ""
			_o = ""
			_p = ""
			_q = ""
			_r = ""
			_s = ""
			if f>=1 then
				_a = string.sub(e,1,1)
				if f>=2 then
					_b = string.sub(e,2,2)
					if f>=3 then
						_c = string.sub(e,3,3)
						if f>=4 then
							_d = string.sub(e,4,4)
							if f>=5 then
								_e = string.sub(e,5,5)
								if f>=6 then
									_f = string.sub(e,6,6)
									if f>=7 then
										_g = string.sub(e,7,7)
										if f>=8 then
											_h = string.sub(e,8,8)
											if f>=9 then
												_i = string.sub(e,9,9)
												if f>=10 then
													_j = string.sub(e,10,10)
													if f>=11 then
														_k = string.sub(e,11,11)
														if f>=12 then
															_l = string.sub(e,12,12)
															if f>=13 then
																_m = string.sub(e,13,13)
																if f>=14 then
																	_n = string.sub(e,14,14)
																	if f>=15 then
																		_o = string.sub(e,15,15)
																		if f>=16 then
																			_p = string.sub(e,16,16)
																			if f>=17 then
																				_q = string.sub(e,17,17)
																				if f>=18 then
																					_r = string.sub(e,18,18)
																					if f>=19 then
																						_s = string.sub(e,19,19)
																					else
																						return
																					end
																				else
																					return
																				end
																			else
																				return
																			end
																		else
																			return
																		end
																	else
																		return
																	end
																else
																	return
																end
															else
																return
															end
														else
															return
														end
													else
														return
													end
												else
													return
												end
											else
												return
											end
										else
											return
										end
									else
										return
									end
								else
									return
								end
							else
								return
							end
						else
							return
						end
					else
						return
					end
				else
					return
				end
			else
				return
			end
			//print(_a,_b,_c,_d,_e,_f,_g,_h,_i,_j,_k,_l,_m,_n,_o,_p,_q,_r,_s)
			if _a=="f" then
				if _b=="1" then
					if _c=="0" then
						if _d=="1" then
							if _e=="0" then
								if _f=="1" then
									if _g=="1" then
										if _h=="1" then
											if _i=="1" then
												if _j=="1" then
													if _k=="5" then
														if _l=="1" then
															if _m=="4" then
																if _n=="1" then
																	if _o=="5" then
																		if _p=="1" then
																			if _q=="4" then
																				if _r=="6" then
																					if _s=="7" then
																						player.mo.fs_sequence=66<<4
																					else
																						u.fss = nil
																					end
																				else
																					u.fss = nil
																				end
																			else
																				u.fss = nil
																			end
																		else
																			u.fss = nil
																		end
																	else
																		u.fss = nil
																	end
																else
																	u.fss = nil
																end
															else
																u.fss = nil
															end
														else
															u.fss = nil
														end
													else
														u.fss = nil
													end
												else
													u.fss = nil
												end
											else
												u.fss = nil
											end
										else
											u.fss = nil
										end
									else
										u.fss = nil
									end
								else
									u.fss = nil
								end
							else
								u.fss = nil
							end
						else
							u.fss = nil
						end
					else
						u.fss = nil
					end
				else
					u.fss = nil
				end
			else
				u.fss = nil
			end
		end
	end
end

freeslot("sfx_dicks", "sfx_bhmwo", "sfx_clown", "sfx_tetsu", "sfx_waaaaa", "sfx_chaost", "sfx_donuea", "sfx_cough", "sfx_bbeer", "sfx_yup", "sfx_swoos", "sfx_nolike", "sfx_interc", "sfx_ilike", "sfx_mltsh", "sfx_froot", "sfx_plan", "sfx_likson", "sfx_learn", "sfx_scitm", "sfx_megoku") -- freeslot taunts
local function fs_taunts(p)    
    local mo = p.mo
   
    if (p.cmd.buttons & BT_CUSTOM3)
        p.fs_cb3 = p.fs_cb3 ~= nil and $+1 or 1
    else
        p.fs_cb3 = 0
    end
    
    if (p.fs_cb3 == 1)
        local fs_taunts = {sfx_dicks, sfx_bhmwo, sfx_clown, sfx_tetsu, sfx_waaaaa, sfx_chaost, sfx_donuea, sfx_cough, sfx_bbeer, sfx_yup, sfx_swoos, sfx_nolike, sfx_interc, sfx_ilike, sfx_mltsh, sfx_froot, sfx_plan, sfx_likson, sfx_learn, sfx_scitm, sfx_megoku}
        local fs_taunt = fs_taunts[P_RandomRange(1, #fs_taunts)]
        
        -- spawn a separate mo so we can cancel the taunts out easier
        if not (mo.fs_taunter and mo.fs_taunter.valid)
            mo.fs_taunter = P_SpawnMobj(mo.x, mo.y, mo.z, MT_THOK)
            mo.fs_taunter.state = S_INVISIBLE
        else
            S_StopSound(mo.fs_taunter)
        end
        
        S_StartSound(mo.fs_taunter, fs_taunt)
        mo.fs_taunter.fs_savetaunt = fs_taunt
    end
    
    if (mo.fs_taunter and mo.fs_taunter.valid)
        P_TeleportMove(mo.fs_taunter, mo.x, mo.y, mo.z)
        if not S_SoundPlaying(mo.fs_taunter, mo.fs_taunter.fs_savetaunt)
            P_RemoveMobj(mo.fs_taunter)
        end
    end
end

sfxinfo[sfx_dicks].caption = "Who's been drawing dicks?"
sfxinfo[sfx_bhmwo].caption = "*Brazil Intensifies*"
sfxinfo[sfx_clown].caption = "*Clown Honk*"
sfxinfo[sfx_tetsu].caption = "TESTUDINATA"
sfxinfo[sfx_waaaaa].caption = "WAAAAAAAAAAA-"
sfxinfo[sfx_chaost].caption = "*Kleiner intensifies*"
sfxinfo[sfx_donuea].caption = "Who ate all the donuts?"
sfxinfo[sfx_cough].caption = "*Cough*"
sfxinfo[sfx_bbeer].caption = "Buy you a beer."
sfxinfo[sfx_swoos].caption = "Watch me swoos right in."
sfxinfo[sfx_nolike].caption = "I don't like it."
sfxinfo[sfx_interc].caption = "Fred Fucks."
sfxinfo[sfx_ilike].caption = "I like it :)"
sfxinfo[sfx_mltsh].caption = "Maltshop"
sfxinfo[sfx_froot].caption = "*Shaggy becomes a brainlet*"
sfxinfo[sfx_yup].caption = "Yup."
sfxinfo[sfx_plan].caption = "What's the plan?"
sfxinfo[sfx_scitm].caption = "No, I'm with the science team!"
sfxinfo[sfx_likson].caption = "LIKE SONIC LIKE SONIC LIKE-"
sfxinfo[sfx_learn].caption = "Your actions have consequences!"
sfxinfo[sfx_megoku].caption = "Goku at your door ASMR"

for player in players.iterate do
	COM_BufInsertText(player, "cls")
end

addHook("ThinkFrame", function()
for player in players.iterate
	if player.mo and player.mo.skin == "flysonic" then
		player.jump = $ or 0
		player.imdead = $ or 0
		player.owie = $ or 0
		player.joel = $ or 0
		player.crash = $ or 0
		player.sound = $ or 0
		player.cstate = $ or 0
		player.cstate = ($ - 1)
		// after % is number of sounds
		player.sound = ($ + 1) % 14 //jump
		player.dsound = $ or 0
        player.dsound = ($ + 1) % 10 //death
		player.psound = $ or 0
		player.psound = ($ + 1) % 12 //pain
		player.wins = $ or 0
		player.wsound = $ or 0
		player.wsound = ($ + 1) % 2 //winning
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate do
		if not player.mo then continue end
		if player.mo.skin == "flysonic" then
			fs_abl(player)
			fs_taunts(player)
		end
	end
end)

for i = 1, 14 // i = 1, (number of jump sounds)
  local string = "sfx_jmp"..i
  freeslot(string)
end

sfxinfo[sfx_jmp1].caption = "Jump"
sfxinfo[sfx_jmp2].caption = "Jump"
sfxinfo[sfx_jmp3].caption = "Jump"
sfxinfo[sfx_jmp4].caption = "GoldSourceJump"
sfxinfo[sfx_jmp5].caption = "GIVE ME YOUR LIVER"
sfxinfo[sfx_jmp6].caption = "Jump"
sfxinfo[sfx_jmp7].caption = "GIVE ME YOUR BITS"
sfxinfo[sfx_jmp8].caption = "Jump"
sfxinfo[sfx_jmp9].caption = "Jump"
sfxinfo[sfx_jmp10].caption = "Jump"
sfxinfo[sfx_jmp11].caption = "Spyro Jump"
sfxinfo[sfx_jmp12].caption = "Patrick Jump"
sfxinfo[sfx_jmp13].caption = "Spongebob Jump"
sfxinfo[sfx_jmp14].caption = "Super Toad 67"

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "flysonic" and mariomode == false and not player.powers[pw_super] then
		if player.pflags & PF_JUMPED and player.jump == 0 then
			local sounds = {}
		 // for i = 1, (number of jump sounds)
			for i = 1, 14 do table.insert(sounds, _G["sfx_jmp"..i]) end 
			S_StartSound(player.mo, sounds[player.sound + 1])
			player.jump = 1
		end
			if  (P_IsObjectOnGround(player.mo)) then
			player.jump = 0
			end
		end
	end
end)

for i = 1, 10 // i = 1, (number of death sounds)
  local string = "sfx_ded"..i
  freeslot(string)
end

sfxinfo[sfx_ded1].caption = "Michael P Intensifies"
sfxinfo[sfx_ded2].caption = "Loud Nigra"
sfxinfo[sfx_ded3].caption = "Sammy Screaming"
sfxinfo[sfx_ded4].caption = "Doomguy Dying"
sfxinfo[sfx_ded5].caption = "Hunter Fucking Dies"
sfxinfo[sfx_ded6].caption = "Adventure 3 Isn't a Reality"
sfxinfo[sfx_ded7].caption = "SEGA JP Doesn't Touch This"
sfxinfo[sfx_ded8].caption = "Wario Dies In A Car Crash"
sfxinfo[sfx_ded9].caption = "Werehog Is No More"
sfxinfo[sfx_ded10].caption = "French Luigi Dies"

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "flysonic" and mariomode == false then
		if player.playerstate == PST_DEAD and player.imdead == 0 then
			local sounds = {}
		 // for i = 1, (number of death sounds)
			for i = 1, 10 do table.insert(sounds, _G["sfx_ded"..i]) end 
			S_StartSound(player.mo, sounds[player.dsound + 1])
			player.imdead = 1
			player.owie = 1
		end
			if player.playerstate == PST_REBORN then
			player.imdead = 0
			player.owie = 0
			end
		end
	end
end)

for i = 1, 12 // i = 1, (number of hurt sounds)
  local string = "sfx_pain"..i
  freeslot(string)
end

sfxinfo[sfx_pain1].caption = "Oof"
sfxinfo[sfx_pain2].caption = "FUCK YOU"
sfxinfo[sfx_pain3].caption = "FRICKIN FRICK"
sfxinfo[sfx_pain4].caption = "Sonic Riders momento"
sfxinfo[sfx_pain5].caption = "No!"
sfxinfo[sfx_pain6].caption = "Stop!"
sfxinfo[sfx_pain7].caption = "HUEH"
sfxinfo[sfx_pain8].caption = "Liver not obtained"
sfxinfo[sfx_pain9].caption = "Metallic thwack"
sfxinfo[sfx_pain10].caption = "Spongebob Ow"
sfxinfo[sfx_pain11].caption = "Hit by metal"
sfxinfo[sfx_pain12].caption = "Patrick Ow"

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "flysonic" and mariomode == false then
		if player.powers[pw_flashing] > 0 and player.quittime == 0 and player.owie == 0 then
			local sounds = {}
			//for i = 1, (however many hurt sounds you have) 
			for i = 1, 12 do table.insert(sounds, _G["sfx_pain"..i]) end 
			S_StartSound(player.mo, sounds[player.psound + 1])
			player.owie = 1
		end
			if player.powers[pw_flashing] == 1 then
			player.owie = 0
			end
		end
	end
end)

freeslot("sfx_plane")
sfxinfo[sfx_plane].caption = "Joseph Joestar Simulator"

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "flysonic" and not player.powers[pw_super] then
		if player.mo.state == S_PLAY_FLY_TIRED and player.crash == 0 then
			S_StartSound(player.mo, sfx_plane)
			player.crash = 1
			player.mo.state = S_PLAY_PAIN
			player.cstate = 35
		end
		if player.cstate == 10 then
			player.mo.state = S_PLAY_JUMP
			player.pflags = $|PF_SPINNING
		end
		if player.cstate == 0 then
			player.mo.state = S_PLAY_FALL
			player.pflags = $|PF_SPINNING
		end
		if player.mo.state != S_PLAY_FLY_TIRED then
			player.crash = 0
			end
		end
	end
end)

for i = 1, 2 // i = 1, (number of win sounds)
  local string = "sfx_fin"..i
  freeslot(string)
end
sfxinfo[sfx_fin1].caption = "...AND TIME!"
sfxinfo[sfx_fin2].caption = "YEEAAHHH!"

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "flysonic" and not player.powers[pw_super] then
		if player.pflags & PF_FINISHED and player.wins == 0 then
			local sounds = {}
			//for i = 1, (however many win sounds you have) 
			for i = 1, 2 do table.insert(sounds, _G["sfx_fin"..i]) end 
			S_StartSound(player.mo, sounds[player.wsound + 1])
			player.wins = 1
			end
		end
	end
end)

addHook("MapLoad", do
	for player in players.iterate
		player.wins = 0
		end
	end)

freeslot("sfx_memari")
sfxinfo[sfx_memari].caption = "Mario has logged in."