Dummy only cast spell at one target in ForGroup

Magoiche

Member
Reaction score
20
I made this trigger to when i cast a spell, a dummy is spawned and some other dummies will cast Life Drain on units near.
But only one dummy cast Life Drain.

JASS:
scope SuckingLight initializer Initial

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A002'
endfunction

private function TargetConditions takes nothing returns boolean
    return IsUnitEnemy( GetFilterUnit(), GetOwningPlayer( GetTriggerUnit() ) ) == true and GetUnitState( GetFilterUnit(), UNIT_STATE_LIFE ) > 0
endfunction

private function Light takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Dummy = CreateUnitAtLoc( GetOwningPlayer( Caster ), 'u002', GetSpellTargetLoc(), 0.0 )
    call UnitApplyTimedLife( Dummy, 'BTLF', 20.0 )
    call UnitAddAbility( Dummy, 'A003' )
    call SetUnitAbilityLevel( Dummy, 'A003', GetUnitAbilityLevel( Caster, 'A002' ) )
    call IssueTargetOrder( Dummy, "drain", GetEnumUnit() )
    set Caster = null
    set Dummy = null
endfunction

private function Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Dummy = CreateUnitAtLoc( GetOwningPlayer( Caster ), 'u000', GetSpellTargetLoc(), 0.0 )
    local group UnitsNear = GetUnitsInRangeOfLocMatching( 800, GetUnitLoc( Dummy ), Condition( function TargetConditions ) )
    call SetUnitColor( Dummy, PLAYER_COLOR_YELLOW )
    if CountUnitsInGroup( UnitsNear ) == 0 then
        call KillUnit( Dummy )
    else
        call UnitApplyTimedLife( Dummy, 'BFTL', 20.0 )
        call ForGroup( UnitsNear, function Light )
    endif
    call DestroyGroup( UnitsNear )
    set Caster = null
    set Dummy = null
    set UnitsNear = null
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope


I can't see where is the error. x.x

Quick Question

1. What GroupClear do? Empty the group? The same as DestroyGroup?

Thanks in advance. =]
 

Flare

Stops copies me!
Reaction score
662
(havne't looked at code, not sure of what the problem would be there :p)

What GroupClear do? Empty the group? The same as DestroyGroup?
GroupClear empties the group, but the group still exists
DestroyGroup (as the name suggests) destroys the group (and presumably empties, not sure what would happen if a new group took a destroyed group's recycled ID), so it's no longer usable unless you do CreateGroup again

GroupClear will not solve a group leak, but if you're using a single global group variable and doing
JASS:
call GroupEnumUnitsInRange (...)
//or
call GroupAddUnit (...)

you can just clear the group if/when the group needs to be emptied of all units, and you shouldn't have any bother.

If you're doing
JASS:
local group g = CreateGroup ()

you're gonna need to use
JASS:
call DestroyGroup (g)
 

chobibo

Level 1 Crypt Lord
Reaction score
48
EDIT: Oh my mistake... sorry.

EDIT2: Sorry dude, I can't also see any errors. Could you post the map? Oh you're also leaking locations, GetSpellTargetLoc() leaks a location. Try storing it to a variable and then RemoveLocation() it.
 

Magoiche

Member
Reaction score
20
@Flare
Thanks!
It will be usefull to me =]

@chobibo
Sorry for what? x.x

Attached the map on the first post.

Note: When i copied the map then opened to remove some things.
The jasshelper did not show up when i was saving. lol
So if you get any error its not my fault. u.u

Note2: Thanks. I had this leak in some other spells too. =]
 

chobibo

Level 1 Crypt Lord
Reaction score
48
JASS:
scope SuckingLight initializer InitScope

globals
    private constant integer    ABILITY_ID         =    'A002'
    private constant integer    DUMMY_DRAIN_ID     =    'A003'
    private constant integer    DUMMY_MASTER       =    'u000'
    private constant integer    DUMMY_CHILD        =    'u002'
    
    private constant real       AREA_OF_EFFECT     =    500.00
    
    private group TARGETS
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILITY_ID
endfunction

private function TargetConditions takes nothing returns boolean
    return IsUnitEnemy( GetFilterUnit(), GetTriggerPlayer() ) == true and GetUnitState( GetFilterUnit(), UNIT_STATE_LIFE ) > 0
endfunction

private function Actions takes nothing returns nothing
    local location loc = GetSpellTargetLoc()
    local integer level = GetUnitAbilityLevel( GetTriggerUnit(), ABILITY_ID )
    
    local unit dummy
    local unit target
    
    local boolean EmptyGroup
    
    call GroupEnumUnitsInRangeOfLoc(TARGETS, loc, AREA_OF_EFFECT, Condition(function TargetConditions))
    
    set EmptyGroup=(FirstOfGroup(TARGETS)==null)
    
    loop
        set target=FirstOfGroup(TARGETS)
        exitwhen target==null
        
        set dummy=CreateUnitAtLoc(GetTriggerPlayer(), DUMMY_CHILD, loc, 0)
        call ShowUnit(dummy, false)
        
        call UnitApplyTimedLife(dummy, 0, 20.0)
        
        call UnitAddAbility(dummy, DUMMY_DRAIN_ID)
        call SetUnitAbilityLevel(dummy, DUMMY_DRAIN_ID, level)
        call IssueTargetOrder(dummy, "drain", target)
        
        call GroupRemoveUnit(TARGETS, target)
    endloop
    
    if not (EmptyGroup) then
        set dummy=CreateUnitAtLoc(GetTriggerPlayer(), DUMMY_MASTER, loc, 0)
        call SetUnitColor(dummy, PLAYER_COLOR_YELLOW)
        call UnitApplyTimedLife(dummy, 0, 20.0)
    endif
    
    call GroupClear(TARGETS)
    call RemoveLocation(loc)
    
    set loc = null
    set dummy = null
    set target = null
endfunction

private function InitScope takes nothing returns nothing
    local trigger trig = CreateTrigger()
    
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )

    set TARGETS=CreateGroup()
endfunction

endscope


I don't know exactly why ForGroup didn't work, I didn't want to change anything in the Object Editor so I tried FirstOfGroup() and it turned out okay.

EDIT: Wrong conclusion.

EDIT 2: AH now I get it!, whenever the dummy caster casts a spell the GetSpellTargetLoc() is modified so it returns something else. I'll post the solution later.


Here's the quick fix to your spell. I haven't edited it, just added the fix, so it leaks and is not optimized.
JASS:
scope SuckingLight initializer Initial

    globals
       private location LOC
    endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A002'
endfunction

private function TargetConditions takes nothing returns boolean
    return IsUnitEnemy( GetFilterUnit(), GetOwningPlayer( GetTriggerUnit() ) ) == true and GetUnitState( GetFilterUnit(), UNIT_STATE_LIFE ) > 0
endfunction

private function Light takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Dummy = CreateUnitAtLoc( GetOwningPlayer( Caster ), 'u002', LOC, 0.0 )
    
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetUnitName(GetEnumUnit()))
    
    call UnitApplyTimedLife( Dummy, 'BTLF', 20.0 )
    call UnitAddAbility( Dummy, 'A003' )
    call SetUnitAbilityLevel( Dummy, 'A003', GetUnitAbilityLevel( Caster, 'A002' ) )
    call IssueTargetOrder( Dummy, "drain", GetEnumUnit() )
    
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "callback: "+I2S(H2I(LOC)))
    
    set Caster = null
    set Dummy = null
endfunction

private function Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local unit Dummy 
    local group UnitsNear
    
    set LOC=GetSpellTargetLoc()
    
    set Dummy=CreateUnitAtLoc( GetOwningPlayer( Caster ), 'u000', LOC, 0.0 )
    set UnitsNear=GetUnitsInRangeOfLocMatching( 800, GetUnitLoc( Dummy ), Condition( function TargetConditions ) )

    
    call SetUnitColor( Dummy, PLAYER_COLOR_YELLOW )
    
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "before callback: "+I2S(H2I(LOC)))

    
    if CountUnitsInGroup( UnitsNear ) == 0 then
        call KillUnit( Dummy )
    else
        call UnitApplyTimedLife( Dummy, 'BFTL', 20.0 )
        call ForGroup( UnitsNear, function Light )
    endif
    
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "after callback: "+I2S(H2I(LOC)))

    call RemoveLocation(LOC)
    
    call DestroyGroup( UnitsNear )
    set Caster = null
    set Dummy = null
    set UnitsNear = null
endfunction

private function Initial takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
    set trig = null
endfunction

endscope
 

Magoiche

Member
Reaction score
20
Yeah. I figured it out too.
But... Making that location a global make the spell non-mui(not sure).
I think i will try changing somethings. i.i

Thanks anyway.
 

chobibo

Level 1 Crypt Lord
Reaction score
48
I already provided a new code without leaks (it's the first one), it's also MUI, if ever you need it you can use it.
 

Magoiche

Member
Reaction score
20
Cool!
You use FirstofGroup then started removing the already target units.
This is going to my remember book. =]

Very big thanks to you.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      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