• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Strange problem with method

Status
Not open for further replies.
Level 7
Joined
Mar 8, 2009
Messages
360
If i call the following method more than once from the same object it doesn't work anymore

JASS:
method Banish2 takes nothing returns nothing
    local unit dummy = CreateUnit( GetOwningPlayer(GetTriggerUnit()), DUMMY, GetUnitX(.targets[.index]), GetUnitY(.targets[.index]), bj_UNIT_FACING)
    call UnitAddAbility(dummy, BANISHID)
    call IssueTargetOrder(dummy, "banish", .targets[.index])            
    set dummy = null
endmethod

The first time it banishes the target but the second(and third, fourth,..) time the method runs but the dummy isn't created , i completely don't understand why.
.targets(.index) is changed properly , if i create special effect on .targets(.index) then it shows up on the correct unit in game.

I'm getting quite desperate, already testing this for a full hour. :sad:

EDIT:

JASS:
scope ChainBanish initializer Init
    globals
        private constant integer SPELLID = 'A01O'
        private constant integer BANISHID = 'A00P'
        private constant integer TARGETS = 7
        private constant integer DUMMY = 'h009'
        private constant real PERIOD = 1.40
        private constant real BOUNCERANGE = 700.00
    endglobals
    
    //=============================================================================
    
    globals
        private boolexpr be
    endglobals    
    
    private function isUnitAlly takes nothing returns boolean
        return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit()))
    endfunction
    
    private struct Chain
        unit array targets[TARGETS]
        integer index
        
        static method create takes unit u1 returns Chain
            local Chain chain = Chain.allocate()
            set chain.targets[0] = u1
            set chain.index = 0
            return chain
        endmethod
                
        method Banish2 takes nothing returns nothing
            local unit dummy = CreateUnit( GetOwningPlayer(GetTriggerUnit()), DUMMY, GetUnitX(.targets[.index]), GetUnitY(.targets[.index]), bj_UNIT_FACING)
            call UnitAddAbility(dummy, BANISHID)
            call IssueTargetOrder(dummy, "banish", .targets[.index])            
            set dummy = null
        endmethod
        
        method SetNextUnit takes nothing returns boolean
            local group units = CreateGroup()
            local integer i = 0
            
            if .index == (TARGETS - 1) then
                call DestroyGroup(units)
                set units = null
                debug call BJDebugMsg("targets full")
                return false
            endif
            
            call GroupEnumUnitsInRange(units, GetUnitX(.targets[.index]), GetUnitY(.targets[.index]), BOUNCERANGE, be)
            set .index = .index + 1
            loop
                exitwhen i == .index
                if .targets[i] == FirstOfGroup(units) then
                    call GroupRemoveUnit( units, FirstOfGroup(units))
                    set i = -1
                endif
                set i = i + 1                
            endloop
            set .targets[.index] = FirstOfGroup(units)                        
            
            call DestroyGroup(units)
            set units = null            
                        
            if .targets[.index] != null then
                debug call BJDebugMsg("unit found")
                call .Banish2()
                return true
            else
                debug call BJDebugMsg("unit not found")
                return false
            endif
        endmethod
    endstruct
    
    private function Banish takes nothing returns nothing
        local Chain chain = GetTimerData(GetExpiredTimer())
        local unit dummy = null
        if chain.SetNextUnit() != true then            
            call chain.destroy()
            call ReleaseTimer(GetExpiredTimer())            
        else            
            set dummy = CreateUnit( GetOwningPlayer(GetTriggerUnit()), DUMMY, GetUnitX(chain.targets[chain.index - 1]),  GetUnitY(chain.targets[chain.index - 1]), bj_UNIT_FACING)
            call UnitAddAbility(dummy, SPELLID)
            call IssueTargetOrder(dummy, "chainlightning", chain.targets[chain.index])
            set dummy = null
        endif           
    endfunction
    
    private function Actions takes nothing returns nothing
        local Chain chain = Chain.create(GetSpellTargetUnit())
        local timer t = NewTimer()
        call chain.Banish2()
        call SetTimerData( t, chain)
        call TimerStart( t, PERIOD, true, function Banish)
        set t = null
    endfunction
    
    private function Conditions takes nothing returns boolean
        return IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) and (GetSpellAbilityId() == SPELLID)
    endfunction

    private function Init takes nothing returns nothing
        local trigger gg_trg_Chain_Banish = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( gg_trg_Chain_Banish, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( gg_trg_Chain_Banish, Condition( function Conditions ) )
        call TriggerAddAction( gg_trg_Chain_Banish, function Actions )
        
        set be = Condition(function isUnitAlly)
    endfunction
endscope
 
Last edited:
Level 8
Joined
Aug 6, 2008
Messages
451
Thats quite useless. Just create one dummy at map init and use it to cast all banishes. Its lot of faster, since CreateUnit is slow, and SetUnitX&Y pretty fast.
 
Level 7
Joined
Mar 8, 2009
Messages
360
I know its faster but the banish is also used by other (normal) units and has a cooldown, or does call UnitAddAbility(dummy, BANISHID) resets cooldown?

And i also want to know why it doesn't work the way I do it.

I'll put full trigger in first post.
 
Level 7
Joined
Mar 8, 2009
Messages
360
Because i got so much response on this i changed this spell into a simple gui spell , that forks banish up to 7 targets. But it doesn't work, again i have no idea what i did wrong , all seems fine until i test it.

  • Forked Banish
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chain Banish (|cffdc143cUltimate|r)
    • Actions
      • Set tempPoint = (Position of (Triggering unit))
      • Set point1 = (Position of (Target unit of ability being cast))
      • Set tempInt = 0
      • -------- - --------
      • -------- Cast Banish on target --------
      • Unit - Create 1 caster 5 sec for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
      • Unit - Add Chain Banish (dummy) to (Last created unit)
      • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Target unit of ability being cast)
      • Unit - Add Banish to (Last created unit)
      • Unit - Order (Last created unit) to Human Blood Mage - Banish (Target unit of ability being cast)
      • -------- - --------
      • -------- Cast Banish on random targets around target --------
      • Set tempGroup = (Units within 400.00 of point1 matching (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))
      • Unit Group - Remove (Target unit of ability being cast) from tempGroup
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • Set tempInt = (tempInt + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • 7 Greater than tempInt
            • Then - Actions
              • Unit - Create 1 caster 5 sec for (Owner of (Casting unit)) at tempPoint facing Default building facing degrees
              • Unit - Add Chain Banish (dummy) to (Last created unit)
              • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Picked unit)
              • Unit - Add Banish to (Last created unit)
              • Unit - Order (Last created unit) to Human Blood Mage - Banish (Picked unit)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_tempGroup)
      • Custom script: call RemoveLocation( udg_tempPoint )
      • Custom script: call RemoveLocation( udg_point1 )
 
Last edited:
Level 10
Joined
May 19, 2008
Messages
176
Because i got so much response on this i changed this spell into a simple gui spell , that forks banish up to 7 targets. But it doesn't work, again i have no idea what i did wrong , all seems fine until i test it.

  • Forked Banish
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chain Banish (|cffdc143cUltimate|r)
    • Actions
      • Set tempPoint = (Position of (Triggering unit))
      • Set point1 = (Position of (Target unit of ability being cast))
      • Set tempInt = 0
      • -------- - --------
      • -------- Cast Banish on target --------
      • Unit - Create 1 caster 5 sec for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
      • Unit - Add Chain Banish (dummy) to (Last created unit)
      • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Target unit of ability being cast) //This is the only thing that happens.
      • Unit - Add Banish to (Last created unit)
      • Unit - Order (Last created unit) to Human Blood Mage - Banish (Target unit of ability being cast)
      • //Dude, that can't work. You give a spell to a unit order it and give immediatly a new spell and order it. The first order won't be done.
      • -------- - --------
      • -------- Cast Banish on random targets around target --------
      • Set tempGroup = (Units within 400.00 of point1 matching (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • //Why do you remove the unit here and not before the loop?
          • If (tempInt Equal to 0) then do (Unit Group - Remove (Target unit of ability being cast) from (Last created unit group)) else do (Do nothing)
          • Set tempInt = (tempInt + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • 7 Greater than tempInt
            • Then - Actions
              • Unit - Create 1 caster 5 sec for (Owner of (Casting unit)) at tempPoint facing Default building facing degrees
              • Unit - Add Chain Banish (dummy) to (Last created unit)
              • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Picked unit)
              • Unit - Add Banish to (Last created unit)
              • Unit - Order (Last created unit) to Human Blood Mage - Banish (Picked unit)
              • //Same here....
            • Else - Actions
      • Custom script: call DestroyGroup(udg_tempGroup)
      • Custom script: call RemoveLocation( udg_tempPoint )
      • Custom script: call RemoveLocation( udg_point1 )

cedi
 
Level 7
Joined
Mar 8, 2009
Messages
360
Because i got so much response on this i changed this spell into a simple gui spell , that forks banish up to 7 targets. But it doesn't work, again i have no idea what i did wrong , all seems fine until i test it.

  • Forked Banish
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chain Banish (|cffdc143cUltimate|r)
    • Actions
      • Set tempPoint = (Position of (Triggering unit))
      • Set point1 = (Position of (Target unit of ability being cast))
      • Set tempInt = 0
      • -------- - --------
      • -------- Cast Banish on target --------
      • Unit - Create 1 caster 5 sec for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees //Doesn't happen
      • Unit - Add Chain Banish (dummy) to (Last created unit)
      • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Target unit of ability being cast)
      • Unit - Add Banish to (Last created unit) //Doesn't happen
      • Unit - Order (Last created unit) to Human Blood Mage - Banish (Target unit of ability being cast) //Doesn't happen
      • -------- - --------
      • -------- Cast Banish on random targets around target --------
      • Set tempGroup = (Units within 400.00 of point1 matching (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))
      • Unit Group - Remove (Target unit of ability being cast) from tempGroup
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • Set tempInt = (tempInt + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • 7 Greater than tempInt
            • Then - Actions
              • Unit - Create 1 caster 5 sec for (Owner of (Casting unit)) at tempPoint facing Default building facing degrees //Doesn't happen
              • Unit - Add Chain Banish (dummy) to (Last created unit) //Doesn't happen
              • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Picked unit) //Doesn't happen
              • Unit - Add Banish to (Last created unit) //Doesn't happen
              • Unit - Order (Last created unit) to Human Blood Mage - Banish (Picked unit) //Doesn't happen
            • Else - Actions
      • Custom script: call DestroyGroup(udg_tempGroup)
      • Custom script: call RemoveLocation( udg_tempPoint )
      • Custom script: call RemoveLocation( udg_point1 )

The problem is that it doesn't create more than one dummy. I have put comments to the things that don't happen.
 
Level 7
Joined
Mar 8, 2009
Messages
360
caster 5 sec is dummy with 5 health and -1 degenration.

I changed my trigger and now it banishes all targets except one random target. Only one of the 7 lightnings is casted (the one before the unit group iteration).

Is there a limit of units on the same loc?

  • Forked Banish
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chain Banish (|cffdc143cUltimate|r)
    • Actions
      • Set tempPoint = (Position of (Triggering unit))
      • Set point1 = (Position of (Target unit of ability being cast))
      • Set tempInt = 0
      • -------- - --------
      • -------- Cast Banish on target --------
      • Unit - Create 1 caster 5 sec for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
      • Unit - Add Chain Banish (dummy) to (Last created unit)
      • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Target unit of ability being cast)
      • Unit - Create 1 caster 5 sec for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
      • Unit - Add Banish to (Last created unit)
      • Unit - Order (Last created unit) to Human Blood Mage - Banish (Target unit of ability being cast)
      • -------- - --------
      • -------- Cast Banish on random targets around target --------
      • Set tempGroup = (Units within 400.00 of point1 matching (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True))
      • Unit Group - Remove (Target unit of ability being cast) from tempGroup
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • Set tempInt = (tempInt + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • 7 Greater than tempInt
            • Then - Actions
              • Unit - Create 1 caster 5 sec for (Owner of (Casting unit)) at tempPoint facing Default building facing degrees //This unit isn't created, bj_LastcreatedUnit is set to null.
              • Unit - Add Chain Banish (dummy) to (Last created unit)
              • Unit - Order (Last created unit) to Orc Far Seer - Chain Lightning (Picked unit)
              • Unit - Create 1 caster 5 sec for (Owner of (Triggering unit)) at tempPoint facing Default building facing degrees
              • Unit - Add Banish to (Last created unit)
              • Unit - Order (Last created unit) to Human Blood Mage - Banish (Picked unit)
            • Else - Actions
      • Custom script: call DestroyGroup(udg_tempGroup)
      • Custom script: call RemoveLocation( udg_tempPoint )
      • Custom script: call RemoveLocation( udg_point1 )
 
Last edited:
Status
Not open for further replies.
Top