//This is what makes tails talk when he gets hurt.
freeslot("sfx_no")


sfxinfo[sfx_no].caption = "oh no!"

local function playerow(target, inflictor, source, damage)
	if target.skin == "tails"
		S_StartSound(target, sfx_no)
	end
end

addHook("MobjDamage", playerow, MT_PLAYER)


//Tails Swipe
addHook("PlayerThink", function(player)
	if not (player.spinner)
		player.spinner = 0
	end
	if not (player.vanillatailswipe)
		player.vanillatailswipe = 0
	end
	if (player.mo.skin == "tails")
		if (player.speed > 1000*FRACUNIT)
		or (player.bot == 1)
			player.charability2 = CA2_SPINDASH
		else
			player.charability2 = CA2_SPINDASH
		end
		
		
		if (player.cmd.buttons & BT_CUSTOM1)--set it to which button you want
		and P_IsObjectOnGround(player.mo)
		and (player.speed < 1000*FRACUNIT)
		and not (player.bot == 1)
		and not (player.skidtime > 0) 
		and not (player.pflags & PF_SPINNING)
		and not (player.pflags & PF_STARTDASH)
		or (player.vanillatailswipe == 1)
		and (player.cmd.buttons & BT_CUSTOM1)
			player.vanillatailswipe = 1
		end
		
		
		if not (player.cmd.buttons & BT_CUSTOM1)
		and not (player.pflags & PF_STARTDASH)
		and not (player.pflags & PF_SPINNING)
		or not P_IsObjectOnGround(player.mo)
			player.vanillatailswipe = 0
		end
		
		
		if (player.vanillatailswipe == 1)
			player.mo.state = S_PLAY_RUN
			player.jumpfactor = 0
			player.normalspeed = 36*FRACUNIT
			//player.pflags = $|PF_SPINNING
			player.spinner = ($ % 7) + 1
			if (player.spinner > 7)
				player.spinner = 0
			end
			player.drawangle = player.spinner * ANGLE_45
		end
		
		//Return to normal
		if (player.vanillatailswipe == 0)
			player.jumpfactor = skins[player.mo.skin].jumpfactor
			player.normalspeed = skins[player.mo.skin].normalspeed
		end
	end
end)

local function tvanillaTailSwipe(enemy, mobj)
	local player = mobj.player
	if not (player.mo.skin == "tails")
	and not (player.vanillatailswipe == 1)
		return false
	end                                //This section will make the function damage 
	if (enemy.flags & (MF_ENEMY|MF_BOSS|MF_MONITOR)) 
	and (player.vanillatailswipe == 1)
	--and not (player.powers[pw_super])
	and not (player.powers[pw_invulnerability])
		P_DamageMobj(enemy, mobj, mobj)
		return true
	end
end

//This is what makes the super theme only for the characters
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.valid and player.mo.skin == "tails")
			if not player.powers[pw_extralife]
			and not (player.exiting)
			if player.powers[pw_super] then
				S_ChangeMusic("belive",true,player)
			end	
		else
			P_RestoreMusic(player)
			end
		end
	end
end)

addHook("TouchSpecial", tvanillaTailSwipe)

//This makes Tails fly without you spamming the jump button :D
addHook('JumpSpecial', function(player)
	    if player.mo and player.mo.valid
			if player.mo.skin == "tails"
               if (player.powers[pw_tailsfly] > 0) and (player.cmd.buttons & BT_JUMP)
                player.fly1 = 1
				end
			end
		end
end)
