Removing Lightning Effects

Crusher

You can change this now in User CP.
Reaction score
121
In this trigger, when the caster is knocked back, the lightning effects stay on the position of caster, eg. previous casting location, but they aren't removed. So, I thought maybe the solution is to add additional line of function which will check if the caster stopped channeling a spell, but the problem is: I don't know to JASS that!

If anyone could help or you have any other possibilities to fix this, please reply here at this very thread.

JASS:
//******************************************************************************
//*                                                                            *
//*                               Quench Life                                  *
//*                                  v1.02                                     *
//*                                                                            *
//*                             By: Rising_Dusk                                *
//*                                                                            *
//******************************************************************************

//**************************************
//* LIBRARY REQUIREMENTS:
//*     - GroupUtils
//*     - UnitIndexingUtils
//* 
scope QuenchLife initializer Init
globals
    //*************************************************************
    //* Configuration Constants
    
    //* Raw codes
    private constant integer SPELL_ID              = 'A03O'
    private constant integer DUMMY_ID              = 'h012'
    private constant string ORDER_STRING           = "starfall"
    //* Lightning related
    private constant integer LIGHTNING_COUNT       = 6
    private constant integer LIGHTNING_TO_GO_LEFT  = 3
    private constant string LIGHTNING_TYPE         = "DRAL"
    private constant real LIGHTNING_Z_OFFSET       = 450.
    private constant real LIGHTNING_ANGLE_OFFSET   = 2*bj_PI/3
    private constant real LIGHTNING_ANGLE_SHIFT    = bj_PI/40
    //* Spell related
    private constant real AREA_OF_EFFECT           = 600.
    //* Damage properties
    private constant attacktype ATTACK_TYPE        = ATTACK_TYPE_NORMAL
    private constant damagetype DAMAGE_TYPE        = DAMAGE_TYPE_UNIVERSAL
    //* System related
    private constant real TIMER_INTERVAL           = 0.10
    private constant integer ITERATIONS_TIL_EFFECT = 5
    //* Effect placement
    private constant string EFFECT_POINT           = "origin"
    
    //*************************************************************
    //* System Variables
    private group CastGroup                        = CreateGroup()
    private timer ScanTimer                        = CreateTimer()
    private player TempPlayer                      = null
    private boolexpr HealChecker                   = null
    private boolexpr DamageChecker                 = null
    private integer array Glowies
    private trigger Trg                            = CreateTrigger()
endglobals

//*****************************************************************
//* Configuration Functions
private constant function LifeStolen takes integer lvl returns real
    //* Life stolen per second
    return 9.
endfunction

private function EndConditions takes unit u, integer lvl returns boolean
    //* Conditions that bring about the spell's end
    //* Returns false if conditions not met
    return GetUnitCurrentOrder(u) != OrderId(ORDER_STRING)
endfunction

private function DamageCheck takes nothing returns boolean
    //* Boolean expression for which units to damage
    return IsUnitEnemy(GetFilterUnit(), TempPlayer) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and GetWidgetLife(GetFilterUnit()) > 0.405 and GetUnitAbilityLevel(GetFilterUnit(), 'Avul') <= 0.
endfunction

private function HealCheck takes nothing returns boolean
    //* Boolean expression for which units to heal
    return IsUnitAlly(GetFilterUnit(), TempPlayer) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) and GetWidgetLife(GetFilterUnit()) > 0.405 and GetUnitAbilityLevel(GetFilterUnit(), 'Avul') <= 0.
endfunction

//*****************************************************************
private struct glowyhax
    lightning array orbital[4]
    integer level              = 0
    integer index              = 0
    unit attach                = null
    real angle1                = 0. 
    real angle2                = 0.
    
    static method create takes unit u returns glowyhax
        local glowyhax g = glowyhax.allocate()
        local integer i  = 1
        local real x     = GetUnitX(u)
        local real y     = GetUnitY(u)
        set g.attach     = CreateUnit(GetOwningPlayer(u), DUMMY_ID, x, y, 0.)
        set g.level      = GetUnitAbilityLevel(u, SPELL_ID)
        set g.angle1     = GetUnitFacing(u)*bj_DEGTORAD
        set g.angle2     = g.angle1 + bj_PI/2
        if IsUnitType(g.attach, UNIT_TYPE_GROUND) then
            call UnitAddAbility(g.attach, 'Amrf')
            call UnitRemoveAbility(g.attach, 'Amrf')
        endif
        call SetUnitFlyHeight(g.attach, LIGHTNING_Z_OFFSET, 0.)
        call PauseUnit(g.attach, true)
        call SetUnitX(g.attach, x)
        call SetUnitY(g.attach, y)
        loop
            exitwhen i > LIGHTNING_COUNT
            set g.orbital<i> = null
            set i = i + 1
        endloop
        return g
    endmethod
    private method onDestroy takes nothing returns nothing
        local integer i  = 1
        //* Clean up all lightning effects
        loop
            exitwhen i &gt; LIGHTNING_COUNT
            call DestroyLightning(this.orbital<i>)
            set i = i + 1
        endloop
        call KillUnit(this.attach)
    endmethod
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function Enumeration takes nothing returns nothing
    local unit e      = GetEnumUnit()
    local unit s      = null
    local integer id  = GetUnitId(e)
    local glowyhax g  = Glowies[id]
    local integer lvl = g.level
    local integer i   = 1
    local location l  = GetUnitLoc(e)
    local real dmg    = LifeStolen(lvl)
    local real xi     = GetLocationX(l)
    local real yi     = GetLocationY(l)
    local real zi     = GetLocationZ(l)
    local real xf     = 0.
    local real yf     = 0.
    local real zf     = 0.
    local real a      = g.angle1
    local real r      = 0.
    
    //* Do stuff for the channeled ability&#039;s visual
    call RemoveLocation(l)
    loop
        exitwhen i &gt; LIGHTNING_COUNT
        //* Do some projections
        set xf = xi + AREA_OF_EFFECT*Cos(a)
        set yf = yi + AREA_OF_EFFECT*Sin(a)
        set l  = Location(xf, yf)
        set zf = GetLocationZ(l)
        call RemoveLocation(l)
        
        //* Move the lightning effect
        if g.orbital<i> != null then
            call MoveLightningEx(g.orbital<i>, true, xi, yi, LIGHTNING_Z_OFFSET+zi, xf, yf, zf)
        else
            set g.orbital<i> = AddLightningEx(LIGHTNING_TYPE, true, xi, yi, LIGHTNING_Z_OFFSET+zi, xf, yf, zf)
        endif
        call DestroyEffect(AddSpellEffectTargetById(SPELL_ID, EFFECT_TYPE_EFFECT, g.attach, &quot;origin&quot;))
        call DestroyEffect(AddSpellEffectById(SPELL_ID, EFFECT_TYPE_EFFECT, xf, yf))
        
        //* Update the angle of the rotation properly
        if i &lt; LIGHTNING_TO_GO_LEFT then
            set a = a - LIGHTNING_ANGLE_OFFSET
        elseif i == LIGHTNING_TO_GO_LEFT then
            set a = g.angle2
        elseif i &gt; LIGHTNING_TO_GO_LEFT then
            set a = a + LIGHTNING_ANGLE_OFFSET
        endif
        set i = i + 1
    endloop
    set g.angle1 = g.angle1 + LIGHTNING_ANGLE_SHIFT
    set g.angle2 = g.angle2 - LIGHTNING_ANGLE_SHIFT
    set g.index  = g.index + 1
    
    //* Don&#039;t forget to have the ability actually do something useful
    set TempPlayer = GetOwningPlayer(e)
    call GroupEnumUnitsInRange(ENUM_GROUP, xi, yi, AREA_OF_EFFECT, DamageChecker)
    loop
        set s = FirstOfGroup(ENUM_GROUP)
        exitwhen s == null
        if ModuloInteger(g.index, ITERATIONS_TIL_EFFECT) == 0 then
            call DestroyEffect(AddSpellEffectTargetById(SPELL_ID, EFFECT_TYPE_TARGET, s, EFFECT_POINT))
        endif
        call UnitDamageTarget(e, s, dmg*TIMER_INTERVAL, false, false, ATTACK_TYPE, DAMAGE_TYPE, null)
        set r = r + dmg*TIMER_INTERVAL
        call GroupRemoveUnit(ENUM_GROUP, s)
    endloop
    //* Now distribute the life evenly to allies
    call GroupEnumUnitsInRange(ENUM_GROUP, xi, yi, AREA_OF_EFFECT, HealChecker)
    if FirstOfGroup(ENUM_GROUP) != null and r &gt; 0. then
        //* Make sure no divide by zero or bad stuff
        set bj_groupCountUnits = 0
        call ForGroup(ENUM_GROUP, function CountUnitsInGroupEnum)
        set r = r / bj_groupCountUnits
        loop
            set s = FirstOfGroup(ENUM_GROUP)
            exitwhen s == null
            if ModuloInteger(g.index, ITERATIONS_TIL_EFFECT) == 0 then
                call DestroyEffect(AddSpellEffectTargetById(SPELL_ID, EFFECT_TYPE_SPECIAL, s, EFFECT_POINT))
            endif
            call SetWidgetLife(s, GetWidgetLife(s) + dmg)
            call GroupRemoveUnit(ENUM_GROUP, s)
        endloop
    endif
    
    //* Check duration and do stuff if spell is over
    if EndConditions(e, lvl) then
        call GroupRemoveUnit(CastGroup, e)
        call g.destroy()
    endif
    
    call GroupClear(ENUM_GROUP)
    set e  = null
    set s  = null
    set l  = null
endfunction

private function Callback takes nothing returns nothing
    call ForGroup(CastGroup, function Enumeration)
    if FirstOfGroup(CastGroup) == null then
        call PauseTimer(ScanTimer)
    endif
endfunction

private function Actions takes nothing returns nothing
    local unit u      = GetTriggerUnit()
    local integer id  = GetUnitId(u)
    local glowyhax g  = glowyhax.create(u)
    
    //* Load caster to group for enumeration
    if FirstOfGroup(CastGroup) == null then
        call TimerStart(ScanTimer, TIMER_INTERVAL, true, function Callback)
    endif
    call GroupAddUnit(CastGroup, u)
    set Glowies[id] = g
    
    set u = null
endfunction

private function Init takes nothing returns nothing
    call TriggerAddAction(Trg, function Actions)
    call TriggerAddCondition(Trg, Condition(function Conditions))
    call TriggerRegisterAnyUnitEventBJ(Trg, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    set DamageChecker = Condition(function DamageCheck)
    set HealChecker   = Condition(function HealCheck)
endfunction
endscope

</i></i></i></i></i>
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
UnitIndexingUtils? What's that? A really old wc3c unit indexing system?
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
UnitIndexingUtils? What's that? A really old wc3c unit indexing system?
No.. it is newer than PUI. It is written by Rising_Dusk.
 

Crusher

You can change this now in User CP.
Reaction score
121
I was asking about my problem, not about UnitIndexing age.
 

Laiev

Hey Listen!!
Reaction score
188
the only way to 'move' a lightning effect is destroying it and then create a new in the new position of the caster/target/whatever (i don't remember if has some function to move the effect, probably yes)

but how do this..

create a timer and create lightning effect every 0,5 sec or 0,4 and remove then after and when ability over/stop cast, stop the timer

a suggestion is, use TimerUtils
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top