freeslot("MT_PEBILL_BOMB", "S_PEBILL_BOMB1", "S_PEBILL_BOMB2")

mobjinfo[MT_PEBILL_BOMB] = {
	doomednum = -1,
	spawnstate = S_PEBILL_BOMB1,
	spawnhealth = 1,
	seesound = sfx_s3k51,
	deathstate = S_XPLD_FLICKY,
	deathsound = sfx_pop,
	speed = 20*FRACUNIT,
	radius = 24*FRACUNIT,
	height = 48*FRACUNIT,
	mass = 100,
	damage = 0,
	flags = MF_NOBLOCKMAP|MF_MISSILE,
}

states[S_PEBILL_BOMB1] = {
	sprite = SPR_POSS,
	frame = A,
	tics = 1,
	action = A_GhostMe,
	var1 = 0,
	var2 = 0,
	nextstate = S_PEBILL_BOMB2
}

states[S_PEBILL_BOMB2] = {
	sprite = SPR_POSS,
	frame = A,
	tics = 1,
	action = A_GhostMe,
	var1 = 0,
	var2 = 0,
	nextstate = S_PEBILL_BOMB1
}

addHook("ThinkFrame", do
	for player in players.iterate
		if player.mo and player.mo.skin == "pebill_light"
			if not (player.mo.fire)
				player.mo.fire = 0
			end
			if not (player.powers[pw_carry] == CR_NIGHTSMODE) 
			and not (player.powers[pw_carry]) 
			and not (player.pflags & PF_STASIS) 
			and not (player.mo.tracer and player.mo.tracer.type == MT_TUBEWAYPOINT) 
		and not (player.mo.state == S_PLAY_SUPER_TRANS1)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS2)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS3)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS4)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS5)
	    and not (player.mo.state == S_PLAY_SUPER_TRANS6)
		and not (player.pflags & PF_FINISHED)
		and P_PlayerInPain(player) == false
		    and player.playerstate == PST_LIVE
			 and (player.cmd.buttons & BT_ATTACK)
		
			and player.mo.fire == 0
            player.mo.fire = 1
		       local flame = P_SpawnPlayerMissile(player.mo, MT_PEBILL_BOMB)
			end
			if not (player.cmd.buttons & BT_ATTACK)
				player.mo.fire = 0
			end
		end
	end
end)