freeslot("sfx_drpdsh")
sfxinfo[sfx_drpdsh].caption = "Drop Dash"

addHook("PlayerThink", function(player)
	if player.dropdashcharged == nil
		player.dropdashcharged = false
	end
end)

freeslot(
"S_DROPDASH1",
"S_DROPDASH2",
"S_DROPDASH3",
"S_DROPDASH4",
"S_DROPDASH5",
"S_DROPDASH6",
"SPR_DRPD"
)

states[S_DROPDASH1] = {
	sprite = SPR_DRPD,
	frame = A,
	tics = 1,
	nextstate = S_DROPDASH2
}

states[S_DROPDASH2] = {
	sprite = SPR_DRPD,
	frame = B,
	tics = 1,
	nextstate = S_DROPDASH3
}

states[S_DROPDASH3] = {
	sprite = SPR_DRPD,
	frame = C,
	tics = 1,
	nextstate = S_DROPDASH4
}

states[S_DROPDASH4] = {
	sprite = SPR_DRPD,
	frame = D,
	tics = 1,
	nextstate = S_DROPDASH5
}

states[S_DROPDASH5] = {
	sprite = SPR_DRPD,
	frame = E,
	tics = 1,
	nextstate = S_DROPDASH6
}

states[S_DROPDASH6] = {
	sprite = SPR_DRPD,
	frame = F,
	tics = 1,
	nextstate = S_DROPDASH1
}

COM_AddCommand("truedropdash", function(p, arg)
	if arg == "off" then
		print("The Drop Dash is now off")
		p.truedropdash = 0
	elseif arg == "on" then
		print("The Drop Dash is now on")
		p.truedropdash = 1
	end
end)

addHook("PlayerThink", function(p)
	if p.truedropdash == nil
		p.truedropdash = 1
	end
end)

addHook("PlayerThink", function(p)
	-- Check if the player object exists, and is alive.
	if not (p.mo and p.mo.valid) then return end
	if not p.mo.health then return end

	-- Check for your skin.
	if p.mo.skin ~= "sonic" then return end
	
	-- Setup a simple button press check.
	
	if not (p.cmd.buttons & BT_CUSTOM1) then
		p.custom1ready = true
		p.custom1tap = false
	elseif p.custom1ready then
		p.custom1ready = false
		p.custom1tap = true
	else
		p.custom1tap = false
	end
end)

//true drop dash by TGTLS credit me and the people in the credits before using publicly, thanks!
addHook("PlayerThink", function(player)
	if player.mo.skin == "sonic"
	and player.mo.state == S_PLAY_JUMP
	and not player.dropdashcharged
	and player.truedropdash == 1
	and player.custom1tap
		player.dropdashcharged = true
		S_StartSound(player.mo, sfx_drpdsh)
		player.mo.state = S_DROPDASH1
	end
end)

addHook("PlayerThink", function(player)
	if player.dropdashcharged
	and not (player.cmd.buttons & BT_CUSTOM1)
	or player.dropdashcharged
	and P_CheckDeathPitCollide(player.mo, true)
		player.dropdashcharged = false
		player.mo.state = S_PLAY_JUMP
	end
	if player.dropdashcharged
	and leveltime%2 == 1
	and player.mo.state >= S_DROPDASH1
		local ghost = P_SpawnGhostMobj(player.mo)
		ghost.colorized = true
		ghost.blendmode = AST_ADD
		ghost.renderflags = ghost.renderflags|FF_FULLBRIGHT
		ghost.fuse = 4
		ghost.frame = TR_TRANS40
	end
	if player.dropdashcharged
	and (player.powers[pw_justsprung] or player.mo.eflags & MFE_SPRUNG)
		player.dropdashcharged = false
	end
	if player.dropdashcharged
		player.mo.spritexscale = FRACUNIT+FixedDiv(player.mo.momz/96,player.mo.scale)
		player.mo.spriteyscale = FRACUNIT-FixedDiv(player.mo.momz/96,player.mo.scale)
	elseif not player.dropdashcharged
	and not (player.powers[pw_carry] == CR_NIGHTSMODE)
		player.mo.spritexscale = FRACUNIT
		player.mo.spriteyscale = FRACUNIT
	end
	if player.dropdashcharged
	and (P_IsObjectOnGround(player.mo) or (player.mo.eflags & MFE_JUSTHITFLOOR))
	and not P_CheckDeathPitCollide(player.mo, true)
		player.dropdashcharged = false
		S_StartSound(player.mo, sfx_zoom)
		player.pflags = $|PF_SPINNING
		player.mo.state = S_PLAY_ROLL
		//the dust is from rebound momentum made by ninja sonic
		P_SpawnMobj(player.mo.x - 25*FRACUNIT, player.mo.y, player.mo.z, MT_DUST)
		P_SpawnMobj(player.mo.x + 25*FRACUNIT, player.mo.y, player.mo.z, MT_DUST)
		P_SpawnMobj(player.mo.x, player.mo.y + 25*FRACUNIT, player.mo.z, MT_DUST)
		P_SpawnMobj(player.mo.x - 20*FRACUNIT, player.mo.y - 20*FRACUNIT, player.mo.z, MT_DUST)
		P_SpawnMobj(player.mo.x + 20*FRACUNIT, player.mo.y - 20*FRACUNIT, player.mo.z, MT_DUST)
		P_SpawnMobj(player.mo.x - 20*FRACUNIT, player.mo.y + 20*FRACUNIT, player.mo.z, MT_DUST)
		P_SpawnMobj(player.mo.x + 20*FRACUNIT, player.mo.y + 20*FRACUNIT, player.mo.z, MT_DUST)
		if player.speed < player.normalspeed
		and (player.cmd.buttons & BT_JUMP)
			P_InstaThrust(player.mo, player.mo.angle, 60*FRACUNIT)
		else
			P_Thrust(player.mo, player.mo.angle, 22*FRACUNIT)
		end
	end
end)
	
addHook("PlayerThink", function(p)
	if p.mo.skin == "sonic"
	and (p.pflags & PF_SPINNING)
	and (p.pflags & PF_JUMPED)
		p.pflags = $ & ~PF_SPINNING
	end
end)