• 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.

Make A ForGroup Stop

Status
Not open for further replies.
Level 4
Joined
Mar 20, 2014
Messages
67
Can you make a ForGroup stop if the condition is returned true? if not what would be a good replacement because I can't think of a better way.
- Zach
Also on an unrelated note, is there a way to find 1 random unit of a type owned by a player?
 
Last edited:
Level 13
Joined
Mar 24, 2013
Messages
1,105
First of group

And on the unrelated note
Pick all units owned by player then enumerate through them all until you find the ones you want then add them to another group and use the random unit from x unit group func
 
Level 4
Joined
Mar 20, 2014
Messages
67
So now way to just pick a random unit type? And I want it to stop if the condition is true, first of group will just pick the first unit in the group repetitively. If it's false I want it to keep going.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Just use an other data structure such as a linked list or a stack.

If you don't need to keep the group during time (only one loop) AND there is absolutely no way that you have ghost units inside (units removed of the game but from the group), then you can use FirstOfGroup with GroupRemoveUnit and exitwhen when FirstOfGroup returns null.
 
Level 4
Joined
Mar 20, 2014
Messages
67
I'm not quite sure I'm following. If I am to do that I need to keep track of the units. I can't just remove them from the group.

What I need to do is skip a unit if it has a condition false, otherwise I want to just do that unit. I understand the FirstOfGroup function but the thing is the units will be deleted that are at the places.

So a unit that returns false in the beginning will return true forty seconds later. If that makes any sense.

I essentially need to skip the Army Camp's (the unit) that returns false, then when one of the (max four) army camp's return true JUST use that one army camp and leave the rest out.

How would I use it in this group for instance?
JASS:
scope ArmyLocust
globals
    private unit acu
endglobals

function ArmyLocustCond takes nothing returns boolean
local integer i = GetUnitTypeId(GetTrainedUnit())
    if ( i == 'e000' ) then
        return true
    endif
    if ( i == 'h008' ) then
        return true
    endif
    return false
endfunction

function ArmyUnitCallback takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer i = LoadInteger(MUAC, 0, GetHandleId(u))
    local integer p = GetPlayerId(GetOwningPlayer(u))
    if ( i < MaxArmyCampUnits) then 
        call BJDebugMsg(I2S(i))
        set acu = u
        set i = i + 1
        call SaveInteger(MUAC, 0, GetHandleId(u), i)
        call SaveUnitHandle(MUAC, 2, GetHandleId(GetTrainedUnit()), u)
        set u = null
    endif
    set u = null
endfunction

function ArmyLocustAct takes nothing returns nothing
local unit u = GetTrainedUnit()
local integer p = GetPlayerId(GetOwningPlayer(u))
local integer h = GetHandleId(u)
local real x
local real y
    if (LoadUnitHandle(MUAC, 2, h) == null) then
        call ForGroup(ArmyCamps, function ArmyUnitCallback)
    endif
    set x = GetUnitX(acu) + GetRandomReal(50, 300) * Cos(GetRandomDirectionDeg() * bj_DEGTORAD)
    set y = GetUnitY(acu) + GetRandomReal(50, 300) * Sin(GetRandomDirectionDeg() * bj_DEGTORAD)
    call SaveUnitHandle(MUAC, 2, h, acu)
    call GroupAddUnit(ArmyUnits, u)
    call UnitAddAbility(u, 'Abun')
    call UnitAddAbility(u, 'Aloc')
    call IssuePointOrder(u, "move", x, y)
    set u = null
    set acu = null
endfunction

//===========================================================================
function InitTrig_Army_Locust takes nothing returns nothing
    set gg_trg_Army_Locust = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Army_Locust, EVENT_PLAYER_UNIT_TRAIN_FINISH )
    call TriggerAddCondition( gg_trg_Army_Locust, Condition( function ArmyLocustCond ) )
    call TriggerAddAction( gg_trg_Army_Locust, function ArmyLocustAct )
endfunction
endscope
The units need to be readded.
 
Last edited:
Status
Not open for further replies.
Top