addHook("ThinkFrame", function()
    for player in players.iterate do
        if not player.mo or player.mo.skin ~= "megaman" then
            continue
        end

        if player.bombgreetspam == nil then
            player.bombgreetspam = 0
        end
        
        if (player.cmd.buttons & BT_CUSTOM3) ~= 0
        and player.bombgunspam == 0 
        and player.bombgun == 0 then
            local missile = P_SpawnPlayerMissile(player.mo, MT_FBOMB)
            if missile then
                missile.flags2 = missile.flags2 & ~MF2_INVERTAIMABLE
            end
            player.mo.state = S_PLAY_FIRE
            player.bombgunspam = 1
        end
        
        if (player.cmd.buttons & BT_CUSTOM3) ~= 0
        and player.bombgunspam == 0 
        and player.bombgun == 1 then
            local missile = P_SpawnPlayerMissile(player.mo, MT_FBOMB)
            if missile then
                missile.flags2 = missile.flags2 & ~MF2_INVERTAIMABLE
            end
            player.mo.state = S_PLAY_FIRE
        end
        
        if (player.cmd.buttons & BT_CUSTOM3) == 0
        and player.bombgunspam == 1 then
            player.bombgunspam = 0
        end
            
        if player.bombgunspam == nil then
            player.bombgunspam = 0
        end
        
        if player.bombgun == nil then
            player.bombgun = 0
        end
    end
end)