if srb2p return end

freeslot("MT_SHOTGUN", "S_MHICON", "SPR_MHPC", "sfx_dshtgn", "sfx_dsssg", "sfx_shlbnc")

mobjinfo[MT_SHOTGUN] = {
	dispoffset = 1,
	flags = MF_NOGRAVITY|MF_NOCLIP|MF_NOBLOCKMAP|MF_NOCLIPHEIGHT
}

addHook("PlayerThink", function(player) // Shotgun variable setup
	if player.mo.skin == "doomguy"
		if player.ShotgunFired == nil
		player.ShotgunFired = 0
		end
	end
end)

addHook("PlayerThink", function(player) // targeting system
	if player.mo.skin == "doomguy"
		player.target = P_LookForEnemies(player, false, true)
		player.charability2 = CA2_NONE
		if player.target
		and player.target.valid
		and not (player.exiting)
		and player.ShotgunFired <= 0
			P_SpawnLockOn(player, player.target, S_MHICON)
			player.TargetDirection = R_PointToAngle2(player.mo.x, player.mo.y, player.target.x, player.target.y)// for the shotgun
			player.TargetDistance = R_PointToDist2(player.mo.x, player.mo.y, player.target.x, player.target.y)// for the shotgun
		end
	end	
end)

addHook("PlayerThink", function(player) // Shotgun animation timer
	if player.mo.skin == "doomguy"
	and player.ShotgunFired >= 1 then
	player.ShotgunFired = $1 - 1
	end
end)

addHook("PlayerThink", function(player) // stops Shotgun animation
	if player.mo.skin == "doomguy"
	and player.ShotgunFired <= 17
	and player.mo.state == S_PLAY_DFRE
	player.mo.state = S_PLAY_STND
	end
end)

addHook("ThinkFrame", function() // Shotgun button press
for player in players.iterate do
	if player.mo.skin ~= "doomguy" then
		continue
	end
		
	if not (player.cmd.buttons & BT_CUSTOM1)
	and not (player.mo.state == S_PLAY_DFRE)
	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)
	and player.shotgunspam == 1 then
		player.shotgunspam = 0
	end

	if player.shotgunspam == nil then
		player.shotgunspam = 0
		end
	end
end)

addHook("PlayerThink", function(player) // Fire shotgun
	if player.mo.skin == "doomguy"
	and player.PrimaryWeaponName == "Shotgun"
	and (player.cmd.buttons & BT_CUSTOM1)
	and player.shotgunspam == 0
	and player.ShotgunFired == 0
	and not (player.exiting)
		player.ShotgunFired = 35
		player.shotgunspam = 1
		S_StartSoundAtVolume(player.mo, sfx_dshtgn, 50)
		player.mo.state = S_PLAY_DFRE
		P_SPMAngle(player.mo, MT_SHOTGUNSHELL, player.SlayerDirection-ANG210, 0)
		if player.target
		P_SpawnMissile(player.mo, player.target, MT_BULLETPUFF)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.TargetDirection-ANG1, 1) // homing isn't vertical
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.TargetDirection-ANG2, 1) // :(
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.TargetDirection-ANG2-ANG1, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.TargetDirection+ANG1, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.TargetDirection+ANG2, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.TargetDirection+ANG2+ANG1, 1)
		else
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.SlayerDirection, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.SlayerDirection-ANG1, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.SlayerDirection-ANG2, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.SlayerDirection-ANG2-ANG1, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.SlayerDirection+ANG1, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.SlayerDirection+ANG2, 1)
		P_SPMAngle(player.mo, MT_BULLETPUFF, player.SlayerDirection+ANG2+ANG1, 1)
		end
	end
end)

states[S_MHICON] = {SPR_MHPC,A|FF_FULLBRIGHT,2,nil,0,0,S_NULL}

sfxinfo[sfx_dshtgn].caption = "Fire Shotgun"

sfxinfo[sfx_dsssg].caption = "Fire Shotgun"

sfxinfo[sfx_shlbnc].caption = "Shell Bounce"