• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[Solved] Just can't seem to get group enum of locusted units to work

Status
Not open for further replies.
Level 12
Joined
Nov 3, 2013
Messages
989
My issue is that both call DisplayTimedTextToForce( GetPlayersAll(), 4.00, "locusts in group: " + I2S(CountUnitsInGroup(locust_spawns_group[i])) ) and
JASS:
            set globalInt = 0
            call GroupEnumUnitsOfPlayer(locust_spawns_group[i], p, function CountLocustsInGroupEnum)
            call DisplayTimedTextToForce( GetPlayersAll(), 4.00, "locusts in group: " +  I2S(globalInt) )
show that there's 0 units in the unit group.

CountUnitsInGroup not working with locusted units is expected (since it uses ForGroup), but GroupEnumUnitsOfPlayer was supposed to still work, but it doesn't seem to.



Map Header
JASS:
globals
    integer globalInt
endglobals

function CountLocustsInGroupEnum takes nothing returns nothing
    set globalInt = globalInt + 1
endfunction


locust swarm is casted (spell effect start)
JASS:
globals
    //constants
    real locust_spawnInterval_inc = -0.20                            //how much the interval decreases per level
    real locust_spawnInterval_base = 1 - locust_spawnInterval_inc     //how often the locusts spawn
    integer locust_spawnMax_inc = 5
    integer locust_spawnMax_base = 10 - locust_spawnMax_inc     //number of locusts to spawn

    //variables
    integer locust_maxIndex = 0
    integer array locust_spawns_countMax
    unit array locust_source
    boolean array locust_bool_source    //locust_bool_source[n] -> next locust spawn belong to source[n]
    unit locust_tempUnit

endglobals


function Trig_locusts_cast_Conditions takes nothing returns boolean
    if ( GetSpellAbilityId() == 'A001' ) then
        return true
    endif
    return false
endfunction


function locusts_cast_boolexpr takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer uId = GetUnitTypeId(u)
    set u = null
    if uId == 'E001' then       //Level 1 morph
        return false
    endif
    /*if uId == 'E00J' then       //level 2 morph
        return false
    endif
    if uId == 'E00H' then       //level 3
        return false
    endif*/
    return true
endfunction

function locusts_cast_timerRepeat takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer timerId = GetHandleId(t)
    local integer i = 0
    local integer savedIndex = LoadInteger(udg_Hashtable, timerId, 0)       //identify which index the next locust belongs to
    local integer spawnCount = LoadInteger(udg_Hashtable, timerId, 1)       //how many timer repeats so far
    local integer spawnCountMax = LoadInteger(udg_Hashtable, timerId, 2)    //max number of repeats
    call DisplayTextToPlayer(Player(0), 0, 0, "locust " + I2S(spawnCount + 1) + " will spawn next")
    loop
        set i = i + 1
        exitwhen i > locust_maxIndex
        //call DisplayTextToPlayer(Player(0), 0, 0, "i = " + I2S(i))
        if savedIndex == i then
            set locust_bool_source[i] = true
            if spawnCount < spawnCountMax then
                call SaveInteger(udg_Hashtable, timerId, 1, spawnCount + 1)
                //call DisplayTextToPlayer(Player(0), 0, 0, "next locust that spawns belongs to locust_source[" + I2S(i) + "]")
            else
                //call DisplayTextToPlayer(Player(0), 0, 0, "next locust that spawns belongs to locust_source[" + I2S(i) + "] and it's the last one")
                call FlushChildHashtable(udg_Hashtable, timerId)
                call PauseTimer(t)
                call DestroyTimer(t)
            endif
        endif
    endloop
    set t = null
endfunction

function locusts_cast_timerEnd takes nothing returns nothing
    local timer t = GetExpiredTimer()
    call AddUnitAnimationProperties(locust_tempUnit, "alternate", false)
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
    set locust_tempUnit = null
endfunction

function Trig_locusts_cast_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local timer tRepeat = CreateTimer()
    local integer timerId = GetHandleId(tRepeat)
    local integer abilLevel

    set locust_maxIndex = locust_maxIndex + 1
    set locust_tempUnit = GetTriggerUnit()
    set abilLevel = GetUnitAbilityLevel(locust_tempUnit, 'A001')

    set locust_source[locust_maxIndex] = locust_tempUnit
    set locust_bool_source[locust_maxIndex] = true

    set locust_spawns_countMax[locust_maxIndex] = locust_spawnMax_base + locust_spawnMax_inc * abilLevel
    call DisplayTextToPlayer(Player(0), 0, 0, "max number of locusts = " + I2S(locust_spawns_countMax[locust_maxIndex]))

    call SaveInteger(udg_Hashtable, timerId, 0, locust_maxIndex)
    call SaveInteger(udg_Hashtable, timerId, 1, 1)
    call SaveInteger(udg_Hashtable, timerId, 2, locust_spawns_countMax[locust_maxIndex] - 1)

    call TimerStart(tRepeat, locust_spawnInterval_base + locust_spawnInterval_inc * abilLevel, true, function locusts_cast_timerRepeat)
    if (locusts_cast_boolexpr()) then
        call TimerStart(t, 0, false, function locusts_cast_timerEnd)
    else
        //call AddUnitAnimationProperties(locust_tempUnit, "alternate", true)
        set locust_tempUnit = null
    endif

    call DisplayTextToPlayer(Player(0), 0, 0, "locust 1 will spawn")
    set tRepeat = null
    set t = null
endfunction

//===========================================================================
function InitTrig_locusts_cast takes nothing returns nothing
    set gg_trg_locusts_cast = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_locusts_cast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    //call TriggerRegisterAnyUnitEventBJ( gg_trg_locusts_cast, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_locusts_cast, Condition( function Trig_locusts_cast_Conditions ) )
    call TriggerAddAction( gg_trg_locusts_cast, function Trig_locusts_cast_Actions )
endfunction


unit enters rect (playable map area)
JASS:
globals
    integer array locust_spawns_count
    group array locust_spawns_group
endglobals


function Trig_locusts_spawn_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer uId = GetUnitTypeId(u)
    set u = null
    if ( uId == 'u000' ) then
        return true
    endif
    if ( uId == 'uloc' ) then
        return true
    endif
    return false
endfunction

function Trig_locusts_spawn_Actions takes nothing returns nothing
    local integer i = 0
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    call DisplayTextToPlayer(Player(0), 0, 0, GetPlayerName(p))
    loop
        set i = i + 1
        exitwhen i > locust_maxIndex
        if locust_bool_source[i] == true then      
            set locust_bool_source[i] = false
            set locust_spawns_count[i] = locust_spawns_count[i] + 1
            call GroupAddUnit(locust_spawns_group[i], u)
            call DisplayTimedTextToForce( GetPlayersAll(), 4.00, "locust " +  I2S(locust_spawns_count[i]) + " spawned" )
            call DisplayTimedTextToForce( GetPlayersAll(), 4.00, "locusts in group: " +  I2S(CountUnitsInGroup(locust_spawns_group[i])) )
      
            set globalInt = 0
            call GroupEnumUnitsOfPlayer(locust_spawns_group[i], p, function CountLocustsInGroupEnum)
            call DisplayTimedTextToForce( GetPlayersAll(), 4.00, "locusts in group: " +  I2S(globalInt) )
      
      
      
      
            //call SaveInteger(udg_Hashtable, GetHandleId(abil_demonFire_source[abil_demonFire_maxIndex]), 'A04C', i)
      
        endif
    endloop
    set u = null
    //set t = null
endfunction

//===========================================================================
function InitTrig_locusts_spawn takes nothing returns nothing
    set gg_trg_locusts_spawn = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_locusts_spawn, GetPlayableMapRect() )
    call TriggerAddCondition( gg_trg_locusts_spawn, Condition( function Trig_locusts_spawn_Conditions ) )
    call TriggerAddAction( gg_trg_locusts_spawn, function Trig_locusts_spawn_Actions )
endfunction




JASS:
function Trig_locusts_death_Conditions takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer uType = GetUnitTypeId(u)
    set u = null
    if ( uType == 'u000' ) then
        return true
    endif
    if ( uType == 'uloc' ) then
        return true
    endif
    return false
endfunction



function Trig_locusts_death_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetTriggerPlayer()
    local integer i = 0
    local integer j
    local integer countLocusts = 0
    local boolean loopEndBool = false
    call DisplayTextToPlayer(Player(0), 0, 0, "locust died")
    loop
        exitwhen i == locust_maxIndex
        set i = i + 1
   
        call DisplayTextToPlayer(Player(0), 0, 0, "i = " + I2S(i))
   
        /*set j = 0
        loop
            call DisplayTextToPlayer(Player(0), 0, 0, "j = " + I2S(j))
            exitwhen j == locust_spawns_countMax[i]
            set j = j + 1
            if locusts_spawns[i][j] != null then
                set countLocusts = countLocusts + 1
                if locust_spawns[i][j] == u then
                    set loopEndBool = true
                    set countLocusts = countLocusts - 1         //this locust just died after all
                endif
            endif
            exitwhen loopEndBool
        endloop*/
    endloop
    call DisplayTextToPlayer(Player(0), 0, 0, "number of locusts alive = " + I2S(countLocusts))
 
    /*if countLocusts == 0 then
        if i != locust_maxIndex then
            set locust_bool_source[i] = locust_bool_source[locust_maxIndex]
            set locust_spawns_count[i] = locust_spawns_count[locust_maxIndex]
            set locust_spawns_group[i] = locust_spawns_group[locust_maxIndex]
       
        endif
        set locust_source[locust_maxIndex] = null
        set locust_maxIndex = locust_maxIndex - 1
    endif*/
 
 
    set u = null
endfunction

//===========================================================================
function InitTrig_locusts_death takes nothing returns nothing
    set gg_trg_locusts_death = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_locusts_death, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_locusts_death, Condition( function Trig_locusts_death_Conditions ) )
    call TriggerAddAction( gg_trg_locusts_death, function Trig_locusts_death_Actions )
endfunction
 

Attachments

  • locust spawn detection system.w3x
    22.5 KB · Views: 15
Last edited:
Status
Not open for further replies.
Top