//Sonic Lost World Bounce Attack for PTails!
addHook("MobjThinker", function(tails)
	if (tails and tails.skin == "tails") //if you're tails
	and tails.player.playerstate == PST_LIVE //you alive bruh?
	and not (tails.player.powers[pw_super]) //super tailshas float instead
		if tails.player.bounceattack == nil //if the variable doesnt exist
			tails.player.bounceattack = 0 //create variable
		end
		if tails.player.bouncenumber == nil //if the variable doesnt exist
			tails.player.bouncenumber = 0 //create variable
			tails.player.justchangedbouncenumber = 0 //create variable
		end
		if P_IsObjectOnGround(tails) //are you on the ground?
		and tails.player.bounceattack == 0 //the player isnt bouncing
			tails.player.bouncenumber = 0 //set it to zero!
		end
		if tails.player.usedown == nil //if the variable doesnt exist
		or not (tails.player.cmd.buttons & BT_USE) //not pressing the spin button?
			tails.player.usedown = 0 //create variable
			tails.player.justchangedbouncenumber = 0 //create variable
		end
		if P_IsObjectOnGround(tails) //Is the player on the ground?
		and (tails.player.cmd.buttons & BT_USE) //Is the player holding the spin button?
			tails.player.usedown = 1 //Set it to one!
		end
		if tails.player.pflags & PF_JUMPED //if the player has jumped
		and not (tails.player.pflags & PF_THOKKED) //and the player hasnt used their mid-air ability
		and not (P_IsObjectOnGround(tails)) //and you arent on the ground.
		and tails.player.cmd.buttons & BT_USE //pressing custom2?
		and tails.player.bounceattack == 0 //checking if the custom variable it set to 0
		and tails.player.usedown == 0 //make sure you arent holding the spin button.
		and not (tails.player.exiting) //not...exiting the level?
		and tails.health //you're alive?
		and not (P_PlayerInPain(tails.player)) //not hurt are you?
			tails.player.bounceattack = 1 //set it to one!
			P_SetObjectMomZ(tails, -35*FRACUNIT) //make the player "shoot" downward
			//P_SetObjectMomZ(tails, FixedMul(-35*FRACUNIT, tails.scale)) //make the player shoot downwards 
			tails.player.pflags = $1|PF_THOKKED //force the player into a "thokked" state
		end
			
		if (tails.eflags & MFE_JUSTHITFLOOR) //you're on the ground.
		and not (tails.player.pflags & PF_SPINNING) //you arent spinning....somehow
		and not (tails.player.pflags & PF_STARTDASH) //you arent doing a spindash
		and not (tails.tracer and tails.tracer.type == MT_TUBEWAYPOINT) //not in a...zoomtube?
		and tails.player.bounceattack == 1 //our custom variable is one right...?
		and tails.health //is the player alive..?
		and not (P_PlayerInPain(tails.player)) //not hurt are you?
			if tails.player.bouncenumber == 0 //if he hasnt bounced yet
			and tails.player.justchangedbouncenumber == 0 //if he hasnt left the ground yet
				tails.player.justchangedbouncenumber = 1 //now he has!
				tails.player.bouncenumber = 1 //Set this to one!
				tails.player.pflags = $1|PF_JUMPED //forcing the player into a jumping state.
				P_SetObjectMomZ(tails, 12*FRACUNIT)
				if not (tails.player.panim == PA_ROLL) //checking if the players animation is it's spinning anim.
					tails.state = S_PLAY_ROLL //force the player into a spinning state.
				end
			end
			if tails.player.bouncenumber == 1 //if it's currently on his first bounce
			and tails.player.justchangedbouncenumber == 0 //if he hasnt left the ground yet
			and not (P_PlayerInPain(tails.player)) //not hurt are you?
				tails.player.justchangedbouncenumber = 1 //now he has!
				tails.player.bouncenumber = 2 //set this to two!
				tails.player.pflags = $1|PF_JUMPED //forcing the player into a jumping state.
				P_SetObjectMomZ(tails, 13*FRACUNIT)
				if not (tails.player.panim == PA_ROLL) //checking if the players animation is it's spinning anim.
					tails.state = S_PLAY_ROLL //force the player into a spinning state.
				end
			end
			if tails.player.bouncenumber == 2 //if it's currently on his second bounce
			and tails.player.justchangedbouncenumber == 0 //if he hasnt left the ground yet
			and not (P_PlayerInPain(tails.player)) //not hurt are you?
				tails.player.justchangedbouncenumber = 1 //now he has!
				tails.player.bouncenumber = 0 //set it back to zero
				tails.state = S_PLAY_SPRING //change to spring frame, like is SLW!
				P_SetObjectMomZ(tails, 15*FRACUNIT) //send the player upwards
				tails.player.pflags = $1 & ~PF_JUMPED // No longer jumping. Don't land on an enemy!
			end
			tails.player.bounceattack = 0 //set it back to zero.
			tails.player.usedown = 1 //set it to one.
			tails.player.pflags = $1 & ~PF_THOKKED //uncheck the thokked flag, allowing you to bounce again.
			S_StartSound(tails, sfx_s3k77) //play a sound c:			
			
		end
		//some quick checks
		
		if tails.player.bounceattack == 1 //checking our variable.
		and tails.health //and you're alive
		and not (P_PlayerInPain(tails.player)) //not hurt are you?
			P_SpawnThokMobj(tails.player) //spawn the players thok object
			if not (tails.player.panim == PA_ROLL) //checking if the players animation is it's spinning anim.
				tails.state = S_PLAY_ROLL //force the player into a spinning state.
			end
			if (tails.momz > (9000*P_MobjFlip(tails))) // the player is going up...?  
				P_SetObjectMomZ(tails, FixedMul(-35*FRACUNIT, tails.scale)) //not anymore >.>
			end
		else 
			tails.player.bounceattack = 0 //set it to 0
		end
		if tails.player.bounceattack == 1 //checking if hes bouncing
			tails.player.pflags = $1 & ~PF_SPINNING // you're no longer "spinning" if you were before
		end
		if not (tails.player.pflags & PF_JUMPED) // if you are not actuallly jumping
			tails.player.bounceattack = 0 //set this back to zero to be safe
		end
		
		if tails.eflags & MFE_GOOWATER //is the player in THZ goop?
		or tails.player.powers[pw_carry] //is the player being carried?
		//or tails.player.pflags & PF_ROPEHANG //is the player on a ACZ ropehang?
			tails.player.bounceattack = 0 //set to zero!
		end
		if not (tails.player.pflags & PF_JUMPED) //if the player hasnt jumped
			tails.player.bounceattack = 0 //set this to zero
		end
	end
end, MT_PLAYER)