• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[AI] Choosing AI Target by Finding Closeby targets using GroupEnum

Status
Not open for further replies.
Level 2
Joined
Apr 17, 2017
Messages
14
I'm aware that most functions wont work in an AI script.

My coding skills suck

This is for a risk based map. I want my AI to go from base to base to expand.

I know I can pass coordinates to it via jass/gui, but I want to use the build into the JASS Script to find a close target and attack move to it.

I read that you can use group enum, can you give me an example?

JASS:
set city = GetEnemyExpansion()
    if city == null then
        call StartGetEnemyBase()
        loop
            exitwhen not WaitGetEnemyBase()
            call SuicideSleep(1)
        endloop
        set city = GetEnemyBase()
    endif

    call SetAllianceTarget(city)
    call FormGroup(3,true)
    call AttackMoveKillA(city)


Doesnt do much like what I want it to, but if I could make the city an actual nearby unit, as opposed to whatever the HELL the AI determines to be an "Expansion"

How can I use groupenum to find nearby unit?
 
Level 12
Joined
Jun 15, 2016
Messages
472
If you want to build expansion, you need to prompt it when you have, say, less than 2 mines, then call a function like this one:

JASS:
function StartExpansion takes integer qty, integer hall returns boolean
    local integer count
    local integer town
    local unit    peon
    local integer gold_cost

    set count = TownCount(hall)
    if count >= qty then
        return true
    endif

    set town = GetNextExpansion()
    if town == -1 then
        return true
    endif

    set take_exp = true

    set gold_cost = GetUnitGoldCost(hall)
    if gold_cost > total_gold then
        return false
    endif
    set total_gold = total_gold - gold_cost

    if GetExpansionFoe() != null then
        return true
    endif

    set peon = GetExpansionPeon()
    if peon != null then
        return SetExpansion(peon,hall)
    endif

    return true
endfunction

I generally suggest looking through the AI file for ideas: JASS Manual: API Browser - common.ai
 
Level 12
Joined
Jun 15, 2016
Messages
472
Well, the AI isn't too good at specifics, but there are a couple of things you can try: what you're looking for is this native ai function AttackMoveKill. The problem with this function is that unlike most functions in AI, this one actually needs a unit as a target, and not a unit id. There are a few other ai natives which return a unit such as GetExpansionFoe and some others. It seems to me none of those is particularly fitting for you, but you're welcome to try those.

If that doesn't work, you can try getting your target via commands to the AI, either by sending the AI a unit's handle id (something that I've yet to try) or by choosing a target with triggers and sending it's coordinates periodically to the AI (then you can attack it with AttackMoveXY).
 
Level 2
Joined
Apr 17, 2017
Messages
14
Youve done some great work on AI, nowow. Are numbers the only things I can pass to them? Also, is

AI - Send Player 1 (Red) the AI Command (1, 11)

The first number dictating the command number?

Can I next send a command of
AI - Send Player 1 (Red) the AI Command (1, 14)
or is the format for ANY second command
AI - Send Player 1 (Red) the AI Command (2, xx)
and third being
AI - Send Player 1 (Red) the AI Command (3, xx) etc


Does that dictate the command number or is it just another data point for our own internal use?
Once I know that I should be able to pass coordinates determined outside the AI
 
Level 12
Joined
Jun 15, 2016
Messages
472
Yes, you can pass only number, and yes the first number is the command number. If you're using multiple commands, the first number should state what command is sent, and the second should give additional data. For example, if you want the AI to guard two points in the map, a primary point and a secondary point, you can create your commend processing function like so:

JASS:
function ProcessCommand takes nothing returns nothing
local integer command = GetLastCommand()
local integer data = GetLastData()

if command == 11 then //get primary point x
    set PrimePointX = data
elseif command == 12 then //get primary point y
    set PrimePointY = data
elseif command == 21 then //get secondary point x
    set SecPointX = data
elseif command == 22 then //get secondary point y
    set SecPointY = data

call PopLastCommand() //clears last command received
endfunction

Note that if you're using commands only to fill one function, for example only using commands to receive the primary point coordinates, the you can use just one command where the command number is the x coordinate and the data is the y coordinate.
 
Status
Not open for further replies.
Top