HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS spell freezes game

08-25-2007, 04:17 PM#1
botanic
I have a spell that when I cast it at level 30 with 500 Int it causes the game to almost completely lock up... I would think it is because of the scaling value of the sfx however I think it could also be the number of generated balls. Ne ways if anyone can give me an idea on making it not lock-up id appreciate it.

Collapse JASS:
function crai_Code takes nothing returns integer        //Rawcode
    return 'A01N'
endfunction

function crai_DummyCode takes nothing returns integer        //DummyRawcode
    return 'e005'
endfunction

function crai_MissileEffect0 takes nothing returns string    //MissileEffect0
    return "Abilities\\Spells\\Human\\ManaFlare\\ManaFlareTarget.mdl"
endfunction

function crai_MissileEffect1 takes nothing returns string    //MissileEffect1
    return "Abilities\\Spells\\Undead\\DevourMagic\\DevourMagicBirthMissile.mdl"
endfunction

function crai_ImpactEffect0 takes nothing returns string    //ImpactEffect0
    return "Abilities\\Weapons\\ColdArrow\\ColdArrowMissile.mdl"
endfunction

function crai_EndChannelStopsMissiles takes nothing returns boolean //When true missiles are destroyed when the hero stops
    return false                                 // channeling
endfunction

function crai_MissileVelocity takes nothing returns real    //Missile speed
    return 600.0
endfunction

function crai_PerWaveByLevel takes integer l returns integer    //Missiles per wave dependent on level
     return (2 + (l/2))
endfunction

function crai_DamagePerMissile takes nothing returns real    //Damage per missile
    return 1.5 * I2R(GetUnitAbilityLevelSwapped('A01N', udg_Shapeshifter_Hero))
endfunction

function crai_DamageFactorMin takes nothing returns real    //Minimum damage and scaling factor for the missiles
    return 0.6 * (I2R(GetUnitAbilityLevelSwapped('A01N', udg_Shapeshifter_Hero))/15)
endfunction

function crai_DamageFactorMax takes nothing returns real    //Maximum damage and scaling factor for the missiles
    return 2.5 * (I2R(GetUnitAbilityLevelSwapped('A01N', udg_Shapeshifter_Hero))/15)
endfunction

function crai_WaveInterval takes nothing returns real        //Interval between waves (Preferably > .50)
    return (1.06 - (I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, udg_Shapeshifter_Hero, false)) / 436))
endfunction

function crai_MissileDuration takes nothing returns real    //Duration of the orbs and their sub-orbs	
    return 2.00
endfunction

function crai_AngularOffset takes nothing returns real        //Determines the tightness of the spray
    return 35.0
endfunction

function crai_Offset takes nothing returns real        //Starting offset of each orb
    return 120.0
endfunction

function crai_RecenteringValue takes nothing returns real    //Factor of the angular offset by which the orb is directed
    return .20                            //Should result in a more forward directed movement despite
endfunction                                // the angular offset

function crai_CollisionRadius takes nothing returns real    //Collision Radius of the missiles
    return 70.
endfunction

function crai_SprayMethod takes nothing returns integer    //Method of spraying each wave
    return 2
endfunction

///////////////////////////////////////////////////////////
// Methods ////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// 0 - Simultaneous; all orbs released at the same time	///
//	Same distribution each wave			///
// 1 - Sequential; orbs released one at a time		///
//	Random distribution each wave			///
// 2 - Both; randomly chooses between 0 and 1		///
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////

function crai_SprayInterval takes nothing returns real        //Interval between sequential orbs
    return (crai_WaveInterval() - 0.05) / 10.
endfunction

function crai_SpraySequentialChance takes nothing returns real    //Chance of sequential waves with method 2
    return 0.50
endfunction


// Conditions


function crai_AbilityCondition takes nothing returns boolean
    return (crai_Code() == GetSpellAbilityId())
endfunction

function crai_TargetConditions takes nothing returns boolean
    local unit u = GetFilterUnit()

    if(IsUnitType(u, UNIT_TYPE_FLYING)) then
        return false
    endif
    if(IsUnitAlly(u, GetOwningPlayer(bj_lastReplacedUnit)))then
        return false
    endif
    if(IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)) then
        return false
    endif
    if(IsUnitType(u, UNIT_TYPE_DEAD)) then
        return false
    endif

    return true
endfunction

function crai_EnumDestructablesInCircleFilter takes nothing returns boolean
    
    local location destLoc = GetDestructableLoc(GetFilterDestructable())

    local boolean result


    set result = DistanceBetweenPoints(destLoc, bj_enumDestructableCenter) <= bj_enumDestructableRadius and (GetDestructableLife(GetFilterDestructable()) >= 0.1)

    call RemoveLocation(destLoc)
    set destLoc = null

    return result
endfunction



// Actions

function crai_GetAngleOfReflection takes real ballXVel, real ballYVel, real impactX, real impactY, real centerX, real centerY returns real

        local real ballDirection = Atan(ballYVel / ballXVel)
        local real normalDirection = Atan( (impactX - centerX) / (impactY - centerY) )
        local real incidenceAngle = normalDirection - ballDirection
        local real reflectedAngle = normalDirection + incidenceAngle

        return reflectedAngle / bj_DEGTORAD

endfunction

function crai_GetClosestDestructable takes nothing returns nothing
    local destructable d = GetEnumDestructable()

    if( bj_lastDyingWidget != null ) then
        if( Distance( GetWidgetX(d), GetWidgetY(d), GetLocationX(bj_enumDestructableCenter), GetLocationY(bj_enumDestructableCenter) ) < bj_randomSubGroupChance ) then
            set bj_randomSubGroupChance = Distance( GetWidgetX(d), GetWidgetY(d), GetLocationX(bj_enumDestructableCenter), GetLocationY(bj_enumDestructableCenter) )
            set bj_lastDyingWidget = d
        endif
    elseif( bj_lastDyingWidget == null )then
        set bj_randomSubGroupChance = Distance( GetWidgetX(d), GetWidgetY(d), GetLocationX(bj_enumDestructableCenter), GetLocationY(bj_enumDestructableCenter) )
        set bj_lastDyingWidget = d
    endif

    set d = null

endfunction

function crai_EnumDestructablesInCircle takes real radius, location loc returns nothing
    local rect r
    local boolexpr bx = Condition(function crai_EnumDestructablesInCircleFilter)

    if (radius >= 0) then
        set bj_enumDestructableCenter = loc
        set bj_enumDestructableRadius = radius
        set r = GetRectFromCircleBJ(loc, radius)

        call EnumDestructablesInRect(r, bx, function crai_GetClosestDestructable)
    
        call RemoveRect(r)
    endif

    call RemoveLocation(loc)
    call DestroyBoolExpr(bx)
    set bx = null
    set r = null
    set loc = null
endfunction

function crai_OrbCleanUp takes unit u returns nothing
    call GroupRemoveUnit(GetHandleGroup(u, "crai_Missiles"), u)
    call DestroyEffect(GetHandleEffect(u, "crai_MissileEffect0"))
    call DestroyEffect(GetHandleEffect(u, "crai_MissileEffect1"))
    call DestroyEffect(AddSpecialEffect(crai_ImpactEffect0(), GetUnitX(u), GetUnitY(u)))
    call FlushStoredMission(LocalVars(), I2S(H2I(u)))
    call PolledWait(0.01)
    call RemoveUnit(u)

    set u = null
endfunction

function crai_OrbCleanUpEnum takes nothing returns nothing
    local unit u = GetEnumUnit()

    call GroupRemoveUnit(GetHandleGroup(u, "crai_Missiles"), u)
    call DestroyEffect(GetHandleEffect(u, "crai_MissileEffect0"))
    call DestroyEffect(GetHandleEffect(u, "crai_MissileEffect1"))
    call DestroyEffect(AddSpecialEffect(crai_ImpactEffect0(), GetUnitX(u), GetUnitY(u)))
    call FlushStoredMission(LocalVars(), I2S(H2I(u)))
    call PolledWait(0.01)
    call RemoveUnit(u)

    set u = null
endfunction

function crai_GetClosestWidget takes unit u, real r returns widget

    local group tempgroup = CreateGroup()
    local unit tempunit
    local boolexpr bx
    local real UnitX = GetUnitX(u)
    local real UnitY = GetUnitY(u)

    set bj_randomSubGroupChance = 0
    set bj_lastDyingWidget = null

    call crai_EnumDestructablesInCircle(r, Location(UnitX, UnitY))

    set bj_lastReplacedUnit = u
    set bx = Condition(function crai_TargetConditions)

    call GroupEnumUnitsInRange(tempgroup, UnitX, UnitY, r, bx)

    loop
        exitwhen (FirstOfGroup(tempgroup) == null)
        set tempunit = FirstOfGroup(tempgroup)
        if( bj_lastDyingWidget != null)then
            if( Distance( UnitX, UnitY, GetUnitX(tempunit), GetUnitY(tempunit)) < bj_randomSubGroupChance )then
                set bj_randomSubGroupChance = Distance( UnitX, UnitY, GetUnitX(tempunit), GetUnitY(tempunit))
                set bj_lastDyingWidget = tempunit
            endif
        else
            set bj_randomSubGroupChance = Distance( UnitX, UnitY, GetUnitX(tempunit), GetUnitY(tempunit))
            set bj_lastDyingWidget = tempunit
        endif
        call GroupRemoveUnit(tempgroup, tempunit)
    endloop


    call GroupClear(tempgroup)
    call DestroyGroup(tempgroup)
    set tempgroup = null
    set tempunit = null
    call DestroyBoolExpr(bx)
    set bx = null

    return bj_lastDyingWidget
endfunction

function crai_MoveAction takes nothing returns nothing
    local unit u = GetEnumUnit()
    local unit u2
    local group g = I2G(GetStoredInteger(LocalVars(), I2S(H2I(u)), "crai_Missiles"))
    local widget w
    local integer x = 0
    local integer source = GetStoredInteger(LocalVars(), I2S(H2I(u)), "crai_Source")
    local string b
    local real a = 0
    local real dir = GetStoredReal(LocalVars(), I2S(H2I(u)), "crai_Direction")
    local real dur = GetStoredReal(LocalVars(), I2S(H2I(u)), "crai_Duration")
    local real fac = GetStoredReal(LocalVars(), I2S(H2I(u)), "crai_Factor")
    local boolean hitx = false
    local boolean hity = false
    local location loc1
    local location loc2

    set a = GetUnitX(u) + crai_MissileVelocity()*0.04*Cos(dir*bj_DEGTORAD)
    if((a < GetRectMaxX(bj_mapInitialPlayableArea)) and (a > GetRectMinX(bj_mapInitialPlayableArea)))then
        call SetUnitX(u, GetUnitX(u) + crai_MissileVelocity()*0.04*Cos(dir*bj_DEGTORAD))
    else
        set hitx = true    
    endif
    set a = GetUnitY(u) + crai_MissileVelocity()*0.04*Sin(dir*bj_DEGTORAD)
    if((a < GetRectMaxY(bj_mapInitialPlayableArea)) and (a > GetRectMinY(bj_mapInitialPlayableArea)))then
        call SetUnitY(u, GetUnitY(u) + crai_MissileVelocity()*0.04*Sin(dir*bj_DEGTORAD))
    else
        set hity = true
    endif

    if(hitx and not hity)then
        if(dir > 0 and dir < 90)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 180 - dir)
        elseif(dir > 90 and dir < 180)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 0 + (180-dir))
        elseif(dir > 180 and dir < 270)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 270 + (270-dir))
        elseif(dir > 270 and dir < 360)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 180 + (360-dir))
        else
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", dir + 180)
        endif

    elseif(hitx and hity) then
        call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", dir + 180)
    elseif(not hitx and hity) then
        if(dir > 0 and dir < 90)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 360 - dir)
        elseif(dir > 90 and dir < 180)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 180 + (180-dir))
        elseif(dir > 180 and dir < 270)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 90 + (270-dir))
        elseif(dir > 270 and dir < 360)then
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", 0 + (360-dir))
        else
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", dir + 180)
        endif

    endif

    set w = crai_GetClosestWidget(u, crai_CollisionRadius())

    if(w != null)then
//		call DB("HIT!: " + R2S(bj_randomSubGroupChance))
    call DestroyEffect(AddSpecialEffect(crai_MissileEffect1(), GetUnitX(u), GetUnitY(u)))
    call DestroyEffect(AddSpecialEffect(crai_ImpactEffect0(), GetUnitX(u), GetUnitY(u)))

    call UnitDamageTarget(I2U(source), w, fac * crai_DamagePerMissile(), false, true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_NORMAL, null)
        set a = crai_GetAngleOfReflection( Cos(dir*bj_DEGTORAD), Sin(dir*bj_DEGTORAD), GetUnitX(u), GetUnitY(u), GetWidgetX(w), GetWidgetY(w))

        if(GetRandomReal(0.00,1.00) < (((fac*fac)/(crai_DamageFactorMax()+(1.5*fac)))-0.2) and not GetStoredBoolean(LocalVars(), I2S(H2I(u)), "crai_AlreadySplit"))then        //SPLITTING
            if(GetRandomReal(0.00,1.00) < (((fac*fac)/(crai_DamageFactorMax()+(1.5*fac)))-0.2))then    //ThreeWay
                set x = 0
                loop
                    exitwhen x == 3
                    set u2 = CreateUnit(GetOwningPlayer(u), crai_DummyCode(), GetUnitX(u), GetUnitY(u), 0.)
                    set b = I2S(H2I(u2))
                    call StoreInteger(LocalVars(), b, "crai_Missiles", H2I(g))
                    call StoreInteger(LocalVars(), b, "crai_Source", source)
                    call StoreInteger(LocalVars(), b, "crai_MissileEffect0", H2I(AddSpecialEffectTarget(crai_MissileEffect0(), u2, "origin")))
                    call StoreInteger(LocalVars(), b, "crai_MissileEffect1", H2I(AddSpecialEffectTarget(crai_MissileEffect1(), u2, "origin")))
                    call StoreBoolean(LocalVars(), b, "crai_AlreadySplit", true)
                    call StoreReal(LocalVars(), b, "crai_Factor", fac*0.5)
                    call SetUnitScale(u, GetStoredReal(LocalVars(), b, "crai_Factor"), GetStoredReal(LocalVars(), b, "crai_Factor"), GetStoredReal(LocalVars(), b, "crai_Factor"))
                    call StoreReal(LocalVars(), b, "crai_Direction", (a + GetRandomReal(-crai_AngularOffset(),crai_AngularOffset())) )
                    call StoreReal(LocalVars(), b, "crai_Duration", dur) 
                    call GroupAddUnit(g, u2)
                    set x = x + 1
                endloop
                set dur = 0.00
            else                                            //TwoWay
                set x = 0
                loop
                    exitwhen x == 2
                    set u2 = CreateUnit(GetOwningPlayer(u), crai_DummyCode(), GetUnitX(u), GetUnitY(u), 0.)
                    set b = I2S(H2I(u2))
                    call StoreInteger(LocalVars(), b, "crai_Missiles", H2I(g))
                    call StoreInteger(LocalVars(), b, "crai_Source", source)
                    call StoreInteger(LocalVars(), b, "crai_MissileEffect0", H2I(AddSpecialEffectTarget(crai_MissileEffect0(), u2, "origin")))
                    call StoreInteger(LocalVars(), b, "crai_MissileEffect1", H2I(AddSpecialEffectTarget(crai_MissileEffect1(), u2, "origin")))
                    call StoreBoolean(LocalVars(), b, "crai_AlreadySplit", true)
                    call StoreReal(LocalVars(), b, "crai_Factor", fac*0.8)
                    call SetUnitScale(u, GetStoredReal(LocalVars(), b, "crai_Factor"), GetStoredReal(LocalVars(), b, "crai_Factor"), GetStoredReal(LocalVars(), b, "crai_Factor"))
                    call StoreReal(LocalVars(), b, "crai_Direction", (a + GetRandomReal(-crai_AngularOffset(),crai_AngularOffset())) )
                    call StoreReal(LocalVars(), b, "crai_Duration", dur) 
                    call GroupAddUnit(g, u2)
                    set x = x + 1
                endloop
                set dur = 0.00
            endif
        else
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Direction", a)
            call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Factor", fac - 0.1)
            if(fac - 0.1 <= 0.30)then
                set dur = 0.0
            endif
        endif
    endif

    call StoreReal(LocalVars(), I2S(H2I(u)), "crai_Duration", dur - 0.04)

    if(dur - 0.04 < 0.0)then
        call crai_OrbCleanUp(u)
    endif

    set u = null
    set u2 = null
    set g = null
    set w = null

endfunction

function crai_MoveTimerAction takes nothing returns nothing
    
    local integer t = H2I(GetExpiredTimer())
    local group g = I2G(GetStoredInteger(LocalVars(), I2S(t), "crai_Missiles"))


    if(GetStoredBoolean(LocalVars(), I2S(t), "crai_Off") and (crai_EndChannelStopsMissiles() or FirstOfGroup(g) == null))then
        call ForGroup(g, function crai_OrbCleanUpEnum)
        call FlushStoredMission(LocalVars(), I2S(t))
        call DestroyTimer(I2Ti(t))
        call GroupClear(g)
        call DestroyGroup(g)
        set g = null
    endif


    call ForGroup(g, function crai_MoveAction)
    set g = null

endfunction

function crai_SequenceRelease takes nothing returns nothing

    local integer t = H2I(GetExpiredTimer())
    local integer i = GetStoredInteger(LocalVars(), I2S(t), "crai_Iterations")
    local string a
    local real dir = GetStoredReal(LocalVars(), I2S(t), "crai_Direction")
    local real diro = GetRandomReal(-crai_AngularOffset(),crai_AngularOffset())
    local group g = I2G(GetStoredInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_MissileTimer")), "crai_Missiles"))
    local unit s = I2U(GetStoredInteger(LocalVars(), I2S(t), "crai_Source"))
    local unit u

    if(g == null)then
        call StoreInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_MissileTimer")), "crai_Missiles", H2I(CreateGroup()))
        set g = I2G(GetStoredInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_MissileTimer")), "crai_Missiles" ))
    endif

    set u = CreateUnit(GetOwningPlayer(s), crai_DummyCode(), GetUnitX(s) + crai_Offset()*Cos((dir+diro)*bj_DEGTORAD), GetUnitY(s) + crai_Offset()*Sin((dir+diro)*bj_DEGTORAD), 0.)
    set a = I2S(H2I(u))
    call StoreInteger(LocalVars(), a, "crai_Missiles", H2I(g))
    call StoreInteger(LocalVars(), a, "crai_Source", H2I(s))
    call StoreInteger(LocalVars(), a, "crai_MissileEffect0", H2I(AddSpecialEffectTarget(crai_MissileEffect0(), u, "origin")))
    call StoreInteger(LocalVars(), a, "crai_MissileEffect1", H2I(AddSpecialEffectTarget(crai_MissileEffect1(), u, "origin")))
    call StoreReal(LocalVars(), a, "crai_Factor", GetRandomReal(crai_DamageFactorMin(),crai_DamageFactorMax()))
    call SetUnitScale(u, GetStoredReal(LocalVars(), a, "crai_Factor"), GetStoredReal(LocalVars(), a, "crai_Factor"), GetStoredReal(LocalVars(), a, "crai_Factor"))
    call StoreReal(LocalVars(), a, "crai_Direction", (dir + (diro)*crai_RecenteringValue()) )
    call StoreReal(LocalVars(), a, "crai_Duration", crai_MissileDuration()) 
    call GroupAddUnit(g, u)

    if((i - 1)>0)then
        call StoreInteger(LocalVars(), I2S(t), "crai_Iterations", i - 1)
        call TimerStart( I2Ti(t), crai_SprayInterval(), false, function crai_SequenceRelease )
    endif

    set g = null
    set s = null
    set u = null

endfunction

function crai_WaveAction takes nothing returns nothing

    local integer t = H2I(GetExpiredTimer())
    local integer x = 0
    local string a
    local integer l = GetStoredInteger(LocalVars(), I2S(t), "crai_Level")    
    local real dir = GetStoredReal(LocalVars(), I2S(t), "crai_Direction")
    local real dirb
    local unit s = I2U(GetStoredInteger(LocalVars(), I2S(t), "crai_Source"))
    local unit u
    local group g = I2G(GetStoredInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_MissileTimer")), "crai_Missiles" ))
    local boolean off = false

    if(GetStoredBoolean(LocalVars(), I2S(GetStoredInteger(LocalVars(),I2S(t), "crai_Source")), "crai_Off"))then
        call StoreBoolean(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_MissileTimer")), "crai_Off", true)
        call FlushStoredBoolean(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_Source")), "crai_Off")
        call FlushStoredMission(LocalVars(), I2S(t))
        set off = true
        call DestroyTimer(GetExpiredTimer())
    endif

    if(g == null)then
        call StoreInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_MissileTimer")), "crai_Missiles", H2I(CreateGroup()))
        set g = I2G(GetStoredInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_MissileTimer")), "crai_Missiles" ))
    endif

    if(crai_SprayMethod()==0 and not off)then
        loop
            exitwhen x == crai_PerWaveByLevel(l)
            set dirb =  (dir + crai_AngularOffset() - ((x / (crai_PerWaveByLevel(l) - 1.0)) * 2 * crai_AngularOffset()))
            set u = CreateUnit(GetOwningPlayer(s), crai_DummyCode(), GetUnitX(s) + crai_Offset()*Cos(dirb*bj_DEGTORAD), GetUnitY(s) + crai_Offset()*Sin(dirb*bj_DEGTORAD), 0.)
            set a = I2S(H2I(u))
            call StoreInteger(LocalVars(), a, "crai_Source", H2I(s))
            call StoreInteger(LocalVars(), a, "crai_Missiles", H2I(g))
            call StoreInteger(LocalVars(), a, "crai_MissileEffect0", H2I(AddSpecialEffectTarget(crai_MissileEffect0(), u, "origin")))
            call StoreInteger(LocalVars(), a, "crai_MissileEffect1", H2I(AddSpecialEffectTarget(crai_MissileEffect1(), u, "origin")))
            call StoreReal(LocalVars(), a, "crai_Factor", GetRandomReal(crai_DamageFactorMin(),crai_DamageFactorMax()))
            call SetUnitScale(u, GetStoredReal(LocalVars(), a, "crai_Factor"), GetStoredReal(LocalVars(), a, "crai_Factor"), GetStoredReal(LocalVars(), a, "crai_Factor"))
            call StoreReal(LocalVars(), a, "crai_Direction", (dir + (crai_AngularOffset() - ((x / (crai_PerWaveByLevel(l) - 1.0)) * 2 * crai_AngularOffset()))*crai_RecenteringValue() ))
            call StoreReal(LocalVars(), a, "crai_Duration", crai_MissileDuration())
            call GroupAddUnit(g, u)
            set x = x + 1
        endloop
    elseif(crai_SprayMethod()==1 and not off)then
        call StoreInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_SequentialSpawnTimer")), "crai_Iterations", crai_PerWaveByLevel(l))
        call TimerStart(I2Ti(GetStoredInteger(LocalVars(), I2S(t), "crai_SequentialSpawnTimer")), 0.01, false, function crai_SequenceRelease)
    elseif(crai_SprayMethod()==2 and not off)then
        if(GetRandomReal(0.0,1.0) <= crai_SpraySequentialChance())then
            call StoreInteger(LocalVars(), I2S(GetStoredInteger(LocalVars(), I2S(t), "crai_SequentialSpawnTimer")), "crai_Iterations", crai_PerWaveByLevel(l))
            call TimerStart(I2Ti(GetStoredInteger(LocalVars(), I2S(t), "crai_SequentialSpawnTimer")), 0.01, false, function crai_SequenceRelease)
        else
            loop
                exitwhen x == crai_PerWaveByLevel(l)
                set dirb =  (dir + crai_AngularOffset() - ((x / (crai_PerWaveByLevel(l) - 1.0)) * 2 * crai_AngularOffset()))
                set u = CreateUnit(GetOwningPlayer(s), crai_DummyCode(), GetUnitX(s) + crai_Offset()*Cos(dirb*bj_DEGTORAD), GetUnitY(s) + crai_Offset()*Sin(dirb*bj_DEGTORAD), 0.)
                set a = I2S(H2I(u))
                call StoreInteger(LocalVars(), a, "crai_Source", H2I(s))
                call StoreInteger(LocalVars(), a, "crai_Missiles", H2I(g))
                call StoreInteger(LocalVars(), a, "crai_MissileEffect0", H2I(AddSpecialEffectTarget(crai_MissileEffect0(), u, "origin")))
                call StoreInteger(LocalVars(), a, "crai_MissileEffect1", H2I(AddSpecialEffectTarget(crai_MissileEffect1(), u, "origin")))
                call StoreReal(LocalVars(), a, "crai_Factor", GetRandomReal(crai_DamageFactorMin(),crai_DamageFactorMax()))
                call SetUnitScale(u, GetStoredReal(LocalVars(), a, "crai_Factor"), GetStoredReal(LocalVars(), a, "crai_Factor"), GetStoredReal(LocalVars(), a, "crai_Factor"))
                call StoreReal(LocalVars(), a, "crai_Direction", (dir + (crai_AngularOffset() - ((x / (crai_PerWaveByLevel(l) - 1.0)) * 2 * crai_AngularOffset()))*crai_RecenteringValue() ))
                call StoreReal(LocalVars(), a, "crai_Duration", crai_MissileDuration())
                call GroupAddUnit(g, u)
                set x = x + 1
            endloop
        endif
    endif
    
    set s = null
    set u = null
    set g = null

endfunction

function crai_Actions takes nothing returns nothing
    local unit source = GetSpellAbilityUnit()
    local location target = GetSpellTargetLoc()
    local location srcloc = Location(GetUnitX(source), GetUnitY(source))
    local real dir = GetUnitFacing( source )
    local string s = I2S(H2I(CreateTimer()))        //Waves
    local integer t2 = H2I(CreateTimer())            //Mover
    local integer t3 = H2I(CreateTimer())            //SequentialTimer

    call StoreInteger(LocalVars(), s, "crai_MissileTimer", t2)
    call StoreReal(LocalVars(), s, "crai_Direction", dir)
    call StoreInteger(LocalVars(), s, "crai_Source", H2I(source))
    call StoreInteger(LocalVars(), s, "crai_Level", GetUnitAbilityLevel(source, crai_Code()))

    if(crai_SprayMethod()!=0)then
        call StoreInteger(LocalVars(), s, "crai_SequentialSpawnTimer", t3)
        call StoreInteger(LocalVars(), I2S(t3), "crai_MissileTimer", t2)
        call StoreReal(LocalVars(), I2S(t3), "crai_Direction", dir)
        call StoreInteger(LocalVars(), I2S(t3), "crai_Level", GetUnitAbilityLevel(source, crai_Code()))
        call StoreInteger(LocalVars(), I2S(t3), "crai_Source", H2I(source))
    else
        call DestroyTimer(I2Ti(t3))
    endif

    call StoreInteger(LocalVars(), I2S(t2), "crai_WaveTimer", S2I(s))
    call StoreInteger(LocalVars(), I2S(t2), "crai_Missiles", H2I(CreateGroup()))
    call StoreInteger(LocalVars(), I2S(t2), "crai_Source", H2I(source))

    call TimerStart( I2Ti(S2I(s)), crai_WaveInterval(), true, function crai_WaveAction )
    call TimerStart( I2Ti(t2), 0.04, true, function crai_MoveTimerAction )

    call RemoveLocation(target)
    call RemoveLocation(srcloc)
    set target = null
    set srcloc = null
    set source = null

endfunction

function crai_CancelActions takes nothing returns nothing
    call StoreBoolean(LocalVars(), I2S(H2I(GetTriggerUnit())), "crai_Off", true)
endfunction

//===========================================================================
function InitTrig_Cerulean_Storm takes nothing returns nothing

    local trigger crai_CancelTrigger = CreateTrigger( )
    set gg_trg_Cerulean_Storm = CreateTrigger(  )


    call TriggerAddAction( gg_trg_Cerulean_Storm, function crai_Actions )
    call TriggerAddAction( crai_CancelTrigger, function crai_CancelActions )
    call TriggerAddCondition( gg_trg_Cerulean_Storm, Condition(function crai_AbilityCondition))
    call TriggerAddCondition( crai_CancelTrigger, Condition(function crai_AbilityCondition))
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Cerulean_Storm, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerRegisterAnyUnitEventBJ( crai_CancelTrigger, EVENT_PLAYER_UNIT_SPELL_ENDCAST )
endfunction
08-25-2007, 04:26 PM#2
darkwulfv
Well, real quick, check for any infinite loops, as those (with massive SFX) will lock any game in a split second.

It could also either be leaks, or just system intensive coding. I don't know, I didn't look through the code.
08-25-2007, 06:59 PM#3
NightBreeze
Have you done any sort of debugging? Like putting messages in the timers to see how often they run .. or to check up to which part of the code everything goes smoothly? Please understand that it's a lot of work for me to microscope the code until I understand what everything is doing ^^ It's easier to get some sort of a direction or hint as to where the problem may be.

Maybe post the map?

Editnotes (details as well!):

- You should null the unit variable before returning in crai_TargetConditions.
- You could make the constant functions constant.
- You should put the period of the MoveTimer in a constant function as well.

Too much work to try and follow all the storing inside the timer callbacks, maybe tomorrow :P
08-26-2007, 12:10 AM#4
botanic
the spell works just when I get to a higher level and more sfx are created that are larger the game almost locks up

for the map goto http://www.mediafire.com/?1n0rxfyrdld and pick the shape shifter hero (the avatar of vengeance in the top left) he has the spell

PS about the constant functions i just removed all the constants because they were bugging the spell. I will add them in later again ;)
08-26-2007, 12:40 AM#5
TaintedReality
Sooo make less effects =D.
08-26-2007, 06:11 AM#6
botanic
I was hoping that there was something that was wrong in the script that made it function slower :/ i know i could just make less... thats easy just I would like to not do that if at all possible
08-26-2007, 09:53 AM#7
NightBreeze
Are you completely sure it's the effects? How about you ONLY decrease the number of effects created and see if it still bugs at a high level? It doesn't seem likely that 30 effects will lock up the game. Oh and how does the locking up occur? Does the lag increase with each level? Does the lock up only last a few seconds? Is the lock up gone when the effects are gone (when the spell is done)?
08-26-2007, 10:42 PM#8
botanic
A) i have reduced the number and it causes it to not lagg it to heck

B) I have reduced the scale value and it causes it to not lagg to heck

C) I agree that 30 effects shouldnt lag the game

D)The lag increases with level

E) the lag only lasts for the duration of the channel ( i can stop it early)

F) the lockup goes away after i cancel the spell :/
08-28-2007, 07:08 AM#9
botanic
i think it has been long enough *bump* :/