Locust Swarm doesn't register locusts owned by player...?

Rinpun

Ex TH Member
Reaction score
105
Alright, for some spells for my WotU map, I'm running into an issue.

To put it simply, GroupEnumUnitsOfPlayer seems to be returning an empty group. Why?

Code:
function Trig_Release_Ships_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00H' or GetSpellAbilityId() == 'A00I'
endfunction

function is_fighter_ship takes nothing returns boolean
    return GetUnitTypeId(GetEnumUnit()) == 'u00F' or GetUnitTypeId(GetEnumUnit()) == 'u00G'
endfunction

function Until_Unrelease takes nothing returns nothing
    local timer until_unrelease = GetExpiredTimer()
    local player owner = Player(GetHandleInt(until_unrelease, "owner_id"))
    local group carrier_ships = CreateGroup()

    call GroupEnumUnitsOfPlayer(carrier_ships, owner, Condition(function is_fighter_ship))

    if (FirstOfGroup(carrier_ships) == null) then // the carrier_ships are not used.
        set udg_Carrier_Full[GetPlayerId(owner)] = CreateUnit(owner, 'u00H', 9999, 9999, 0)

        call DestroyTimer(until_unrelease)
        call FlushHandleLocals(until_unrelease) 
    endif

    call DestroyGroup(carrier_ships)
endfunction

function Trig_Release_Ships_Actions takes nothing returns nothing
    local timer until_unrelease = CreateTimer()
    local unit carrier = GetTriggerUnit()
    local player owner = GetOwningPlayer(carrier)

    call RemoveUnit(udg_Carrier_Full[GetPlayerId(owner)])

    call SetHandleInt(until_unrelease, "owner_id", GetPlayerId(owner))
    call TimerStart(until_unrelease, .05, true, function Until_Unrelease)

    set carrier = null
endfunction

//===========================================================================
function InitTrig_Release_Ships takes nothing returns nothing
    set gg_trg_Release_Ships = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Release_Ships, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Release_Ships, Condition( function Trig_Release_Ships_Conditions ) )
    call TriggerAddAction( gg_trg_Release_Ships, function Trig_Release_Ships_Actions )
endfunction
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
You should use GetFilterUnit and not GetEnumUnit in filters, talking about the function is_fighter_ship(). ^^

Also, the function Condition() creates a boolexpr wich must be destroyed with DestroyBoolExpr(), else it will leak.

Code:
        call DestroyTimer(until_unrelease)
        call FlushHandleLocals(until_unrelease)
You should change the order of these 2 lines.
 

Rinpun

Ex TH Member
Reaction score
105
Thanks! Now it works :)
 

Sim

Forum Administrator
Staff member
Reaction score
534
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top