System TimedLightning

Flare

Stops copies me!
Reaction score
662
This is a system I created, which consists of a number of functions used for creating lightning effects very easily in a number of different ways:
  • Between 2 units
  • Between 2 locations
  • Between 2 XYZ coordinates
  • In an expanding/contracting ring around an XYZ coordinate
  • Same as above, expect with a location instead of XYZ
  • Between an XYZ coordinate and a unit
  • Between a location and a unit

Main reasoning behind making this was because I have always found lightning effects to be a pain in the ass to get working, and have always wanted a simpler method of doing it :)

Technical details:
Made in vJASS
MUI
Not laggy (for me anyway)
I don't think there is a leak (except for the test trigger, but that doesn't matter :p)
Uses Cohadar's Timer Ticker system
Requires NewGen WE

Importing guidelines
Code:
If you do not already have TT 3.4, copy and paste the TT trigger into your map.

Copy the TimedLightning trigger into your map
[size="1"]Alternatively, copy the whole 'Copy me' category into your map if you don't have Timer Ticker[/size]

Use the functions as you wish

What does this system do?
JASS:
//What does this system do?
//------------------------------\\
//This generates a lightning effect, to the end-user's specifications between 2 units
//This lightning effect will fade over the specified time period, and will 'track' both units movement
//The fade effect automatically adjusts to the duration of the lightning
//i.e. If the lightning is set to last 5 seconds, it will be visible for that 5 seconds


Why use this system?
JASS:
//Why use this system?
//------------------------------\\
//From my search, there isn't a system which serves the same purpose (unless I overlooked it)
//Well, if you are like me, and find lightning effects to be a pain in the ass, this simplifies the process
//Just call the function, with your lightning type, source unit, target unit, and duration.
//Then let this do all the work, while you sit back and relax


How do I use this?
Simply call the appropriate TimedLightning function like so:
JASS:
//                                      ---To use---
//Simply call the appropriate TimedLightning function like so
//-----------------------------------------------------------
call TL_Unit (lightid, sourceUnit, targetUnit, duration, fadeOn, initFade, endFade)
//Generates a lightning effect between 2 units

call TL_Loc (lightid, loc1, loc2, duration, fadeOn, initFade, endFade)
//Generates a lightning effect between 2 locations

call TL_Coord (lightid, x1, y1, z1, x2, y2, z2, duration, fadeOn, initFade, endFade)
//Generates a lightning effect between 2 sets of XYZ coordinates

call TL_Ring (lightid, lightningCount, initAngle, centerx, centery, zHeight, initRadius, endRadius, duration, fadeOn, initFade, endFade)
//Generates a ring of lightning effects which around an XYZ starting at initRadius and expands/contracts towards endRadius

call TL_RingLoc (lightid, lightningCount, initAngle, whichLoc, zHeight, initRadius, endRadius, duration, fadeOn, initFade, endFade)
//Same as TL_Ring, takes a location instead of coordinates

call TL_Coord2Unit (lightid, x, y, z, whichUnit, duration, fadeOn, initfade, endfade)
//Creates a lightning effect that is static at one XYZ position, while other end tracks the motion of specified unit

call TL_Loc2Unit (lightid, whichLoc, z, whichUnit, duration, fadeOnn, initFade, endFade)
//Same as TL_Coord2Unit, takes a location instead of coordinates


//NOTE:
//TL_Ring takes the initangle argument in RADIANS
//TL_RingLoc takes the initangle argument in DEGREES

//fadeOn is a boolean, initFade/endFade is a value between 0 and 1


Indexing:
JASS:
//ALL TimedLightning functions return an index - this index is required to use any of the modification functions
//The index of the last created TimedLightning can also be accessed through the TL_Last variable
//So, if you intend to modify any existing TimedLightning effects, keep track of the index given either by this:
set someIntegerVar = TL_WhichFunc (...)
//or
call TL_WhichFunc (...)
set someIntegerVar = TL_Last


Modification functions:
JASS:
//                                          ---Modification functions---
//NOTE: RGB values taken by any of these functions range from 0 to 1

call TL_SetNextRGB (r1, r2, g1, g2, b1, b2)
//Sets the start/end RGB values of the next TimedLightning
//This only affects the next TimedLightning/TimedLightningRing  - the function must be called again if you want to recolour another TimedLightning
//Works on Ring and non-Ring functions

call TL_Destroy (index)
//Allows you to manually destroy the lightning associated with the specified index
//Only works on non-Ring functions

call TL_DestroyRing (index)
//Allows you to manually destroy the lightning ring associated with the specified index
//Only works on Ring functions

call TL_ChangeRGB (index, r1, r2, g1, g2, b1, b2)
//Allows you to change the start/end RGB values of the lightning associated with the specified index
//Only works on non-Ring functions

call TL_ChangeRingRGB (index, r1, r2, g1, g2, b1, b2)
//Allows you to change the start/end RGB values of the lightning ring associated with the specified index
//Only works with Ring functions

call TL_ChangeSourceCoord (index, x, y, z)
//Changes the source location of the lightning associated with the specified index
//Only works with TL_Coord, TL_Loc, TL_Coord2Unit, TL_Loc2Unit

call TL_ChangeSourceLoc (index, loc, z)
//Changes the source location of the lightning associated with the specified index
//Works with same functions as TL_ChangeSourceCoord

call TL_ChangeTargetCoord (index, x, y, z)
//Changes the target location of the lightning associated with the specified index
//Only works with TL_Coord, TL_Loc

call TL_ChangeTargetLoc (index, loc, z)
//Changes the target location of the lightning associated with the specified index
//Only works with TL_Coord, TL_Loc

call TL_ChangeSourceUnit (index, u)
//Changes the source unit of the lightning associated with the specified index
//Only works with TL_Unit

call TL_ChangeTargetUnit (index, u)
//Changes the target unit of the lightning associated with the specified index
//Only works with TL_Unit, TL_Coord2Unit, TL_Loc2Unit

call ChangeRingCoord (index, x, y, z)
//Changes the centre of the lightning ring associated with the specified index
//Only works with Ring functions

call ChangeRingLoc (index, loc, z)
//Changes the centre of the lightning ring associated with the specified index
//Only works with Ring functions

call FadeEnable (index, fadeOn)
//Determines whether the lightning associated with the specified index fades/recolours or not
//Only works with non-Ring functions

call RingFadeEnable (index, fadeOn)
//Determines whether the lightning ring associated with the specified index fades/recolours or not
//Only works with Ring functions


If you are a GUI user, then do this
Code:
Custom script:   call TL_Unit ("DRAL", udg_u, udg_u2, 2., true, 0.5)
NOTE - Those variables are just an example - do NOT copy-paste this straight into your map, as it is likely to fail miserably without modifying it to suit your purposes

Screenshots: (they aren't very amazing to be honest :D)
tl1zi2.png

tl2jo4.png

And a larger one , demonstrating TimedLightningRing with 15 vertices
tlring.jpg

Code:
JASS:
//TimedLightning function
//By Flare a.k.a TmT.Fudge a.k.a the-thingy
//Uses Cohadar's TT system

//                          ----INFO----
//What does this system do?
//------------------------------\\
//This generates a lightning effect, to the end-user's specifications in a number of situations
//This lightning effect will fade over the specified time period, and will 'track' both units movement
//The fade effect automatically adjusts to the duration of the lightning
//i.e. If the lightning is set to last 5 seconds, it will be visible for that 5 seconds

//Why use this system?
//------------------------------\\
//From my search, there isn't a system which serves the same purpose (unless I overlooked it)
//Well, if you are like me, and find lightning effects to be a pain in the ass, this simplifies the process
//Just call the function, with your lightning type, source unit, target unit, and duration.
//Then let this do all the work, while you sit back and relax
    
//RGB colour of the lightning -MAY- be added in future.
//^--- These will only be added if users find it necessary

//If you feel that there is something else that should be added, feel free to let me know


//                                      ---To use---
//Simply call the appropriate TimedLightning function like so
//-----------------------------------------------------------
//call TL_Unit (lightid, sourceUnit, targetUnit, duration, fadeOn, initFade, endFade)
//Generates a lightning effect between 2 units

//call TL_Loc (lightid, loc1, loc2, duration, fadeOn, initFade, endFade)
//Generates a lightning effect between 2 locations

//call TL_Coord (lightid, x1, y1, z1, x2, y2, z2, duration, fadeOn, initFade, endFade)
//Generates a lightning effect between 2 sets of XYZ coordinates

//call TL_Ring (lightid, lightningCount, initAngle, centerx, centery, zHeight, initRadius, endRadius, duration, fadeOn, initFade, endFade)
//Generates a ring of lightning effects which around an XYZ starting at initRadius and expands/contracts towards endRadius

//call TL_RingLoc (lightid, lightningCount, initAngle, whichLoc, zHeight, initRadius, endRadius, duration, fadeOn, initFade, endFade)
//Same as TL_Ring, takes a location instead of coordinates

//call TL_Coord2Unit (lightid, x, y, z, whichUnit, duration, fadeOn, initfade, endfade)
//Creates a lightning effect that is static at one XYZ position, while other end tracks the motion of specified unit

//call TL_Loc2Unit (lightid, whichLoc, z, whichUnit, duration, fadeOnn, initFade, endFade)
//Same as TL_Coord2Unit, takes a location instead of coordinates


//NOTE:
//TL_Ring takes the initangle argument in RADIANS
//TL_RingLoc takes the initangle argument in DEGREES

//fadeOn is a boolean, initFade/endFade is a value between 0 and 1
//NOTE: fadeOn also affects RGB colouring

//ALL TimedLightning functions return an index - this index is required to use any of the modification functions
//The index of the last created TimedLightning can also be accessed through the TL_Last variable

//                                          ---Modification functions---
//NOTE: RGB values taken by any of these functions range from 0 to 1

//call TL_SetNextRGB (r1, r2, g1, g2, b1, b2)
//Determines the start/end RGB values of the next created lightning effect
//Works on Ring and non-Ring functions

//call TL_Destroy (index)
//Allows you to manually destroy the lightning associated with the specified index
//Only works on non-Ring functions

//call TL_DestroyRing (index)
//Allows you to manually destroy the lightning ring associated with the specified index
//Only works on Ring functions

//call TL_ChangeRGB (index, r1, r2, g1, g2, b1, b2)
//Allows you to change the start/end RGB values of the lightning associated with the specified index
//Only works on non-Ring functions

//call TL_ChangeRingRGB (index, r1, r2, g1, g2, b1, b2)
//Allows you to change the start/end RGB values of the lightning ring associated with the specified index
//Only works with Ring functions

//call TL_ChangeSourceCoord (index, x, y, z)
//Changes the source location of the lightning associated with the specified index
//Only works with TL_Coord, TL_Loc, TL_Coord2Unit, TL_Loc2Unit

//call TL_ChangeSourceLoc (index, loc, z)
//Changes the source location of the lightning associated with the specified index
//Works with same functions as TL_ChangeSourceCoord

//call TL_ChangeTargetCoord (index, x, y, z)
//Changes the target location of the lightning associated with the specified index
//Only works with TL_Coord, TL_Loc

//call TL_ChangeTargetLoc (index, loc, z)
//Changes the target location of the lightning associated with the specified index
//Only works with TL_Coord, TL_Loc

//call TL_ChangeSourceUnit (index, u)
//Changes the source unit of the lightning associated with the specified index
//Only works with TL_Unit

//call TL_ChangeTargetUnit (index, u)
//Changes the target unit of the lightning associated with the specified index
//Only works with TL_Unit, TL_Coord2Unit, TL_Loc2Unit

//call ChangeRingCoord (index, x, y, z)
//Changes the centre of the lightning ring associated with the specified index
//Only works with Ring functions

//call ChangeRingLoc (index, loc, z)
//Changes the centre of the lightning ring associated with the specified index
//Only works with Ring functions

//call FadeEnable (index, fadeOn)
//Determines whether the lightning associated with the specified index fades/recolours or not
//Only works with non-Ring functions

//call RingFadeEnable (index, fadeOn)
//Determines whether the lightning ring associated with the specified index fades/recolours or not
//Only works with Ring functions

//LIGHTNING ID NUMBERS
//------------------------------\\
//"CLPB" - Chain Lightning Primary
//"CLSB" - Chain Lightning Secondary
//"DRAB" - Drain
//"DRAL" - Drain Life
//"DRAM" - Drain mana
//"AFOD" - Finger of Death
//"FORK" - Forked Lightning
//"HWPB" - Healing Wave Primary
//"HWSB" - Healing Wave Secondary
//"CHIM" - Lightning Attack
//"LEAS" - Magic Leash
//"MBUR" - Mana Burn
//"MFPB" - Mana Flare
//"SPLK" - Spirit Link


library TL initializer TL_Init requires TT

private keyword Data
private keyword RingData

//Timer period is 0.03125
globals
    private location temploc = Location (0, 0)
    private constant integer MAX_LIGHT = 50 //Maximum number of lightning effects used for TL_Ring(Loc)
    public integer Last = 0
    private real R1 = 1
    private real R2 = 1
    private real G1 = 1
    private real G2 = 1
    private real B1 = 1
    private real B2 = 1
    private real MinX
    private real MaxX
    private real MinY
    private real MaxY
endglobals


private function ResetRGB takes nothing returns nothing
    set R1 = 1
    set G1 = 1
    set B1 = 1
    set R2 = 1
    set G2 = 1
    set B2 = 1
endfunction


public function SetNextRGB takes real r1, real r2, real g1, real g2, real b1, real b2 returns nothing
    set R1 = r1
    set G1 = g1
    set B1 = b1
    set R2 = r2
    set G2 = g2
    set B2 = b2
endfunction


public function Destroy takes integer index returns nothing
    //local Data a = Data (index)
    set Data(index).dest = true
endfunction


public function DestroyRing takes integer index returns nothing
    //local RingData a = RingData (index)
    set RingData(index).dest = true
endfunction

public function ChangeRGB takes integer index, real r1, real r2, real g1, real g2, real b1, real b2 returns nothing
    local Data a = Data (index)
    set a.rtamt = (TT_PERIOD / a.maxdur - a.currentdur) * (r1-r2)
    set a.gtamt = (TT_PERIOD / a.maxdur - a.currentdur) * (g1-g2)
    set a.btamt = (TT_PERIOD / a.maxdur - a.currentdur) * (b1-b2)
endfunction

public function ChangeRingRGB takes integer index, real r1, real r2, real g1, real g2, real b1, real b2 returns nothing
    local RingData a = RingData (index)
    set a.rtamt = (TT_PERIOD / a.maxdur - a.currentdur) * (r1-r2)
    set a.gtamt = (TT_PERIOD / a.maxdur - a.currentdur) * (g1-g2)
    set a.btamt = (TT_PERIOD / a.maxdur - a.currentdur) * (b1-b2)
endfunction


public function ChangeSourceCoord takes integer index, real x1, real y1, real z1 returns nothing
    local Data a = Data (index)
    set a.x1 = x1
    set a.y1 = y1
    set a.z1 = z1
endfunction

public function ChangeSourceLoc takes integer index, location loc, real z returns nothing
    call ChangeSourceCoord (index, GetLocationX (loc), GetLocationY (loc), z)
endfunction


public function ChangeTargetCoord takes integer index, real x2, real y2, real z2 returns nothing
    local Data a = Data (index)
    set a.x2 = x2
    set a.y2 = y2
    set a.z2 = z2
endfunction

public function ChangeTargetLoc takes integer index, location loc, real z returns nothing
    call ChangeTargetCoord (index, GetLocationX (loc), GetLocationY (loc), z)
endfunction


public function ChangeSourceUnit takes integer index, unit whichUnit returns nothing
    //local Data a = Data (index)
    set Data(index).source = whichUnit
endfunction


public function ChangeTargetUnit takes integer index, unit whichUnit returns nothing
    //local Data a = Data (index)
    set Data(index).target = whichUnit
endfunction

public function ChangeRingCoord takes integer index, real x, real y, real z returns nothing
    local RingData a = RingData (index)
    set a.Cx = x
    set a.Cy = y
    set a.Cz = z
endfunction

public function ChangeRingLoc takes integer index, location l, real z returns nothing
    call ChangeRingCoord (index, GetLocationX (l), GetLocationY (l), z)
endfunction

public function RingFadeEnable takes integer index, boolean fadeOn returns nothing
    //local RingData a = RingData (index)
    set RingData(index).fadeon = fadeOn
endfunction

public function FadeEnable takes integer index, boolean fadeOn returns nothing
    //local Data a = Data (index)
    set Data(index).fadeon = fadeOn
endfunction


private function GetUnitZ takes unit u returns real
    local real x = GetUnitX (u)
    local real y = GetUnitY (u)
    call MoveLocation (temploc, x, y)
    return GetLocationZ (temploc) + GetUnitFlyHeight (u)
endfunction


private function GetPointZ takes real x, real y returns real
    call MoveLocation (temploc, x, y)
    return GetLocationZ (temploc)
endfunction

private function AddLightningCustom takes string lightid, boolean checkVis, real x1, real y1, real z1, real x2, real y2, real z2 returns lightning
    if z1 < 0 then
        set z1 = 0
    endif
    
    if z2 < 0 then
        set z2 = 0
    endif
    
    if x1<MaxX and x1>MinX and y1<MaxY and y1>MinY then
        if x2<MaxX and x2>MinX and y2<MaxY and y2>MinY then
            return AddLightningEx (lightid, checkVis, x1, y1, z1, x2, y2, z2)
        endif
    endif
    
    return null
endfunction

private function MoveLightningCustom takes lightning whichLight, boolean checkVis, real x1, real y1, real z1, real x2, real y2, real z2 returns nothing
        if z1 < 0 then
        set z1 = 0
    endif
    
    if z2 < 0 then
        set z2 = 0
    endif

    if x1<MaxX and x1>MinX and y1<MaxY and y1>MinY then
        if x2<MaxX and x2>MinX and y2<MaxY and y2>MinY then
            call MoveLightningEx (whichLight, checkVis, x1, y1, z1, x2, y2, z2)
        endif
    endif
endfunction

private function SetLightningColorCustom takes lightning whichLight, real r, real g, real b, real a returns nothing
    if r < 0 then
        set r = 0
    elseif r > 1 then
        set r = 1
    endif
    
    if g < 0 then
        set g = 0
    elseif g > 1 then
        set g = 1
    endif
    
    if b < 0 then
        set b = 0
    elseif b > 1 then
        set b = 1
    endif
    
    if a < 0 then
        set a = 0
    elseif a > 1 then
        set a = 1
    endif
    
    call SetLightningColor (whichLight, r, g, b, a)
endfunction

private struct RingData
    lightning array tl[MAX_LIGHT]
    integer lightcount
    real maxdur
    real currentdur = 0
    real fadeamt
    real currentfade = 1
    boolean fadeon
    real array a1cos[MAX_LIGHT]
    real array a1sin[MAX_LIGHT]
    real array a2cos[MAX_LIGHT]
    real array a2sin[MAX_LIGHT]
    real exval
    real curdist
    real Cz
    real Cx
    real Cy
    real r
    real g
    real b
    real rtamt
    real gtamt
    real btamt
    boolean dest = false
    method onDestroy takes nothing returns nothing
        local integer i = 0
        loop
        exitwhen i >= .lightcount
            call DestroyLightning (.tl<i>)
            set i = i + 1
        endloop
        set .currentfade = 1
        set .currentdur = 0        
    endmethod
endstruct
    
    
private struct Data
    lightning tl
    real maxdur
    real currentdur = 0
    real fadeamt
    unit source
    unit target
    real currentfade = 1
    boolean fadeon
    real angle1
    real angle2
    real exval
    real z1
    real z2
    real x1
    real y1
    real x2
    real y2
    real r
    real g
    real b
    real rtamt
    real gtamt
    real btamt
    boolean dest = false
    method onDestroy takes nothing returns nothing
        call DestroyLightning (.tl)
        set .currentfade = 1
        set .currentdur = 0        
    endmethod
endstruct


private function TLCoord2UnitCallback takes nothing returns boolean
    local Data a = TT_GetData ()
    local real x = GetUnitX (a.target)
    local real y = GetUnitY (a.target)
    local real z = GetUnitZ (a.target)
    set a.currentdur = a.currentdur + TT_PERIOD
    if z &lt; 0 then
        set z = 0
    endif
    
    if a.currentdur &gt;= a.maxdur or a.dest then
        call a.destroy ()
        return true
    endif
     
    if a.fadeon == true then
        set a.currentfade = a.currentfade - a.fadeamt
        set a.r = a.r - a.rtamt
        set a.g = a.g - a.gtamt
        set a.b = a.b - a.btamt
        call SetLightningColorCustom (a.tl, a.r, a.g, a.b, a.currentfade)
    endif
    call MoveLightningCustom (a.tl, true, a.x1, a.y1, a.z1, x, y ,z)
    
    
    return false
endfunction


private function TLRingCallback takes nothing returns boolean
    local RingData a = TT_GetData ()
    local real x1
    local real y1
    local real x2
    local real y2
    local integer i = 0
    
    if a.currentdur &gt;= a.maxdur or a.dest then
        call a.destroy ()
        return true
    endif
    
    if a.fadeon == true then
        set a.currentfade = a.currentfade - a.fadeamt
        set a.r = a.r - a.rtamt
        set a.g = a.g - a.gtamt
        set a.b = a.b - a.btamt
        loop
        exitwhen i &gt;= a.lightcount
            call SetLightningColorCustom (a.tl<i>, a.r, a.g, a.b, a.currentfade)
            set i = i + 1
        endloop
        set i = 0
    endif
    
    set a.curdist = a.curdist - a.exval

    loop
    exitwhen i &gt;= a.lightcount
        set x1 = a.Cx + a.a1cos<i> * a.curdist
        set y1 = a.Cy + a.a1sin<i> * a.curdist
        set x2 = a.Cx + a.a2cos<i> * a.curdist
        set y2 = a.Cy + a.a2sin<i> * a.curdist
        call MoveLightningEx (a.tl<i>, true, x1, y1, a.Cz, x2, y2, a.Cz)
        set i = i + 1
    endloop
    set a.currentdur = a.currentdur + TT_PERIOD
    
    return false
endfunction

private function TLUnitCallback takes nothing returns boolean
    local Data a = TT_GetData ()
    local real x1 = GetUnitX (a.source)
    local real y1 = GetUnitY (a.source)
    local real z1 = GetUnitZ (a.source)
    local real x2 = GetUnitX (a.target)
    local real y2 = GetUnitY (a.target)
    local real z2 = GetUnitZ (a.target)
    if z1 &lt; 0 then
        set z1 = 0
    endif
    
    if z2 &lt; 0 then
        set z2 = 0
    endif
    
    if a.currentdur &gt;= a.maxdur or a.dest then
        call a.destroy ()
        return true
    endif
    
    call MoveLightningCustom (a.tl, true, x1, y1, z1, x2, y2, z2)
    
    if a.fadeon == true then
        set a.currentfade = a.currentfade - a.fadeamt
        set a.r = a.r - a.rtamt
        set a.g = a.g - a.gtamt
        set a.b = a.b - a.btamt
        call SetLightningColorCustom (a.tl, a.r, a.g, a.b, a.currentfade)
    endif
    
    set a.currentdur = a.currentdur + TT_PERIOD
    
    
    return false
endfunction


private function TLCallback takes nothing returns boolean
    local Data a = TT_GetData ()
    
    if a.fadeon == true then
        set a.currentfade = a.currentfade - a.fadeamt
        set a.r = a.r - a.rtamt
        set a.g = a.g - a.gtamt
        set a.b = a.b - a.btamt
        call SetLightningColorCustom (a.tl, a.r, a.g, a.b, a.currentfade)
    endif
    
    set a.currentdur = a.currentdur + TT_PERIOD
    
    if a.currentdur &gt;= a.maxdur or a.dest then
        call a.destroy ()
        return true
    endif
    
    call MoveLightningCustom (a.tl, true, a.x1, a.y1, a.z1, a.x2, a.y2, a.z2)
    
    return false
endfunction


public function Coord takes string lightid, real x1, real y1, real z1, real x2, real y2, real z2, real duration, boolean fadeon, real initfade, real endfade returns integer
    local Data a = Data.create ()
    if z1 &lt; 0 then
        set z1 = 0
    endif
    
    if z2 &lt; 0 then
        set z2 = 0
    endif
    
    set a.r = R1
    set a.g = G1
    set a.b = B1
    set a.maxdur = duration
    set a.rtamt = (TT_PERIOD / a.maxdur) * (a.r-R2)
    set a.gtamt = (TT_PERIOD / a.maxdur) * (a.g-G2)
    set a.btamt = (TT_PERIOD / a.maxdur) * (a.b-B2)
    set a.x1 = x1
    set a.y1 = y1
    set a.z1 = z1
    set a.x2 = x2
    set a.y2 = y2
    set a.z2 = z2
    set a.tl = AddLightningCustom (lightid, true, x1, y1, z1, x2, y2, z2)
    call SetLightningColorCustom (a.tl, a.r, a.g, a.b, initfade)
    set a.currentdur = 0
    set a.fadeon = fadeon
    set a.fadeamt = (TT_PERIOD / a.maxdur) * (initfade - endfade)
    call TT_Start (function TLCallback, a)
    call ResetRGB ()
    set Last = a
    return a
endfunction


public function Loc takes string lightid, location l1, location l2, real duration, boolean fadeon, real initfade, real endfade returns integer
    local real x1 = GetLocationX (l1)
    local real y1 = GetLocationY (l1)
    local real z1 = GetLocationZ (l1)
    local real x2 = GetLocationX (l2)
    local real y2 = GetLocationY (l2)
    local real z2 = GetLocationZ (l2)
    if z1 &lt; 0 then
        set z1 = 0
    endif
    
    if z2 &lt; 0 then
        set z2 = 0
    endif
    return Coord (lightid, x1, y1, z1, x2, y2, z2, duration, fadeon, initfade, endfade)
endfunction


public function Unit takes string lightid, unit source, unit target, real duration, boolean fadeon, real initfade, real endfade returns integer
    local Data a = Data.create ()
    local real x1 = GetUnitX (source)
    local real y1 = GetUnitY (source)
    local real z1 = GetUnitZ (source)
    local real x2 = GetUnitX (target)
    local real y2 = GetUnitY (target)
    local real z2 = GetUnitZ (target)
    if z1 &lt; 0 then
        set z1 = 0
    endif
    
    if z2 &lt; 0 then
        set z2 = 0
    endif
    set a.source = source
    set a.target = target
    set a.fadeon = fadeon
    set a.currentdur = 0
    set a.maxdur = duration
    set a.fadeamt = (TT_PERIOD / a.maxdur) * (initfade-endfade)
    set a.r = R1
    set a.g = G1
    set a.b = B1
    set a.rtamt = (TT_PERIOD / a.maxdur) * (a.r-R2)
    set a.gtamt = (TT_PERIOD / a.maxdur) * (a.g-G2)
    set a.btamt = (TT_PERIOD / a.maxdur) * (a.b-B2)
    
    set a.tl = AddLightningCustom (lightid, true, x1, y1, z1, x2, y2, z2)
    call SetLightningColorCustom (a.tl, a.r, a.g, a.b, initfade)
    call TT_Start (function TLUnitCallback, a)
    call ResetRGB ()
    set Last = a
    return a
endfunction


public function Ring takes string lightid, integer lightningcount, real initangle, real cx, real cy, real cz, real initrad, real endrad, real duration, boolean fadeon, real initfade, real endfade returns integer
    local RingData a = RingData.create ()
    local real angleinc
    local real angleval = initangle
    local integer i = 0
    local real x1
    local real y1
    local real x2
    local real y2
    if lightningcount &gt; MAX_LIGHT then
        set lightningcount = MAX_LIGHT
    endif
    set a.maxdur = duration
    set a.fadeon = fadeon
    set a.lightcount = lightningcount
    set angleinc = (bj_PI*2)/lightningcount
    set a.r = R1
    set a.g = G1
    set a.b = B1
    set a.rtamt = (TT_PERIOD / a.maxdur) * (a.r-R2)
    set a.gtamt = (TT_PERIOD / a.maxdur) * (a.g-G2)
    set a.btamt = (TT_PERIOD / a.maxdur) * (a.b-B2)
    set a.fadeamt = (TT_PERIOD / a.maxdur) * (initfade - endfade)
    set a.curdist = initrad
    set a.exval = (TT_PERIOD / a.maxdur) * (initrad - endrad)
    set a.Cx = cx
    set a.Cy = cy
    set a.Cz = cz
    loop
    exitwhen i &gt;= lightningcount
        set a.a1cos<i> = Cos (angleval)
        set a.a1sin<i> = Sin (angleval)
        set x1 = cx + a.a1cos<i> * initrad
        set y1 = cy + a.a1sin<i> * initrad
        set angleval = angleval + angleinc
        set a.a2cos<i> = Cos (angleval)
        set a.a2sin<i> = Sin (angleval)
        set x2 = cx + a.a2cos<i> * initrad
        set y2 = cy + a.a2sin<i> * initrad
        set a.tl<i> = AddLightningCustom (lightid, true, x1, y1, cz, x2, y2, cz)
        set i = i + 1
    endloop
    call TT_Start (function TLRingCallback, a)
    call ResetRGB ()
    set Last = a
    return a
endfunction


public function RingLoc takes string lightid, integer lightningcount, real initangle, location l, real z, real initrad, real endrad, real duration, boolean fadeon, real initfade, real endfade returns integer
    local real a = Deg2Rad (initangle)
    local real x = GetLocationX (l)
    local real y = GetLocationY (l)
    return Ring (lightid, lightningcount, a, x, y, z, initrad, endrad, duration, fadeon, initfade, endfade)
endfunction


public function Coord2Unit takes string lightid, real x, real y, real z, unit u, real duration, boolean fadeon, real initfade, real endfade returns integer
    local Data a = Data.create ()
    local real ux = GetUnitX (u)
    local real uy = GetUnitY (u)
    local real uz = GetUnitZ (u)
    if uz &lt; 0 then
        set uz = 0
    endif
    
    if z &lt; 0 then
        set a.z1 = 0
    endif
    
    set a.x1 = x
    set a.y1 = y
    set a.z1 = z
    set a.target = u
    set a.maxdur = duration
    set a.fadeon = fadeon
    set a.currentfade = initfade
    set a.r = R1
    set a.g = G1
    set a.b = B1
    set a.rtamt = (TT_PERIOD / a.maxdur) * (a.r-R2)
    set a.gtamt = (TT_PERIOD / a.maxdur) * (a.g-G2)
    set a.btamt = (TT_PERIOD / a.maxdur) * (a.b-B2)
    set a.tl = AddLightningCustom (lightid, true, a.x1, a.y1, a.z1, ux, uy, uz)
    call SetLightningColorCustom (a.tl, a.r, a.g, a.b, initfade)
    set a.fadeamt = (TT_PERIOD/duration) * (initfade-endfade)
    call TT_Start (function TLCoord2UnitCallback, a)
    call ResetRGB ()
    set Last = a
    return a
endfunction


public function Loc2Unit takes string lightid, location l, unit u, real duration, boolean fadeon, real initfade, real endfade returns integer
    local real lx = GetLocationX (l)
    local real ly = GetLocationY (l)
    local real lz = GetLocationZ (l)
    if lz &lt; 0 then
        set lz = 0
    endif
    
    return Coord2Unit (lightid, lx, ly, lz, u, duration, fadeon, initfade, endfade)
endfunction

private function TL_Init takes nothing returns nothing
    set MinX = GetRectMinX(bj_mapInitialPlayableArea)
    set MaxX = GetRectMaxX(bj_mapInitialPlayableArea)
    set MinY = GetRectMinY(bj_mapInitialPlayableArea)
    set MaxY = GetRectMaxY(bj_mapInitialPlayableArea)
endfunction

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


Credits:
The usual - if you plan on using this system in your map, please credit me for making it as alot of work went into making this work properly.
It's a very simple request, so please just add something that shows that I am the creator

Latest version changes:
  • Fixed an issue with the Z component, and a few other tweaks
  • Replaced some GetRectMin/Max calls with variables

I'm going to leave v7 there incase any bugs I missed crop up
 

Attachments

  • TL v7.w3x
    27.2 KB · Views: 430
  • TL v15.w3m
    34.3 KB · Views: 407

Trollvottel

never aging title
Reaction score
262
if you want to refer to the timer period of TT simply use TT_PERIOD
maybe you should make an ex version where the timer tracks the Z-position of the units, too.
 

Flare

Stops copies me!
Reaction score
662
if you want to refer to the timer period of TT simply use TT_PERIOD
maybe you should make an ex version where the timer tracks the Z-position of the units, too.

I was going to add that, but can't figure out how to get a unit's Z (there isn't a GetUnitZ function apparently :p)

And the TIMERPERIOD was just for reference, not sure why I used it :p Will fix it soon though

@Flare, why don't you use a 0.01s timer ? (use ABCT)

1) That's liable to cause lag if moving alot of lightning effects :S
2) The lightning tracking is smooth, so is that really necessary?
 
Reaction score
456
Make one function for X and Y too.

JASS:
function TimedLightningXY takes string lightid, real sourceX, real sourceY, real targetX, real targetY, real duration, boolean fadeon, real endfade returns nothing
    local TLdata a = TLdata.create()
    set a.source = source
    set a.target = target
    set a.fadeon = fadeon
    set a.currentdur = 0
    set a.maxdur = duration
    set a.fadeamt = (TIMERPERIOD / a.maxdur) * (1-endfade)
    set a.tl = AddLightning (lightid, true, sourceX, sourceY, targetX, targetY)
    call SetLightningColor(a.tl, 1, 1, 1, a.currentfade)
    call TT_Start(function TimerCallback, a)
endfunction

function TimedLightningUnit takes string lightid, unit source, unit target, real duration, boolean fadeon, real endfade returns nothing
    call TimedLightningXY(lightid, GetUnitX(source), GetUnitY(source), GetUnitX(target), GetUnitY (target), duration, fadeon, endfade)
endfunction


No spaces between function name and brackets.

EDIT: And of course, you have to edit the struct a bit.
 

Builder Bob

Live free or don't
Reaction score
249
I was going to add that, but can't figure out how to get a unit's Z (there isn't a GetUnitZ function apparently :p)

Here's a simple GetUnitZ() function with added GetTerrainZ() if you'll ever find that useful.

JASS:
library GetUnitZ

globals
	private location tempLocation
endglobals

function GetTerrainZ takes real x, real y returns real
	call MoveLocation(tempLocation, x, y)
	return GetLocationZ(tempLocation)
endfunction

function GetUnitZ takes unit u returns real
	return GetTerrainZ(GetUnitX(u), GetUnitY(u)) + GetUnitFlyHeight(u)
endfunction

public function InitTrig takes nothing returns nothing
	set tempLocation = Location(0., 0.)
endfunction

endlibrary


Edit: Trigger must be named GetUnitZ
 
Reaction score
456
>1) I guess I could make a stationary lightning (is that what you mean?)
I mean exactly what I said. I may want to create a timed lightning between xs and ys.

2) I find spaces between function calls and brackets easier to read (since that's how I usually do it when writing stuff in English :p)
Nah.

>Also, for a stationary lightning, should I take locations or coordinates in the arguments
You can do both. Just make sure that the location taker calls for coordinate taker.
 

Builder Bob

Live free or don't
Reaction score
249
Oh cool, thanks for that :)

Also, for a stationary lightning, should I take locations or coordinates in the arguments (I know that coordinates are faster, but it would probably make it simpler for GUI users with locations :p)

Following blizzard's standard, you could make 3 functions:

TimedLightning - for x/y coordinates
TimedLightningTarget
TimedLightningLoc
 
Reaction score
456
>TimedLightningTarget
"Unit" sounds better for me :p.. Because it's created between two units.
 
Reaction score
456
>Ah, sneaky Cohadar... the globals block said PERIOD
That's because public makes it <library/scopename>_<name>.
 
Reaction score
456
>Why would I have to edit the struct? There isn't really anything new that needs to be stored for a stationary lightning.
There are the coordinates. And as you're going to use coordinates, there is no use for source and target.
 
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