• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Running loop problem

Status
Not open for further replies.
Level 6
Joined
Mar 15, 2005
Messages
112
Having trouble running a loop inside a pick every unit in range matching 2 conditions.
JASS:
function Condition3 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction
function Condition4 takes nothing returns boolean
    return ( IsPlayerAlly(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetTriggerUnit())) != true )
endfunction
function DummyCondition takes nothing returns boolean
    return GetBooleanAnd( Condition3(), Condition4() )
endfunction

function DummyFunction takes nothing returns nothing
local integer array2
local location array loc3
local real real2 = 90
local unit array dummy2
local location loc2 = GetSpellTargetLoc()
loop
exitwhen array2 == 16
call TriggerSleepAction(.25)
set array2 = array2 + 1
set real2 = real2 - 30
set loc3[13] = PolarProjectionBJ(loc2, 300, real2)
call CreateNUnitsAtLoc( 1, 'h001', GetOwningPlayer(GetTriggerUnit()), loc3[13], GetRandomDirectionDeg() )
call SetUnitAbilityLevelSwapped( 'A001', GetLastCreatedUnit(), GetUnitAbilityLevelSwapped('A000', GetTriggerUnit()) )
call IssueTargetOrder( GetLastCreatedUnit(), "chainlightning", GroupPickRandomUnit(GetUnitsInRangeOfLocAll(400.00, loc2)) )
set dummy2[array2] = GetLastCreatedUnit()
endloop
endfunction
I call the function "DummyFunction" in another part of the trigger.
Had this working before I created the conditions. But I know the conditions are right because I had this work once without the loop. Is the problem putting a loop inside a "pick every unit and do multiple actions" doesn't work? If you'd like I can post the whole trigger but its pretty big. By the way I'm getting no syntax errors. This is for the spell contest so I'll understand if your unwilling to help =P. If you want the full thing I'll pm the code.
 
Level 6
Joined
Mar 15, 2005
Messages
112
Alright heres the whole trigger.
JASS:
// Ancient's Fury
// Made by IncubiProtocoL
// Cooldowns/mana cost have been set to zero for testing purposes.
// You will need to alter Entangling roots (nuetral hostile 1). Just remove mana cost.
// You also need to edit Chain Lightning to how you'd like it. Its casted many times so don't make damage to high.
// 2 dummy units used. A circle of dummies and one is spawned at the edge of the bushes to cast chain lightning.
// Had to make pathing blockers because locusted units don't seem to have collision.
// Can alter treant to whatever you want. Change its damage etc.
// Mana costs and cool downs are effected by level increases. Chain Lightning damage increases with level and treants last longer.
// The rawcode of the custom spell you use must be 'A000' or change it right below this line.
// Might not be fully MUI since I used a wait. Can't figure out how to resolve.
// Since I'm using all locals maybe it is still MUI.
// Did a test that makes many unit cast it at the same time and no problems.
function Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction
function Condition1 takes nothing returns boolean//Conditions for the treants to spawn.
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction
function Condition2 takes nothing returns boolean
    return ( IsPlayerAlly(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetTriggerUnit())) != true )
endfunction
function TreantCondition takes nothing returns boolean
    return GetBooleanAnd( Condition1(), Condition2() )
endfunction
    //........................................
function Condition3 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction
function Condition4 takes nothing returns boolean
    return ( IsPlayerAlly(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetTriggerUnit())) != true )
endfunction
function DummyCondition takes nothing returns boolean
    return GetBooleanAnd( Condition3(), Condition4() )
endfunction
function TreantFunction takes nothing returns nothing // Things that happen to any enemy units withing range of the spell.
call CreateNUnitsAtLoc( 1, 'efon', GetTriggerPlayer(), Location(GetLocationX(GetUnitLoc(GetEnumUnit())), GetLocationY(GetUnitLoc(GetEnumUnit()))), bj_UNIT_FACING )
call UnitApplyTimedLifeBJ( ( 10.00 * I2R(GetUnitAbilityLevelSwapped('A000', GetTriggerUnit())) ), 'BEfn', GetLastCreatedUnit() )
call GroupTargetOrder( GetLastCreatedGroup(), "entanglingroots", GetEnumUnit() )
endfunction
function DummyFunction takes nothing returns nothing
local integer array2
local location array loc3
local real real2 = 90
local unit array dummy2
local location loc2 = GetSpellTargetLoc()
loop
exitwhen real2 == -270
call TriggerSleepAction(.25)
set array2 = array2 + 1
set real2 = real2 - 30
set loc3[13] = PolarProjectionBJ(loc2, 300, real2)
call CreateNUnitsAtLoc( 1, 'h001', GetOwningPlayer(GetTriggerUnit()), loc3[13], GetRandomDirectionDeg() )
call SetUnitAbilityLevelSwapped( 'A001', GetLastCreatedUnit(), GetUnitAbilityLevelSwapped('A000', GetTriggerUnit()) )
call IssueTargetOrder( GetLastCreatedUnit(), "chainlightning", GroupPickRandomUnit(GetUnitsInRangeOfLocAll(400.00, loc2)) )
set dummy2[array2] = GetLastCreatedUnit()
endloop
endfunction
function Actions takes nothing returns nothing //Creates all the local variables
local location loc1 = GetSpellTargetLoc()
local location loc2 = GetSpellTargetLoc()
local location array loc3
local real real1 = 60
local real real2 = 90
local integer array1 = 0
local unit array dummy1
local unit array dummy2
local integer count1 = 0
local unit unit1 = GetTriggerUnit()
local destructable array destr1
loop //Creates a circle of dummies
exitwhen real1 == 420
set real1 = real1 + 15
set array1 = array1 + 1
set loc1 = PolarProjectionBJ(loc2, 300, real1)
call CreateNUnitsAtLoc( 1, 'h000', GetOwningPlayer(GetTriggerUnit()), loc1, bj_UNIT_FACING )
call CreateDestructableLoc( 'YTpc', loc1, GetRandomDirectionDeg(), 1, 0 )
set dummy1[array1] = GetLastCreatedUnit()
set destr1[array1] = GetLastCreatedDestructable()
call RemoveLocation(loc1)
set loc1 = null
endloop //Creates the hand of the clock
call ForGroupBJ( GetUnitsInRangeOfLocMatching(300.00, loc2, Condition(function DummyCondition)), function DummyFunction )
loop //If you use another effect make sure it has a death animation. Since the effect is destroyed instantly.
exitwhen real2 == -270
call TriggerSleepAction( .25 )
set real2 = real2 + -30
set loc3[1] = PolarProjectionBJ(loc2, 25, real2)
set loc3[2] = PolarProjectionBJ(loc2, 50, real2)
set loc3[3] = PolarProjectionBJ(loc2, 75, real2)
set loc3[4] = PolarProjectionBJ(loc2, 100, real2)
set loc3[5] = PolarProjectionBJ(loc2, 125, real2)
set loc3[6] = PolarProjectionBJ(loc2, 150, real2)
set loc3[7] = PolarProjectionBJ(loc2, 175, real2)
set loc3[8] = PolarProjectionBJ(loc2, 200, real2)
set loc3[9] = PolarProjectionBJ(loc2, 225, real2)
set loc3[10] = PolarProjectionBJ(loc2, 250, real2)
set loc3[11] = PolarProjectionBJ(loc2, 275, real2)
set loc3[12] = PolarProjectionBJ(loc2, 300, real2)
call DestroyEffect(AddSpecialEffectLocBJ( loc3[1], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[2], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[3], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[4], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[5], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[6], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[7], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[8], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[9], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[10], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[11], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call DestroyEffect(AddSpecialEffectLocBJ( loc3[12], "Abilities\\Spells\\Undead\\Possession\\PossessionCaster.mdl" ))
call RemoveLocation(loc3[1])
call RemoveLocation(loc3[2])
call RemoveLocation(loc3[3])
call RemoveLocation(loc3[4])
call RemoveLocation(loc3[5])
call RemoveLocation(loc3[6])
call RemoveLocation(loc3[7])
call RemoveLocation(loc3[8])
call RemoveLocation(loc3[9])
call RemoveLocation(loc3[10])
call RemoveLocation(loc3[11])
call RemoveLocation(loc3[12])
set loc3[1] = null
set loc3[2] = null
set loc3[3] = null
set loc3[4] = null
set loc3[5] = null
set loc3[6] = null
set loc3[7] = null
set loc3[8] = null
set loc3[9] = null
set loc3[10] = null
set loc3[11] = null
set loc3[12] = null
endloop
loop //Destroys the circle
exitwhen count1 == 30
call RemoveUnit( dummy1[count1] )
call RemoveUnit( dummy2[count1] )
call RemoveDestructable(destr1[count1] )
set destr1[count1] = null
set dummy1[count1] = null
set dummy2[count1] = null
set count1 = count1 + 1
endloop
call ForGroupBJ( GetUnitsInRangeOfLocMatching(300.00, loc2, Condition(function TreantCondition)), function TreantFunction )
set count1 = 0 //Cleanup
call RemoveLocation(loc2)
set loc2 = null
endfunction
//===========================================================================
function InitTrig_Ancients_Fury_Copy takes nothing returns nothing
    set gg_trg_Ancients_Fury_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ancients_Fury_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Ancients_Fury_Copy, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_Ancients_Fury_Copy, function Actions )
endfunction
If I can't get this to work I'll just stick with the version without conditions. Without conditions if dead units or ally units are in range gives the part of the spell a chance to do nothing. It picks random unit's in range (which is why I'm trying to setup some conditions).
 
Level 6
Joined
Mar 15, 2005
Messages
112
Had a problem getting a loop to work for that. Decided to do it the hard way. Loop within a loop problem I think. I need those locations destroyed quickly so I can't put a loop outside of that loop. Not a big deal though. Edit: Yea. Man I've tried so many things to get this to work. I was thinking using a sleep function inside the "pick units do multiple actions" was the problem. Tried running the
JASS:
call ForGroupBJ( GetUnitsInRangeOfLocMatching(300.00, loc2, Condition(function DummyCondition)), function DummyFunction )
inside the loop with lots of effects. Didn't work still.
 
Level 6
Joined
Mar 15, 2005
Messages
112
Heres the map so you can test etc. The enabled version works. The disabled one is the one I've posted here that I'm having problems with. Edit: kool thx. I appreciate it. If you can't fix I guess I'll deal with no conditions for it. Doesn't effect the spell to much. Maybe I'll make it so the chain lightning can target allies/dead. So even you and your allies will be in danger inside of the spell's range. Not sure if dead units can be casted upon though.
 
Last edited:
Status
Not open for further replies.
Top