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

        if player.firegreetspam == nil then
            player.firegreetspam = 0
        end
        
        if (player.cmd.buttons & BT_CUSTOM1) ~= 0
        and player.firegunspam == 0 
        and player.firegun == 0 then
            local missile = P_SpawnPlayerMissile(player.mo, MT_FIRE_BULLET)
            if missile then
                missile.flags2 = missile.flags2 & ~MF2_INVERTAIMABLE
            end
            player.mo.state = S_PLAY_FIRE
            player.firegunspam = 1
        end
        
        if (player.cmd.buttons & BT_CUSTOM1) ~= 0
        and player.firegunspam == 0 
        and player.firegun == 1 then
            local missile = P_SpawnPlayerMissile(player.mo, MT_FIRE_BULLET)
            if missile then
                missile.flags2 = missile.flags2 & ~MF2_INVERTAIMABLE
            end
            player.mo.state = S_PLAY_FIRE
        end
        
        if (player.cmd.buttons & BT_CUSTOM1) == 0
        and player.firegunspam == 1 then
            player.firegunspam = 0
        end
            
        if player.firegunspam == nil then
            player.firegunspam = 0
        end
        
        if player.firegun == nil then
            player.firegun = 0
        end
    end
end)