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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage

      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