Dummy only cast spell at one target in ForGroup

Magoiche

Member
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!
Staff member
(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
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
@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
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
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
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
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.
  • tom_mai78101 tom_mai78101:
    Would like to get some annual forum statistics report.
  • The Helper The Helper:
    there are stats in the xenforo forum admin section and we have matomo stats we started collecting beginning of the year so we will not have annual on that until next year
  • The Helper The Helper:
    I thought you had keys to the bathroom Tom? Ghan does Tom have access to the stats thread in the bathroom
  • The Helper The Helper:
    since I started jacking with the bots on the site we doubled our page views on the site in a week lol
  • The Helper The Helper:
    I have been having lots of fun
  • The Helper The Helper:
    we have had like 6000 views of the American Airlines economy class thread in the last week
  • The Helper The Helper:
    I ought to stick a travel affiliate link or something on that page to try and monetize that they are just going there and leaving it might even be bots I am not sure
  • The Helper The Helper:
    I just got into it with the Atari VCS Facebook Moderator I started trolling him and almost got banned
  • The Helper The Helper:
    They deleted one of my posts one time so I was trolling him on a help post I put up because I am evil I guess and bored and the guy handled it well I loved his attitude Atari has a good social media presence even if they do not have many games.
  • The Helper The Helper:
    The French Atari they call them even though they are like totally based in America they just have French Money coming in. Gotta love it
  • Ghan Ghan:
    Microsoft buying Activision Blizzard holy crap!
  • The Helper The Helper:
    I know right holy cow
  • Accname Accname:
    Thats not going to save it.
  • The Helper The Helper:
    It might
  • The Helper The Helper:
    They are going to use alot of that IP in the Metaverse
  • The Helper The Helper:
    I found a new section of the stats that is freaking interesting!
  • The Helper The Helper:
    oh yeah this is what I was looking for good job matomo! These are some sweet stats I am learning the interface on it too!
  • The Helper The Helper:
    If anyone ever asks later how I found out about it was watching the site bots but not watching what they were doing but asking myself why they were here?
  • The Helper The Helper:
    there must be a reason and ok that is it
  • The Helper The Helper:
    the past and the future all come together into one
  • The Helper The Helper:
    the search engines are what built thehelper.net the search engines will make it big again maybe
  • The Helper The Helper:
    the real question is are 5 million links better than 60 real good links?
  • The Helper The Helper:
    the answer is 60 lol
  • The Helper The Helper:
    unless you put 100k links on it lol then you get something

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome
    Top