1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Strange problem with method

Discussion in 'Triggers & Scripts' started by Vulcano, Aug 6, 2009.

  1. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    If i call the following method more than once from the same object it doesn't work anymore

    Code (vJASS):
    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:
    Full Trigger

    Code (vJASS):
    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: Aug 9, 2009
  2. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    post the struct that is containing this method.
     
  3. Viikuna

    Viikuna

    Joined:
    Aug 6, 2008
    Messages:
    430
    Resources:
    0
    Resources:
    0
    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.
     
  4. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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.
     
  5. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
  6. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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.

    Gui spell
    • 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: Aug 10, 2009
  7. cedi

    cedi

    Joined:
    May 19, 2008
    Messages:
    165
    Resources:
    7
    Icons:
    2
    Spells:
    5
    Resources:
    7
    cedi
     
  8. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    only the first order happens the banish doesn't happen
     
  9. Reaper2008

    Reaper2008

    Joined:
    Jul 27, 2008
    Messages:
    1,117
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Use 7 different units (maybe even 14), as it takes time to cast spells.
     
  10. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    The problem is that it doesn't create more than one dummy. I have put comments to the things that don't happen.
     
  11. cedi

    cedi

    Joined:
    May 19, 2008
    Messages:
    165
    Resources:
    7
    Icons:
    2
    Spells:
    5
    Resources:
    7
    Is there something special about the unit: caster 5 sec?
    And does the banish have enough range and no mana costs? So can you cast it yourself?

    cedi
     
  12. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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?

    trigger
    • 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: Aug 16, 2009
  13. cedi

    cedi

    Joined:
    May 19, 2008
    Messages:
    165
    Resources:
    7
    Icons:
    2
    Spells:
    5
    Resources:
    7
    Nope, a new unit pushes the others a bit away...

    cedi
     
  14. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Bumb.
    The trigger posted in the last post is still not working. I did some testing and found out that the units casting the chain effect in the group loop aren't created. Any idea why those units aren't created?
     
  15. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1
  16. Vulcano

    Vulcano

    Joined:
    Mar 8, 2009
    Messages:
    335
    Resources:
    1
    Maps:
    1
    Resources:
    1