freeslot("S_PLAY_BWEE", "sfx_bchr", "sfx_bwee", "S_PLAY_BRED", "SPR2_ASCD")

states[S_PLAY_BWEE] = {SPR_PLAY, SPR2_ASCD|FF_ANIMATE, 1, nil, 0, 0, S_PLAY_BWEE}
states[S_PLAY_BRED] = {SPR_PLAY, SPR2_ROLL|FF_ANIMATE, 1, nil, 0, 0, S_PLAY_BRED}

//This is for the Hard Drop
-- specify the stall duration and downward speed
-- ghost spawn interval
addHook("ThinkFrame", function()
for player in players.iterate do
-- initialize custom variables -- 1 second (35 tics)
player.bstall = player.bstall or false
player.bstalltimer = player.bstalltimer or 0
player.hasStalled = player.hasStalled or false
player.spawn_ghost = player.spawn_ghost or false
player.bghost_timer = player.bghost_timer or 0
player.bkickpowup = player.bkickpowup or 0
player.bkickpowfront = player.bkickpowfront or 0
player.bkickanim = player.bkickanim or 0
player.bkickcharge = player.bkickcharge or 0

if not player.powers[pw_super] then
player.bkickpowup = 26 * FRACUNIT
player.bkickcharge = 18
player.bkickanim = S_PLAY_BWEE
player.bkickpowfront = 25 * FRACUNIT
else
player.bkickpowup = 35 * FRACUNIT
player.bkickcharge = 12
player.bkickanim = S_PLAY_SPRING
player.bkickpowfront = 40 * FRACUNIT
end

if player.mo and player.mo.valid and not (gametype == GT_LTMMURDERMYSTERY) and player.mo.skin == "bob" then
if (player.cmd.buttons & BT_CUSTOM2) and (player.pflags & PF_JUMPED) and not player.bstall and not player.hasStalled then
player.bstall = true
player.spawn_ghost = true
player.bghost_timer = 10
player.bstalltimer = player.bkickcharge
player.hasStalled = true

-- play the start sound effect for stalling
S_StartSound(player.mo, sfx_bwee)
end

if player.bstall then
player.mo.momz = 0 -- stall vertical movement
P_InstaThrust(player.mo, player.mo.angle, FixedMul(0 * FRACUNIT, player.mo.scale))
player.mo.state = S_PLAY_ROLL

player.bstalltimer = player.bstalltimer - 1

if player.bstalltimer <= 0 then
player.bstall = false
P_SetObjectMomZ(player.mo, player.bkickpowup)
player.mo.state = S_PLAY_BRED
P_InstaThrust(player.mo, player.mo.angle, FixedMul(player.bkickpowfront, player.mo.scale)) -- do the fucking dash -- throw player downward

-- play the end sound effect when stalling ends
S_StartSound(player.mo, sfx_bchr)
player.mo.state = player.bkickanim
end	
end

if player.mo.momz == 0 * FRACUNIT and player.mo.state == S_PLAY_BWEE then
player.mo.state = S_PLAY_FALL
player.spawn_ghost = false
end

-- spawn ghost mobjs while custom 1 is pressed
if player.spawn_ghost then
player.bghost_timer = player.bghost_timer - 1
if player.bghost_timer <= 0 then
P_SpawnGhostMobj(player.mo)
player.bghost_timer = 10
end
end

if P_IsObjectOnGround(player.mo) then
player.bstall = false -- reset the stalling flag when the player touches down again
player.bstalltimer = 0
player.hasStalled = false -- allow another stall after touching the ground

player.spawn_ghost = false -- stop spawning ghost mobjs
player.bghost_timer = 0 -- reset the ghost timer
end
end
end
end)