- Joined
- Apr 16, 2010
- Messages
- 584
Hello. I need a trigger that can create lightning from Z location to point i want. I know it's not hard but i don't know. +rep to helper as always.
library Lightnings initializer init needs AbilityPreload,TimerUtils//AbilityPreload and TimerUtils are both available at wc3.net
globals
private constant real LIGHTNING_Z = 0. //A small offset if you want to link 2 units. 0. = lightning will be created on the feet
private constant real TIMEOUT = 0.03 //Period of the timer. The fastest it is, the most fluant it is but the most power_devourer it is.
private constant integer DUMMY_ID = 'u000' //id of a dummy unit without any model - stats - sight etc...
private constant integer RAVEN_ID = 'Amrf" //Given to a unit, this ability allows to change the flying height.
endglobals
private struct str //a struct is something like a meta-variable
unit origin //origin of the lightning
unit destination //...
lightning fx //your lightning
integer duration
integer i
endstruct
private function Update takes nothing returns nothing //this function updates the position of the lightning in the case you want it to move
local timer t = GetExpiredTimer() //through Timerutils
local str dat = GetTimerData(t) //you are able to retreive the data stored into the struct
local real x1 = GetUnitX(dat.origin)
local real y1 = GetUnitY(dat.origin)
local real z1 = GetUnitFlyHeight(dat.origin)
local real x2 = GetUnitX(dat.destination)
local real y2 = GetUnitY(dat.destination)
local real z2 = GetUnitFlyHeight(dat.destination)
if dat.i < dat.duration and not (IsUnitType(dat.origin,UNIT_TYPE_DEAD)) and not (IsUnitType(dat.destination,UNIT_TYPE_DEAD)) then
set dat.i = dat.i + 1 //if the origin and the destination are alive, still update the lightning position
call MoveLightningEx(dat.fx,true,x1,y1,z1+LIGHTNING_Z,x2,y2,z2+LIGHTNING_Z)
else
call DestroyLightning(dat.fx) //if timer has reached the duration (counted with the integer i) or one of the unit is dead, remove the lightning
call ReleaseTimer(t) //release the timer through timerutils to avoid leaks
call dat.destroy() //destroy the struct
endif
endfunction
//This function allows to link 2 units with a lightning
//origin = first unit
//destination = second unit
//duration = the maximal duration you want the lightning to get
//lightningArt = the string of the lightning (like a model for a special effect, example "DRAL", "DRAM" etc..)
function AddLightningToUnits takes unit origin, unit destination, real duration, string lightningArt returns nothing
local timer t = NewTimer() // create a timer through TimerUtils
local str dat = str.create() //Create a struct (metavariable)
local real x1 = GetUnitX(origin)
local real y1 = GetUnitY(origin)
local real z1 = GetUnitFlyHeight(origin)
local real x2 = GetUnitX(destination)
local real y2 = GetUnitY(destination)
local real z2 = GetUnitFlyHeight(destination)
set dat.origin = origin
set dat.destination = destination
set dat.duration = R2I(duration/TIMEOUT)
set dat.fx = AddLightningEx(lightningArt_ART, true,x1,y1,z1+LIGHTNING_Z,x2,y2,z2+LIGHTNING_Z)
set dat.i = 0
call SetTimerData(t, dat)
call TimerStart (t, TIMEOUT, true, function Update )
endfunction
//This function allows you to create a lightning effect from a point (x1,y1,z1) to an other point (x2,y2,z2) during (duration) seconds with the (lightningArt) effect
function AddLightningOnLocation takes real x1, real y1, real z1, real x2, real y2, real z2, real duration, string lightningArt returns nothing
local unit origin = CreateUnit(Player(15),DUMMY_ID,x1,y1,0.)
local unit destination = CreateUnit(Player(15),DUMMY_ID,x2,y2,0.)
call UnitAddAbility(origin,RAVEN_ID)
call UnitAddAbility(destination,RAVEN_ID)
call SetUnitFlyHeight(origin,z1,0.)
call SetUnitFlyHeight(destination,z2,0.)
call UnitApplyTimedLife(origin,'BTLF',duration)
call UnitApplyTimedLife(destination,'BTLF',duration)
call AddLightningToUnits(origin,destination,duration,lightningArt)
set origin = null
set destination = null
endfunction
private function init takes nothing returns nothing
call AbilityPreload(RAVEN_ID)//To prevent lag on first use
endfunction
endlibrary