FAForever Forums
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login
    The current pre-release of the client ("pioneer" in the version) is only compatible to itself. So you can only play with other testers. Please be aware!

    Quick AI brain question

    Scheduled Pinned Locked Moved Modding & Tools
    7 Posts 3 Posters 330 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 Offline
      Resin_Smoker
      last edited by

      Q Would it be possible to call something like this from a unit script?

      local myBrain = self:GetAIBrain():GetCurrentEnemy() or false
      

      Been digging around for another way to get a units current target from within the unit sim, without having to ask the weapon. Which I've often found the results from the weapon can be questionable or unreliable. Leading to sim errors in some specific situations.

      I'm also looking into this...

      local myFocus = self:GetFocusUnit() or false
      

      To see what is given in comparison to the units weapon.

      Cheers!

      -Resin

      Kykhu Oss https://youtu.be/JUgyGTgeZb8
      Unit Thrower https://youtu.be/iV8YBXVxxeI
      Beam Tentacle https://youtu.be/le5SNwHvC4c
      Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
      Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

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

        Just to make sure I’ve understood, you want to know what enemy unit a unit (self) is currently trying to fire at? And you’d be ok with sim mod commands to achieve this (ie you’re not asking for purposes of a UI mod)? If so, then I think it’s possible to cycle through the unit’s weapons and return the unit they’re currently targeting, as you mention; for further away targets (where an attack order is queued up but the target isnt in range of the weapon) I think there are also some functions that can help.

        I’d need to check my code to refresh my memory on them (GetFocusUnit was one if them I think) which I can’t do at the moment so if no-one’s able to respond in the meantime fee free to ping me later

        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 Offline
          Resin_Smoker @maudlin27
          last edited by

          @maudlin27

          Previously I've used...

          local myTarget = self:GetWeaponByLabel('Dummy'):GetCurrentTarget() or false
          

          While this does work, it can at times be unreliable as the weapon states can vary based upon its a large number of factors. (Units can have more than one as well) So while yes, I've managed to make it work, it would be better to have the means to pull from the units brain. To see just what the unit is focusing on at that given moment.

          Also... PlayUnitSound Is there a list of all the sounds available within FA? Been looking through the GitHub and thus far nothing stands out as "sounds".

          Kykhu Oss https://youtu.be/JUgyGTgeZb8
          Unit Thrower https://youtu.be/iV8YBXVxxeI
          Beam Tentacle https://youtu.be/le5SNwHvC4c
          Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
          Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

          maudlin27M 1 Reply Last reply Reply Quote 0
          • R Offline
            Resin_Smoker
            last edited by

            Here's the unit I'm working on: https://youtu.be/9ZsWrh2TsR4

            Kykhu Oss https://youtu.be/JUgyGTgeZb8
            Unit Thrower https://youtu.be/iV8YBXVxxeI
            Beam Tentacle https://youtu.be/le5SNwHvC4c
            Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
            Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

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

              nil is always false, so putting or false is excessive.

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

              R 1 Reply Last reply Reply Quote 0
              • R Offline
                Resin_Smoker @Ctrl-K
                last edited by

                @ctrl-k

                Granted, though at the time It made sense.

                Kykhu Oss https://youtu.be/JUgyGTgeZb8
                Unit Thrower https://youtu.be/iV8YBXVxxeI
                Beam Tentacle https://youtu.be/le5SNwHvC4c
                Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
                Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

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

                  @resin_smoker The ones I'm aware of for weapons are
                  :GetCurrentTarget() - returns the unit, if there is a unit being targeted
                  :GetCurrentTargetPos() - returns the target, i.e. for ground attack targets (I've not tested to see all the cases in which this triggers, e.g. if it will return a value for a unit target's position)
                  :WeaponHasTarget() - I've not used this one myself but I'd noted it down for reference when I was looking at how to get weapon target information

                  with weapons being cycled through with something like:

                  for iWeapon, oWeapon in oUnit.WeaponInstances do
                      if oWeapon.GetCurrentTarget then
                          local oCurTarget = oWeapon:GetCurrentTarget()
                          if oCurTarget then
                  		‘Have a target for the weapon
                  	 end
                      end
                  end
                  

                  You can also use the Navigator object to get the current target position of a unit, e.g.:

                  oUnit:GetNavigator():GetCurrentTargetPos() - This isn’t just a move order target – e.g. if the unit is building something, it returns the target of that building
                  I found it unreliable, and made a note when I tested that with attack-move orders although I’ve not tested it extensively to confirm, it appeared that giving an attack-move order to a unit that caused that unit to then stop and attack a target, would result in the navigator position being that unit’s position.

                  There's also a :GetGoalPos() function (which I think is based off the navigator as well)

                  You can also use oUnit:GetFocusUnit() (which works e.g. in the case of a building a unit, I've not checked if it also works in the case of an attack order)

                  Another one is oUnit:GetGuardedUnit()
                  I've not tested this one but presume it works with the guard order.

                  My rough notes on these and other commands are in section 5 of the AI development guide (linked to from the FAF wiki https://wiki.faforever.com/en/Development/AI/AI-Modding) although I don't think they'll add much more than what's here, other than you can look at e.g. unit.lua in the FAF Git as various comments have been added documenting functions available for units (and similarly with other files) which might provide further alternatives.

                  You could also look into oUnit:GetCommandQueue() and analysing this - there might be documentation on this in the FAF repo as from memory some of the devs were able to figure out how to interpret the results of this (but it's not something I needed to look into beyond checking if a unit's command queue was empty as for my AI I track the orders given to each AI unit anyway which I rely on)

                  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

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