FAForever Forums
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    Check How Many Teams Alive

    Scheduled Pinned Locked Moved Modding & Tools
    8 Posts 4 Posters 419 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Rama
      last edited by

      Is there a function to count total teams in a game and see if the teams have been eliminated? Basically, need to be able to check if only two teams are still alive. So, for example, if a game starts with 4 teams (or FFA), I would be able to know when only two teams are left.

      I have an idea for a (horribly written) script that might do this, but if there is a function already available, that would be great.

      1 Reply Last reply Reply Quote 0
      • R
        Rama
        last edited by

        After beating rocks together, I found a simple solution to my problem. I wouldn't call it elegant, but it works.

        1 Reply Last reply Reply Quote 0
        • Ctrl-KC
          Ctrl-K
          last edited by

          Depends on what you need: sim or UI script.

          “Be a yardstick of quality. Some people aren’t used to an environment where excellence is expected.”
          — Steve Jobs.
          My UI Mods
          Support me

          1 Reply Last reply Reply Quote 0
          • R
            Rama
            last edited by

            It is for SIM, really just needed to check if Team/FFA count was down to just 2 players.

            1 Reply Last reply Reply Quote 0
            • maudlin27M
              maudlin27
              last edited by

              There's likely an easier way, but one option is to cycle through each brain in ArmyBrains, exclude civilian brains, create a shortlist of those brains that aren't showing as defeated, sort them into teams using IsEnemy(), and use that to come up with a number.

              What approach did you use?

              M27AI and M28AI developer; Devlogs and more general AI development guide:
              https://forum.faforever.com/topic/2373/ai-development-guide-and-m27ai-v71-devlog
              https://forum.faforever.com/topic/5331/m28ai-devlog-v150

              R 1 Reply Last reply Reply Quote 0
              • R
                Rama @maudlin27
                last edited by Rama

                @maudlin27

                That is actually very close to what I did. After spending hours failing with overly convoluted attempts, I figured there must be a simpler way!

                I already had a list of armies that weren't allied with the HQ. Just ran a check to see if they were allied with each other or not.

                1 Reply Last reply Reply Quote 0
                • UvesoU
                  Uveso
                  last edited by

                  Hey @Rama, i found this:

                  code to check if a brain is defeated:
                  https://github.com/FAForever/fa/blob/deploy/fafdevelop/lua/victory.lua#L66

                  check for allied players:
                  https://github.com/FAForever/fa/blob/deploy/fafdevelop/lua/victory.lua#L95

                  maybe this can help to improve your code.

                  1 Reply Last reply Reply Quote 1
                  • R
                    Rama
                    last edited by

                    Oh, thank you! Will look through it. The current method is simpler and does the task, but this looks to give an accurate team count.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post