freeslot("S_PLAY_GJUP", "S_PLAY_GFLL", "SPR2_CRAK", "SFX_SCRK")

states[S_PLAY_GJUP] = {SPR_PLAY, SPR2_CRAK|FF_ANIMATE, 1, nil, 0, 0, S_PLAY_GJUP}
states[S_PLAY_GFLL] = {SPR_PLAY, SPR2_ROLL|FF_ANIMATE, 2, nil, 0, 0, S_PLAY_GFLL}

//Borrowed Miguel's core of the hard drop
-- specify the stall duration and downward speed
local stall_duration = 90 -- 3.5 second 
local cracker_up = -1 * FRACUNIT
local PF_FLY = 0x4000

addHook("ThinkFrame", function()
for player in players.iterate do
-- initialize custom variables
player.stalling = player.stalling or false
player.stalltimer = player.stalltimer 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 == "superguide" 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 custom1_pressed = (player.cmd.buttons & BT_CUSTOM1) ~= 0

if custom1_pressed and jumped and not player.stalling and not player.hasStalled then
player.mo.state = S_PLAY_GJUP
player.stalling = true
player.stalltimer = stall_duration
player.hasStalled = true

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

if player.stalling then
player.mo.momz = 0 -- stall vertical movement
player.pflags = $ | PF_FLY

player.stalltimer = player.stalltimer - 1

if player.stalltimer <= 0 then
player.stalling = false
player.mo.momz = cracker_up -- throw player downward
player.pflags = $ & ~PF_FLY -- resume normal physics

-- play the end sound effect when stalling ends
player.mo.state = S_PLAY_GFLL
end	
end

if onground then
player.stalling = false -- reset the stalling flag when the player touches down again
player.stalltimer = 0
player.hasStalled = false -- allow another stall after touching the ground
end
end
end
end)