// you spawn fire		
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "redsonic"
			if not (player.mo.firerun)
				player.mo.firerun = 0
			end
		if player.mo.state == S_PLAY_RUN
		and P_IsObjectOnGround(player.mo)
		and not (player.mo.eflags & MFE_UNDERWATER)
		--or player.mo.state == S_PLAY_ROLL
		or player.mo.state == S_PLAY_WALK
		and not (player.mo.eflags & MFE_UNDERWATER)
		and P_IsObjectOnGround(player.mo)
		or player.mo.state == S_PLAY_STND
		and not (player.mo.eflags & MFE_UNDERWATER)
		and P_IsObjectOnGround(player.mo)
		or player.mo.state == S_PLAY_WAIT
		and not (player.mo.eflags & MFE_UNDERWATER)
		and P_IsObjectOnGround(player.mo)
		or player.mo.state == S_PLAY_SKID
		and not (player.mo.eflags & MFE_UNDERWATER)
		and P_IsObjectOnGround(player.mo)
		or player.mo.state == S_PLAY_SPINDASH
		and not (player.mo.eflags & MFE_UNDERWATER)
		and P_IsObjectOnGround(player.mo)
		or (player.pflags & PF_SPINNING)
		and P_IsObjectOnGround(player.mo)
		and not (player.pflags & PF_THOKKED)
		and not (player.mo.eflags & MFE_UNDERWATER) then
			P_ElementalFire(player)
			player.mo.firerun = 1
		end
	end
end
end)
// spring fix
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "redsonic"
			if not (player.mo.sjump)
				player.mo.sjump = 0
			end
		if not P_IsObjectOnGround(player.mo)
		and (player.powers[pw_super]) --then
		and not (player.mo.state == S_PLAY_SPRING) then
		--and not (player.pflags & PF_THOKKED) then
		player.pflags = $1|PF_JUMPED
			player.mo.sjump = 1
		end
	end
end
end)	
// these 3 hooks are for the super fly
addHook("ThinkFrame", do
       for player in players.iterate
	   if (player.mo and player.mo.skin == "redsonic")
	   
	   if not (player.mo.flyup) then
	   player.mo.flyup = 0
	   end
	   
	   if (player.powers[pw_super])
	   and (player.pflags & PF_JUMPED)
	   and (player.cmd.buttons & BT_JUMP)
	   and not (player.cmd.buttons & BT_USE)
	    and not (player.powers[pw_carry])
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
	   and not P_IsObjectOnGround(player.mo)
	   P_SetObjectMomZ(player.mo, 20*FRACUNIT, false)
	   player.mo.state = S_PLAY_GLIDE
	   player.mo.flyup = 1
	   player.pflags = $1|PF_THOKKED
	   end
	    end
	end
end)

addHook("ThinkFrame", do
       for player in players.iterate
	   if (player.mo and player.mo.skin == "redsonic")
	   
	   if not (player.mo.flydown) then
	   player.mo.flydown = 0
	   end
	   if (player.powers[pw_super])
	   and (player.pflags & PF_JUMPED)
	   	and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
	   and (player.cmd.buttons & BT_USE)
	   and not (player.cmd.buttons & BT_JUMP)
	    and not (player.powers[pw_carry])
	   and not P_IsObjectOnGround(player.mo)
	   P_SetObjectMomZ(player.mo, -20*FRACUNIT, false)
	   player.mo.state = S_PLAY_GLIDE
	   player.mo.flydown = 1
	   player.pflags = $1|PF_THOKKED
	   end
	    end
	end
end)

addHook("ThinkFrame", do
       for player in players.iterate
	   if (player.mo and player.mo.skin == "redsonic")
	   
	   if not (player.mo.airfly) then
	   player.mo.airfly = 0
	   end
	   
	   if (player.powers[pw_super])
	   and (player.pflags & PF_THOKKED)
	   and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		and not (player.pflags & PF_FINISHED)
		and not (player.mo.state == S_PLAY_DEAD)
	  and not (player.powers[pw_carry])
	   and not (player.cmd.buttons & BT_JUMP)
	   and not (player.cmd.buttons & BT_USE)
	   and not P_IsObjectOnGround(player.mo)
	   P_SetObjectMomZ(player.mo, 0*FRACUNIT)
	   player.mo.state = S_PLAY_GLIDE
	   player.mo.airfly = 1
	   player.pflags = $1|PF_THOKKED
	   end
	   end
	end
end)


// these 4 hooks are for the boost as super sonic
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "redsonic")
			if not (player.mo.superredboost)
				player.mo.superredboost = 0
			end
			if player.cmd.buttons & BT_CUSTOM2
		    and (player.powers[pw_super])
			and not (player.powers[pw_carry])
			and not (player.powers[pw_sneakers])
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
			and not P_IsObjectOnGround(player.mo)
				if player.mo.superredboost == 0
					player.mo.superredboost = 1
					player.mo.state = S_PLAY_GLIDE
				end
				P_InstaThrust(player.mo, player.mo.angle, 95*FRACUNIT)
			end
			if not (player.cmd.buttons & BT_CUSTOM1)
				player.mo.superredboost = 0
				end
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "redsonic")
			if not (player.mo.superredboost)
				player.mo.superredboost = 0
			end
			if player.cmd.buttons & BT_CUSTOM2
		    and (player.powers[pw_super])
			and not (player.powers[pw_carry])
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
			and not (player.powers[pw_sneakers])
			and P_IsObjectOnGround(player.mo)
				if player.mo.superredboost == 0
					player.mo.superredboost = 1
					player.mo.state = S_PLAY_RUN
				end
				P_InstaThrust(player.mo, player.mo.angle, 95*FRACUNIT)
			end
			if not (player.cmd.buttons & BT_CUSTOM2)
				player.mo.superredboost = 0
			end
		end
	end
end)
	
	addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "redsonic")
			if not (player.mo.superredboost)
				player.mo.superredboost = 0
			end
			if player.cmd.buttons & BT_CUSTOM2
			and (player.powers[pw_sneakers])
			and not (player.powers[pw_carry])
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		    and (player.powers[pw_super])
			and P_IsObjectOnGround(player.mo)
				if player.mo.superredboost == 0
					player.mo.superredboost = 1
					player.mo.state = S_PLAY_RUN
				end
				P_InstaThrust(player.mo, player.mo.angle, 125*FRACUNIT)
			end
			if not (player.cmd.buttons & BT_CUSTOM2)
				player.mo.superredboost = 0
			end
		end
	end
end)


	addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "redsonic")
			if not (player.mo.superredboost)
				player.mo.superredboost = 0
			end
			if player.cmd.buttons & BT_CUSTOM2
			and (player.powers[pw_sneakers])
			and not (player.powers[pw_carry])
		    and (player.powers[pw_super])
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
			and not P_IsObjectOnGround(player.mo)
				if player.mo.superredboost == 0
					player.mo.superredboost = 1
					player.mo.state = S_PLAY_GLIDE
				end
				P_InstaThrust(player.mo, player.mo.angle, 125*FRACUNIT)
			end
			if not (player.cmd.buttons & BT_CUSTOM2)
				player.mo.superredboost = 0
			end
		end
	end
end)
// fire not hurting you
addHook("ShouldDamage", function(target, inflictor, damage)
	if (target.skin == "redsonic")if (inflictor and inflictor.flags & MF_FIRE) 
		return false
	end
end
end, MT_PLAYER) 

// fire not hurting you
addHook("MobjDamage",function(ptarget, inf, src, damage, damageType)
	for player in players.iterate
			if not (player.mo.firer)
				player.mo.firer = 0
			end
  if not (ptarget and ptarget.valid and ptarget.player) return end
  if ptarget.skin == "redsonic" and damageType == DMG_FIRE 
    return true
  end
end
end,MT_PLAYER)
// spike killer
addHook ("MobjMoveCollide", function (player, spike)
	if player.player ~= nil and player.player.powers[pw_super] and player.skin == "redsonic"
		if (spike.type == MT_SPIKE
		or spike.type == MT_WALLSPIKE)
			if (player.z + player.height < spike.z) 
			or (player.z > spike.z + spike.height)
				return false
			else
				P_KillMobj(spike,player,player)
			end
		end
	end
end)

//double jump (not shield)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "redsonic"
		
			   
	   if not (player.mo.usedown) then
	   player.mo.usedown = 0
	   end
	   
	  if not (player.mo.doublejump) then
	   player.mo.doublejump = 0
	   end
	   
	   if (player.cmd.buttons & BT_USE)
	   and (player.mo.usedown == 0)
	   and (player.pflags & PF_JUMPED)
	   and player.powers[pw_shield] == SH_NONE
	   and not (player.pflags & PF_THOKKED)
	   and not (player.powers[pw_super])
	    and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
	   and not P_IsObjectOnGround(player.mo)
	   S_StartSound(player.mo, sfx_jump)
	   player.mo.usedown = 1
	   player.mo.usejump = 1
	   player.mo.state = S_PLAY_ROLL
	   P_SetObjectMomZ(player.mo, 11*FRACUNIT, false)
	   player.pflags = $1|PF_THOKKED
	   --player.pflags = $1 & ~PF_JUMPED
	   end
	   
	   if (player.mo.doublejump == 1)
	   and not P_IsObjectOnGround(player.mo)
	   player.pflags = $1|PF_THOKKED
	  -- player.pflags = $1 & ~PF_JUMPED
	   end

	   
	   if not (player.cmd.buttons & BT_USE)
	   and (player.mo.usedown == 1)
	   player.mo.usedown = 0
	   end
	   
	    end
	end
end)

// damage fix
addHook("PlayerCanDamage", function(player, mobj)
	if player.mo and player.mo.skin == "redsonic"
	and player.mo.state == S_PLAY_ROLL
	and (mobj.flags&MF_ENEMY or mobj.flags&MF_BOSS or mobj.flags&MF_MONITOR) return true end
end, MT_PLAYER)

// give a ring (useful for super sonic)
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "redsonic")
			  if not (player.mo.fbox) then
	   player.mo.fbox = 0
	   end
	   
	 if not(player.pflags & PF_FINISHED)
	and not (player.weapondelay) 
	--and not player.pflags & PF_JUMPED
	     and player.cmd.buttons & BT_TOSSFLAG
		 and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.pflags & PF_FINISHED)
		and not (player.mo.state == S_PLAY_DEAD)
		local boxf = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_RING)
         boxf.scale = player.mo.scale -- this was useless but i kept it just in case
		 player.weapondelay = TICRATE*1
	           player.mo.fbox = 1
			end
		end
	end
end)
// the coolest 06 jump(its a scrapped code)
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "redsonic"
     if not (player.mo.jump) then
	   player.mo.jump = 0
	   end
		if (player.pflags & PF_JUMPED)
		and not (player.powers[pw_super])
		and not (player.pflags & PF_THOKKED)
		and not player.powers[pw_justsprung]
		and not player.powers[pw_carry]
			and not (player.mo.eflags & MFE_VERTICALFLIP)
				if player.mo.momz < 1
                 player.mo.state = S_PLAY_FALL
				end
				if player.mo.momz > 1
				if not (player.mo.state == S_PLAY_JUMP) 					
				player.mo.state = S_PLAY_JUMP
			end
		end
	end
if (player.pflags & PF_JUMPED) 
if not (player.powers[pw_super])
and not (player.pflags & PF_THOKKED)
and not player.powers[pw_justsprung]
and not player.powers[pw_carry]
	and (player.mo.eflags & MFE_VERTICALFLIP)
		if player.mo.momz < 1 
		player.mo.state = S_PLAY_JUMP
	end
			if player.mo.momz > 1
		 if not (player.mo.state == S_PLAY_FALL) 
				player.mo.state = S_PLAY_FALL	
						end
					end
				end
			end
		end
	end
end)
// infinite lives (for no reason)
addHook("ThinkFrame", do
	for player in players.iterate
		if (player.mo and player.mo.skin == "redsonic")
		if player.playerstate == PST_LIVE
		player.lives = 127
		end
		end
	end
end)
// go into a roll state when doing the thok
	addHook("ThinkFrame", do
    for player in players.iterate do
		if player.mo and player.mo.skin == "redsonic"
		and not player.powers[pw_super]
		and not P_IsObjectOnGround(player.mo)
		and (player.pflags & PF_THOKKED)
			player.mo.state = S_PLAY_ROLL
		end
	end
end)
// fire attack
addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "redsonic"
			if not (player.mo.fire)
				player.mo.fire = 0
			end
			if not (player.powers[pw_carry] == CR_NIGHTSMODE) 
			and not (player.powers[pw_carry]) 
			and not (player.pflags & PF_STASIS) 
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.pflags & PF_FINISHED)
		and P_PlayerInPain(player) == false
		    and player.playerstate == PST_LIVE
			 and (player.cmd.buttons & BT_CUSTOM1)
			and player.mo.fire == 0
            player.mo.fire = 1
		       local flame = P_SpawnPlayerMissile(player.mo, MT_REDFIRE)
			end
			if not (player.cmd.buttons & BT_CUSTOM1)
				player.mo.fire = 0
			end
		end
	end
end)

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "redsonic"
			if not (player.mo.fires)
				player.mo.fires = 0
			end
			if (player.cmd.buttons & BT_FIRENORMAL)
			 or (player.cmd.buttons & BT_CUSTOM3)
			and not (player.powers[pw_carry] == CR_NIGHTSMODE)
			and not (player.powers[pw_carry]) 
			and not (player.pflags & PF_STASIS)
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.pflags & PF_FINISHED)
		and P_PlayerInPain(player) == false
	    and player.playerstate == PST_LIVE
			and player.mo.fires == 0
				player.mo.fires = 1 
				S_StartSound(player.mo, sfx_s3k70)
		       local flame = P_SpawnPlayerMissile(player.mo, MT_REDFIRE)
				end
			if not (player.cmd.buttons & BT_FIRENORMAL)
			or not (player.cmd.buttons & BT_CUSTOM3)
				player.mo.fires = 0
			end
		end
	end
end)

// allow you to jump off when carried
	addHook("ThinkFrame", do
    for player in players.iterate do
		if player.mo and player.mo.skin == "redsonic"
		and player.powers[pw_super]
		and not P_IsObjectOnGround(player.mo)
		and (player.cmd.buttons & BT_ATTACK)
		and player.powers[pw_carry] == CR_PLAYER
			--player.mo.state = S_PLAY_ROLL
			player.pflags = $1 & ~PF_JUMPED
		end
	end
end)
// dont thok while super
addHook("JumpSpinSpecial", function(player) 
    if not (player.powers[pw_super] and player.mo.skin == "redsonic") then return end
    player.charability = CA_NONE
	end)
	
	addHook("AbilitySpecial", function(player) 
    if not (player.powers[pw_super] and player.mo.skin == "redsonic") then return end
    player.charability = CA_NONE
	end)
	// thok ability
		addHook("AbilitySpecial", function(player) 
    if (player.powers[pw_super] and player.mo.skin == "redsonic") then return end
    player.charability = CA_THOK
	end)