[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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      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