• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] Fire and Forget Lightning System

Status
Not open for further replies.
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 notGetLocalPlayer()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
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
You have such a wierd attitude. Anyway, you could probably use "The Lab" instead, if you are unsure whether resource is "complete" or not. Also, you can get suggestions related to your stuff - with those, you can decide if it's worth to submit script or not.

You should also your search engine or google to look for similar stuff / related to your resource. Then scan the script, ask yourself if it's unique in some way, if it brings something new, or meaby your approach is differend. Meaby yours allows for more customization / is lighter and more portable?

Remember to credit or at least mention few (if not all) dudes who originaly made idea flesh. This step is not really required, yet, personaly I like to show some respect to work of others.
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
True, this section is mainly filled with resources involving usage of custom parsers. You can also use "spell section" for standard jass resources.
If you post resource here, with knowledge and attitude for it to be graveyarded, then why you post at all? You should take my advice and not be so negative.

On the other hand, rewritting your resources into vJass/Wurst/ZINC to add some portability and additional features is not out of boundary, even for you, claiming that "vJass is bane of war3".
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
blinded hatred for vJass right here. But you know, why have a system that supports 1 or maybe 2 things, when we have another system, that already supports 6 other things?

Yes good thing about this is that it is in Jass, but nevertheless, we have one already, and imo it would've been better at Spells section or at The Lab
 
Status
Not open for further replies.
Top