HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[Script] LightningUtils

09-12-2010, 04:07 AM#1
Fledermaus
Background:
When making some spells for my map, I discovered that I needed to create my own lightning, I looked around wc3c but couldn't find any released resources. I made my own one which just connected lightning between units as I didn't really need anything else. I then looked deeper in wc3c and found Kueken's abandoned AdvLightning thread. I like the idea of making a proper library to deal with lightning so I did. And here we are.

Requirements:Credits:Code:
Expand Library:
09-12-2010, 08:42 AM#2
Anitarf
Quote:
It is VERY important that you DO NOT use any of the functions from this library with lightning that was NOT created via this library
You already lost me here. It should be easy to work around this problem with hooks.
09-12-2010, 03:41 PM#3
Fledermaus
Sorry, I'm not quite sure what you mean.
09-12-2010, 06:15 PM#4
Anitarf
You should be able to make these functions work with regularly created lightnings.
09-16-2010, 05:43 AM#5
Fledermaus
Update!

Added hook support for AddLightning, AddLightningEx and AddLightningLoc (controlled by a configuration constant). Also added in some debug hooks for all the other natives that shouldn't be used. And I fixed a bug where lightning created with CreateLightningBetweenPoints could not be destroyed if it had a FadeTime over 0 seconds.

EDIT: Forgot to mention that I removed the table requirement.
09-16-2010, 08:46 PM#6
Deaod
Expand JASS:
You might want to use this principle for your hooks.
09-17-2010, 02:30 AM#7
Fledermaus
You mean like this?

Expand JASS:

The lightning created after the hook should have the same handle id as the one created by the hook (unless something retarded is going on).

Or are you just suggestion that I print out the handle id of the lightning that I create/destroy to get the correct id for the struct?

EDIT: Oh, you mean that I create one at init to make sure they'll have the same id? That's not a bad idea.
09-17-2010, 08:25 AM#8
Deaod
Quote:
You mean like this?
Yes, like that.

Do note however, that this will fail if someone else creates a lightning during a hook of AddLightning(Ex/AtLoc) and doesnt destroy it.
10-17-2010, 02:16 AM#9
Ignitedstar
If this makes handling lightning a doozy, I'm going to try this out. Those lightning functions... Grrr... they look easy, but ah... lol
10-20-2010, 04:09 AM#10
Fledermaus
Not sure if you're wanting a reply before you try it out :p but ah, I think it makes everything pretty easy.
12-12-2010, 05:18 PM#11
SanKakU
well, i'm curious...why did you say that using destroylightning function will crash the game? does it cause a leak? i'm new to using lightnings but i think i understand how they work and i'm not afraid to use them...

do you mean if we use your system we cannot any longer use destroylightning function or do you mean that we should never use destroylightning function to begin with?
12-12-2010, 08:11 PM#12
Fledermaus
If a lightning that has been destroyed is ever used in another lightning function (e.g. MoveLightning) the game will crash. Since this library moves lightning that are connected to one or more units, the user calling DestroyLightning will most likely crash the game.
I should probably add a hook in that will safely release anything not destroyed by the system and tell the user off anyway.
12-12-2010, 08:56 PM#13
SanKakU
so, reviewed the code instructions some more...i don't understand what advantage this library gives over using lightning normally. the only thing i notice that's new here is there is a fade time for lightning when you want it to go away. what advantage is there with using all those replacement functions?

it seems like a main point of it may be that it removes clutter by taking away the need to move lightnings, but instead of that we have to put in functions that dictate the movement style. is this about right?
12-12-2010, 10:11 PM#14
Fledermaus
The three main things it does is the death fade time, easy attachment to/between units and delayed releases. I had thought of allowing you to change the colour over time but thought it might be too much for this library, it's meant to be a simple thing for making lightning easier to use.
12-14-2010, 12:31 AM#15
Fledermaus
Updated the system to have even more optional support for keeping the native functions operational. Better hooks + a constant to determine which flavour you want to use. Documentation also updated to reflect the change and help explain the differences. Can someone tell me if it all makes sense? xD