Loops don't work.

Blackrage

Ultra Cool Member
Reaction score
25
For some reason the loops don't work in my spell.

PS: It's not complete. I was just testing it to see if it worked, but the loops didn't work.

JASS:
scope Torrent initializer Init
    private struct Torrent
        group g
        unit c
        real z
        real dmg
        integer level
        
        //=====================Do not touch above=====================\\
        //======================Configuration=========================\\
        static constant integer AbilId = 'A000'                         //The Ability Id.
        static constant integer DummyId = 'u001'                        //The Dummy Id.
        static constant integer DummyAbilId = 'A001'                    //The Dummy Ability Id (The Slow).
        private static constant real SpellDelay = 2.                    //How long it takes for Torrent to actually work.
        private static constant real BaseDamage = 60                    //This is the base damage. Formula is BaseDamage+(DPL*AbilLevel).
        private static constant real DPL = 60                           //This is how much the damage increases per level.
        private static constant real AoE = 225                          //This is the Area of Effect of the spell.
        private static constant real MaxHeight = 500                    //This is how high the units go.
        private static constant real DisableTime = 1.53                 //This is how long the units are paused/in the air.
        
        private static constant integer FlyAbil = 'Amrf'                //This is the Crow Ability. Do not change unless you changed the original ability yourself.
        private static constant string SFX = "Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl"  // This is the Effect shown when Torrent "erupts"
        //============================================================\\
        //==================Do not touch past here====================\\
        
        
        static method GroupCondition takes nothing returns boolean
            return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false and IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) == false
        endmethod
        
        static method start takes unit Caster, real TargetX, real TargetY, integer Level returns nothing
            local Torrent d = Torrent.create()
            local unit PickedUnit
            
            set d.c = Caster
            set d.dmg = .BaseDamage + (.DPL*I2R(Level))
            set d.level = Level
            call GroupEnumUnitsInRange(d.g, TargetX, TargetY, .AoE, Condition(function Torrent.GroupCondition))
            call DestroyEffect(AddSpecialEffectLoc(.SFX, Location(TargetX, TargetY)))
            
            loop
                set PickedUnit = FirstOfGroup(d.g)
                exitwhen PickedUnit == null
                    call PauseUnit(PickedUnit, true)
                    call UnitAddAbility(PickedUnit, .FlyAbil)
                    call BJDebugMsg("Debug 1")
            endloop
            
            call TT_Start(function Torrent.callback, d)
        endmethod
        
        static method callback takes nothing returns boolean
            local Torrent d = TT_GetData
            local integer int = 0
            local unit PickedUnit
            local real Damage = d.dmg / 2
            local real DPS = ((Damage/.MaxHeight)/.DisableTime)*TT_PERIOD
            local real ZPerTick = .MaxHeight*(.DisableTime*TT_PERIOD)
            local boolean EndCheck
            call BJDebugMsg("Debug 2")
            
            loop
                set PickedUnit = FirstOfGroup(d.g)
                exitwhen PickedUnit == null
                    call BJDebugMsg("Debug 3")
                    call SetUnitFlyHeight(PickedUnit, d.z, 0.)
                    call UnitDamageTarget(d.c, PickedUnit, Damage, false, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            endloop
            
            if d.z >= .MaxHeight then
                call BJDebugMsg("Debug 4")
                set d.z = d.z - ZPerTick
            else
                call BJDebugMsg("Debug 4")
                set d.z = d.z + ZPerTick
            endif
            
            if d.z <= 0. then
                call BJDebugMsg("Debug 5")
                return true
            endif
            return false
        endmethod
        
        method onDestroy takes nothing returns nothing
            local unit PickedUnit
            call BJDebugMsg("Debug 6")
            loop
                set PickedUnit = FirstOfGroup(.g)
                exitwhen PickedUnit == null
                call PauseUnit(PickedUnit, false)
                call CreateUnit(GetOwningPlayer(.c), .DummyId, GetUnitX(PickedUnit), GetUnitY(PickedUnit), 0.)
                call UnitAddAbility(bj_lastCreatedUnit, .DummyAbilId)
                call SetUnitAbilityLevel(bj_lastCreatedUnit, .DummyAbilId, .level)
                call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', 1.5)
                call IssueTargetOrder(bj_lastCreatedUnit, "slow", PickedUnit)
                
                call UnitRemoveAbility(PickedUnit, .FlyAbil)
                call SetUnitFlyHeight(PickedUnit, 0., 0.)
            endloop
            set .c = null
            call DestroyGroup(.g)
        endmethod
    endstruct
    
    private function Actions takes nothing returns nothing
        call Torrent.start(GetTriggerUnit(), GetLocationX(GetSpellTargetLoc()), GetLocationY(GetSpellTargetLoc()), GetUnitAbilityLevel(GetTriggerUnit(), Torrent.AbilId))
    endfunction

    private function Cond takes nothing returns boolean
        return GetSpellAbilityId() == Torrent.AbilId
    endfunction
    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function Cond))
        call TriggerAddAction(t, function Actions)
    endfunction
endscope

+rep to whoever helps.
 

Blackrage

Ultra Cool Member
Reaction score
25
K, I did that. The first loop works, but for some reason it gets stuck at that loop and the caster gets paused instead of the enemy units.
 

saw792

Is known to say things. That is all.
Reaction score
280
1. The caster is not excluded from the group condition
2. You are not removing PickedUnit from the group in the loop. Thus it will keep selecting the same unit, over and over again. I don't know how wc3 didn't crash from an infinite loop to be honest.
 

The Undaddy

Creating with the power of rage
Reaction score
55
I don't know how wc3 didn't crash from an infinite loop to be honest.
Sometimes wc3 just crashes the current instance of the trigger :) All the 'hit op limit' stuff.

Btw if you still have a problem you can post your current code :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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