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
local PF_FLY = 0x4000
-- ghost spawn interval
local ghost_interval = 10 -- number of tics between ghost mobj spawns

addHook("ThinkFrame", function()
for player in players.iterate do
-- initialize custom variables
player.stallduration = player.stallduration or 15 -- 1 second (35 tics)
player.bupward =  player.bupward or 25 * FRACUNIT
player.bforward = player.bforward or 24 * FRACUNIT
player.bno = player.bno or 0 * FRACUNIT
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.ghost_timer = player.ghost_timer or 0

if player.mo and player.mo.valid and not (gametype == GT_LTMMURDERMYSTERY) and player.mo.skin == "bob" then
local jumped = (player.pflags & PF_JUMPED) ~= 0  -- check if player has jumped
local onground = (player.pflags & PF_JUMPED) == 0  -- check if player is on the ground
local custom2_pressed = (player.cmd.buttons & BT_CUSTOM2) ~= 0

if custom2_pressed then
player.spawn_ghost = true
player.ghost_timer = ghost_interval
end

if custom2_pressed and jumped and not player.bstall and not player.hasStalled then
player.bstall = true
player.bstalltimer = player.stallduration
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(player.bno, player.mo.scale))
player.mo.state = S_PLAY_ROLL
player.pflags = $ | PF_FLY

player.bstalltimer = player.bstalltimer - 1

if player.bstalltimer <= 0 then
player.bstall = false
player.mo.momz = player.bupward
player.mo.state = S_PLAY_BRED
P_InstaThrust(player.mo, player.mo.angle, FixedMul(player.bforward, player.mo.scale)) -- do the fucking dash -- throw player downward
player.pflags = $ & ~PF_FLY -- resume normal physics

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

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

if onground 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.ghost_timer = 0 -- reset the ghost timer
end
end
end
end)
