[vJASS] CountUnitsInGroup() used incorrectly?

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
The purpose of the following trigger is to damage units at random around an item-wielder every two seconds. Said item is a two-stage ring. One just does damage, the other gives the user gold and wood when it deals damage.

The way I do this is having a function that clears a group and then sets it when the item type is acquired or dropped. This maintains a group for the periodic event and reduces lag by not creating it every 2 seconds.

The periodic action adds the source group mentioned above into a local group. The rings stack so I have it loop thru the inventory and then do the damage loop every time it finds a ring in the slot. The two are very similiar, so I copied/pasted and the RingOfGreed doesn't work.

This one works:
JASS:
scope RingOfHellLord initializer InitTrig
globals
    private group RING_HOLD
    private constant integer ITEM_ID = 'I00N'
    private constant integer BAT_NUM = 3
    private constant integer BAT_DAM = 75
    private unit RING_HOLDER
endglobals

private function GCond takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == ITEM_ID
endfunction

private function GAddCond takes nothing returns boolean
local integer i = 0
local item = ring
    loop   
        set ring = UnitItemInSlot(GetFilterUnit(), i)
        if ring != null and GetItemTypeId(ring) == ITEM_ID then
            set i = 5
        endif
        exitwhen i >= 5
        set i = i+1
    endloop
    return GetItemTypeId(ring) == ITEM_ID
endfunction
    
private function GroupAdd takes nothing returns nothing
    call DestroyGroup(RING_HOLD)
    set RING_HOLD = CreateGroup()
    set RING_HOLD = GetUnitsInRectMatching(bj_mapInitialPlayableArea, Condition(function GAddCond))
   // call DestroyCondition(function GAddCond)
endfunction

private function EnumFilter takes nothing returns boolean
    //call BJDebugMsg("enumfilter used")
    return IsUnitEnemy(RING_HOLDER, GetOwningPlayer(GetFilterUnit())) == true
endfunction

private function Act takes nothing returns nothing
local item ring
local effect s
local group copy = CreateGroup()
local group g = CreateGroup()
//local unit RING_HOLDER
local unit TARGET
local integer i = 0
local integer j = 0
local location k
    call GroupAddGroup(RING_HOLD, copy)
    loop
        set RING_HOLDER = FirstOfGroup(copy)
        exitwhen RING_HOLDER == null
        //call BJDebugMsg("RING_HOLDER != null")
        set k = GetUnitLoc(RING_HOLDER)
        loop
            set ring = UnitItemInSlot(RING_HOLDER, i)
            if ring != null and GetItemTypeId(ring) == ITEM_ID then
                //call BJDebugMsg("if ring != null and getitemtypeid==itemid == true")
                loop
                    call GroupEnumUnitsInRangeOfLoc(g, k, 300, Condition(function EnumFilter))
                    //call DestroyCondition(EnumFilter())
                    set TARGET = GroupPickRandomUnit(g)
                    call UnitDamageTargetEx(RING_HOLDER, TARGET, BAT_DAM, ATTACK_TYPE_PIERCE, DAMAGE_TYPE_SPELL, false)
                    //call BJDebugMsg("Damage function called")
                    set s = AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualCaster.mdl", TARGET, "overhead")
                    call DestroyEffect(s)
                    exitwhen j >= (BAT_NUM - 1)
                    set j = j+1
                endloop
            endif
            exitwhen i >= 5
            set i = i+1
        endloop
        set i = 0
        set j = 0
        call GroupClear(g)
        call GroupRemoveUnit(copy, RING_HOLDER)
    endloop
    //call BJDebugMsg("trigend")
call DestroyGroup(copy)
call DestroyGroup(g)
call RemoveLocation(k)
set k = null
set copy = null
set g = null
set RING_HOLDER = null
set TARGET = null
set s = null
set ring = null
endfunction

private function InitTrig takes nothing returns nothing
local trigger trg = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_DROP_ITEM)
    call TriggerAddCondition(trg, Condition(function GCond))
    call TriggerAddAction(trg, function GroupAdd)
    
    set trg = CreateTrigger()
    call TriggerRegisterTimerEvent(trg,2,true)
    call TriggerAddAction(trg, function Act)
    
    set RING_HOLD = CreateGroup()
endfunction
endscope

This one does not work: The problem happens either in the GroupEnum function (it shouldn't though since it works in the top one) or at the ContUnits function. The "call BJDebugMsg("RING_HOLDER != null")" function displays in game when I am holding a ring, and so does the "trigend" one.

JASS:
scope RingOfGreed initializer InitTrig
globals
    private group RING_HOLD
    private constant integer ITEM_ID = 'I01J'
    private constant integer BAT_NUM = 6
    private constant integer BAT_DAM = 90
    private unit RING_HOLDER
endglobals

private function GCond takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == ITEM_ID
endfunction

private function GAddCond takes nothing returns boolean
local integer i = 0
local item = ring
    loop   
        set ring = UnitItemInSlot(GetFilterUnit(), i)
        if ring != null and GetItemTypeId(ring) == ITEM_ID then
            set i = 5
        endif
        exitwhen i >= 5
        set i = i+1
    endloop
    return GetItemTypeId(ring) == ITEM_ID
endfunction
    
private function GroupAdd takes nothing returns nothing
    call DestroyGroup(RING_HOLD)
    set RING_HOLD = CreateGroup()
    set RING_HOLD = GetUnitsInRectMatching(bj_mapInitialPlayableArea, Condition(function GAddCond))
   // call DestroyCondition(function GAddCond)
endfunction

private function EnumFilter takes nothing returns boolean
    call BJDebugMsg("enumfilter used")
    return IsUnitEnemy(RING_HOLDER, GetOwningPlayer(GetEnumUnit())) == true
endfunction

private function Act takes nothing returns nothing
local item ring
local group copy = CreateGroup()
local group g = CreateGroup()
local unit RING_HOLDER
local unit TARGET
local integer RING_NUM = 0
local integer i = 0
local integer j = 0
local integer count
local location k
    call GroupAddGroup(RING_HOLD, copy)
    loop
        set RING_HOLDER = FirstOfGroup(copy)
        exitwhen RING_HOLDER == null
        call BJDebugMsg("RING_HOLDER != null")
        set k = GetUnitLoc(RING_HOLDER)
        loop
            set ring = UnitItemInSlot(RING_HOLDER, i)
            if ring != null and GetItemTypeId(ring) == ITEM_ID then
                call GroupEnumUnitsInRangeOfLoc(g, k, 300, Condition(function EnumFilter))
                set count = CountUnitsInGroup(g)
                if count >= 1 then
                    call BJDebugMsg("countunitsingroup > 0")
                    set RING_NUM = RING_NUM+1
                    loop
                        //call GroupEnumUnitsInRangeOfLoc(g, k, 300, Condition(function EnumFilter))
                        
                        //call DestroyCondition(EnumFilter())
                        set TARGET = GroupPickRandomUnit(g)
                        call UnitDamageTargetEx(RING_HOLDER, TARGET, BAT_DAM, ATTACK_TYPE_PIERCE, DAMAGE_TYPE_SPELL, false)
                        call BJDebugMsg("Damage function called")
                        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualCaster.mdl", TARGET, "overhead"))
                        exitwhen j >= (BAT_NUM - 1)
                        set j = j+1
                    endloop
                endif
            endif
            exitwhen i >= 5
            set i = i+1
        endloop
        if FM == true then
            set RING_NUM = RING_NUM*2
        endif
        call SetPlayerState(GetOwningPlayer(RING_HOLDER), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(RING_HOLDER), PLAYER_STATE_RESOURCE_GOLD) + (RING_NUM * 5))
        call SetPlayerState(GetOwningPlayer(RING_HOLDER), PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(GetOwningPlayer(RING_HOLDER), PLAYER_STATE_RESOURCE_LUMBER) + (RING_NUM * 10))
        set i = 0
        set j = 0
        call GroupClear(g)
        call GroupRemoveUnit(copy, RING_HOLDER)
    endloop
    call BJDebugMsg("trigend")
call DestroyGroup(copy)
call DestroyGroup(g)
call RemoveLocation(k)
set k = null
set copy = null
set g = null
set RING_HOLDER = null
set TARGET = null
set ring = null
endfunction

private function InitTrig takes nothing returns nothing
local trigger trg = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_DROP_ITEM)
    call TriggerAddCondition(trg, Condition(function GCond))
    call TriggerAddAction(trg, function GroupAdd)
    
    set trg = CreateTrigger()
    call TriggerRegisterTimerEvent(trg,2,true)
    call TriggerAddAction(trg, function Act)
    
    set RING_HOLD = CreateGroup()
endfunction
endscope
 

Samael88

Evil always finds a way
Reaction score
181
private unit RING_HOLDER

local unit RING_HOLDER

You got two declarations with the same name and type. with udgs I know that this is possible beause of the udg_ infront of the globals name. But I am not sure about vJass. Could be that especially with that being in the same scope and all:)

Edit: this is just a quik guess tho beacuse I have not bothered to learn vJass that much since I get aroung fine in vanilla Jass.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top