• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[AI] Trying to Make Function That Outputs Specific Units

Level 21
Joined
Mar 16, 2008
Messages
973
Trying to make a function that targets 4 preplaced Castles 'hcas' on map in AI script. Would be easy if we could access udg variables but we can't for AI. Do the functions below look OK? for some reason they don't seem to work. But I haven't used debug codes yet. I'm just wondering if anyone more familiar with JASS notices any blatant problems.

JASS:
//===========================================================================
// Picks a player that isn't the AI and is playing (has gold)
//===========================================================================
function Pick_Tar takes nothing returns player
    local player array p
    local integer array_count = 0
    local integer i
    if (gCond_Has_Gold_Red) and (ai_player !=Player(0)) then
        set array_count = array_count + 1
        set p[array_count] = Player(0)
    endif
    if (gCond_Has_Gold_Blu) and (ai_player !=Player(1)) then
        set array_count = array_count + 1
        set p[array_count] = Player(1)
    endif
    if (gCond_Has_Gold_Tea) and (ai_player !=Player(2)) then
        set array_count = array_count + 1
        set p[array_count] = Player(2)
    endif
    if (gCond_Has_Gold_Pur) and (ai_player !=Player(3)) then
        set array_count = array_count + 1
        set p[array_count] = Player(3)
    endif
    set i = GetRandomInt(1, array_count)
    return p[i]
endfunction

//===========================================================================
// Finds a unit of type
//===========================================================================
function FindUnitOfType takes player p returns unit
    local group g
    local unit u
    local unit found
    call GroupEnumUnitsOfPlayer(g, p, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null or found != null
        call GroupRemoveUnit(g, u)
        if GetUnitTypeId(u) == 'hcas' then
            set found = u
        endif
    endloop
    return found
endfunction
 
Top