	if srb2p return end


freeslot("sfx_dsdash", "sfx_dsbeep")

addHook("PlayerThink", function(player) // set up for variables
	if player.mo.skin == "doomguy"
		if player.DashStateTimer == nil
		player.DashStateTimer = 0
		end
		if player.DashAttackTimer == nil
		player.DashAttackTimer = 0
		end
		if player.DashCounter == nil
		player.DashCounter = 2
		end
		if player.DashBeeped == nil
		player.DashBeeped = 0
		end
	end
end)

addHook("PlayerThink", function(player) // timer for damaging enemies
	if(player.mo.skin == "doomguy")
	and player.DashAttackTimer >= 0
	player.DashAttackTimer = $1 - 1
	end
end)

addHook("PlayerThink", function(player) // timer for recharge
	if(player.mo.skin == "doomguy")
	and player.DashStateTimer >= 0
	player.DashStateTimer = $1 - 1
	end
end)

addHook("PlayerThink", function(player) // refills if recharged
	if player.DashBeeped == 0
	and player.mo.skin == "doomguy"
	and player.DashStateTimer <= 0
	player.DashCounter = 2
	S_StartSound(player.mo, sfx_dsbeep)
	player.DashBeeped = 1
	end
end)

local function hud_dash(v,player) // the hud
if not(player.mo and player.mo.valid and player.mo.skin == "doomguy")
	return
	end
	if player.DashCounter == 2 then
		v.drawScaled(0,0,FRACUNIT/2,v.cachePatch("DSHICON1"),V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	elseif player.DashCounter == 1 then
		v.drawScaled(0,0,FRACUNIT/2,v.cachePatch("DSHICON2"),V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	elseif player.DashCounter <= 0 then
		v.drawScaled(0,0,FRACUNIT/2,v.cachePatch("DSHICON3"),V_SNAPTORIGHT|V_SNAPTOBOTTOM|V_PERPLAYER)
	end
end

hud.add(hud_dash)

local function DashAttack(player) // the actual dash
	if player.DashCounter >= 1
	and player.mo.skin == "doomguy"
	and not (player.exiting)
	if (P_IsObjectOnGround(player.mo) == true) // are you on the ground
		player.DashAttackTimer = 5
		player.DashStateTimer = 0
		player.DashCounter = $1 - 1
		player.DashBeeped = 0
		player.DashStateTimer = 35
		player.mo.state = S_PLAY_DASH
		P_InstaThrust(player.mo, player.mo.angle, 60*FRACUNIT) // friction makes it so you need to launch at a higher speed on the ground
		P_SpawnGhostMobj(player.mo)
		S_StartSound(player.mo, sfx_dsdash)
		player.mo.state = S_PLAY_STND
	else
		player.DashAttackTimer = 5
		player.DashStateTimer = 0
		player.DashCounter = $1 - 1
		player.DashBeeped = 0
		player.DashStateTimer = 35
		player.mo.state = S_PLAY_DASH
		P_InstaThrust(player.mo, player.mo.angle, 50*FRACUNIT)
		P_SetObjectMomZ(player.mo, 0*FRACUNIT)
		P_SpawnGhostMobj(player.mo)
		S_StartSound(player.mo, sfx_dsdash)
		player.mo.state = S_PLAY_FALL
		end
	end
end


local function DashPress(player) // button presses instead of holding it
	if player.mo.skin ~= "doomguy" then
		return
	end

	if (player.cmd.buttons & BT_CUSTOM1)
	and not (player.pflags & PF_FULLSTASIS)
	and not (player.pflags & PF_STASIS)
	and not (player.mo.state == S_PLAY_PAIN)
	and not (player.mo.state == S_PLAY_DEAD)
		if not player.pressedcustom1
			DashAttack(player)
		end

		player.pressedcustom1 = true
	else -- We are not pressing Custom 1 this frame
		player.pressedcustom1 = false -- Set pressedcustom1 to false
	end
end

addHook("PlayerThink", DashPress)

addHook("PlayerThink", function(player) // makes you damage enemies while dashing
	if(player.mo.skin == "doomguy")
	if player.DashAttackTimer >= 1
	player.pflags = $|PF_SPINNING
	P_SpawnGhostMobj(player.mo)
	player.charflags = $|SF_CANBUSTWALLS
	elseif not (player.pflags & PF_FULLSTASIS)
	and not (player.pflags & PF_STASIS)
	player.pflags = ($1 & !PF_SPINNING)
	player.charflags = ($1 & !SF_CANBUSTWALLS)
	if (player.mo.state == S_PLAY_ROLL)
	player.mo.state = S_PLAY_STND
			end
		end
	end
end)

addHook("PlayerThink", function(player) // halts vertical momentum when not jumping
	if(player.mo.skin == "doomguy")
	and player.DashAttackTimer >= 1
	and not (player.pflags & PF_STARTJUMP)
	P_SetObjectMomZ(player.mo, 0*FRACUNIT)
	end
end)

sfxinfo[sfx_dsdash].caption = "Dash"

sfxinfo[sfx_dsbeep].caption = "Dash Recharged"
