- Joined
- Nov 25, 2008
- Messages
- 1,309
Below is a fairly simple system to handle lightnings. It's purpose is to create, and fade out, lightning bolts over a given period of time. Once faded it out, it removes the lightning bolts. Unfortunately, this is not
GetLocalPlayer()
capable.
JASS:
//===========================================================================
//
// Fire and Forget Lightning System.
//
// Author: Zeatherann
// Description: A simple system to create static lightning bolts that fade out to nothing over a given interval of time.
//
//===========================================================================
globals
constant real FFLS_TIMEOUT =0.05
lightning array FFLS_Bolts
real array FFLS_TimeLeft
real array FFLS_TimeStart
integer FFLS_InstanceCount =0
timer FFLS_UpdateTimer =CreateTimer()
endglobals
//===========================================================================
// FFLS_Update
// takes nothing
// returns nothing
//
// This is the core of the system, and is ran every FFLS_TIMEOUT seconds.
//===========================================================================
function FFLS_Update takes nothing returns nothing
local integer Index=1
local lightning Bolt
local real Time
loop
exitwhen Index>FFLS_InstanceCount
set Bolt=FFLS_Bolts[Index]
if(Bolt==null)then
if(FFLS_InstanceCount>1)then
set FFLS_Bolts[Index]=FFLS_Bolts[FFLS_InstanceCount]
set FFLS_Bolts[FFLS_InstanceCount]=null
set FFLS_TimeLeft[Index]=FFLS_TimeLeft[FFLS_InstanceCount]
set FFLS_TimeStart[Index]=FFLS_TimeStart[FFLS_InstanceCount]
endif
set FFLS_InstanceCount=FFLS_InstanceCount-1
set Index=Index-1
else
set Time=FFLS_TimeLeft[Index]
if(Time>0)then
call SetLightningColor(Bolt,1,1,1,Time/FFLS_TimeStart[Index])
set FFLS_TimeLeft[Index]=Time-FFLS_TIMEOUT
else
call DestroyLightning(Bolt)
set FFLS_Bolts[Index]=null
endif
set Bolt=null
endif
set Index=Index+1
endloop
if(FFLS_InstanceCount==0)then
call PauseTimer(FFLS_UpdateTimer)
endif
endfunction
//===========================================================================
// FFLS_Create
// takes string Type - This is the lightning type to create.
// real X1 - The X coordinate to place the start of the bolt.
// real Y1 - The Y coordinate to place the start of the bolt.
// real X2 - The X coordinate to place the end of the bolt.
// real Y2 - The Y coordinate to place the end of the bolt.
// real Time - How long the bolt will be around for, must be greater than 0.
// returns nothing
//
// This creates a new lightning bolt to display, and fade out after some time.
//===========================================================================
function FFLS_Create takes string Type,real X1,real Y1,real X2,real Y2,real Time returns nothing
local integer Index=FFLS_InstanceCount+1
if(Time>0)then
set FFLS_Bolts[Index]=AddLightning(Type,true,X1,Y1,X2,Y2)
set FFLS_TimeLeft[Index]=Time
set FFLS_TimeStart[Index]=Time
set FFLS_InstanceCount=Index
if(Index==1)then
call TimerStart(FFLS_UpdateTimer,FFLS_TIMEOUT,true,function FFLS_Update)
endif
endif
endfunction