HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Feedback on lightning script + test map

07-04-2009, 10:31 AM#1
0zyx0
This script's primary feature is to handle timed lightning effects, but it also supports additional features. The most noticeable one is connecting lightning effects to units. The script will only get the position of a unit once, even if multiple lightning effects is connected to the same unit. This is done by using an internal struct called LightningLoc, which has an x, y and z member. If a LightningLoc is attached to a unit, the x, y and z will be updated periodically. Then, the lightning effects will be moved to the appropriate coordinates. Since the LightningLocs have to be updated before the lightnings are moved, this script can't use TimedLoop, however in return, the update period can be specified.

To iterate trough all structs to update them, this script uses ListModule by grim001. This improves speed, and only one function call per struct type has to be done on every update period. This time, the script supports fading out lightnings. This is done by another struct called Fader. It has most of the members of the Lightning struct, and some additional ones.

The script needs some form of unit indexing, it uses the function GetUnitId(), so both UnitIndexingUtill and AutoIndex will work (PUI will also work if you configure the system to do that). You will however have to make sure the unit is indexed before it is passed to this system.

This is the code used to test this in the sample map:
Expand JASS:
I know the API isn't perfect, how can I improve it?
Here is the script itself:
Expand JASS:
The scirpt should be more readable this time, since I have removed some unnessecary textmacros, and replaced some code with other textmacros.

I am planning to add something to handle lightnings that doesn't move, to improve speed. That will require TimerUtils. A question: How should this script handle unit death?

Here is the test map: LightningSystem.w3m
Any feedback is appreciated, I will give +rep for any useful feedback. Please note, I will not be able to post for about 5 weeks, but I will still read all feedback, and I will give rep as soon as I can.
Attached Files
File type: w3mLightningSystem.w3m (23.8 KB)
07-04-2009, 11:31 AM#2
Blubb-Tec
ok, this is what i've found from looking over the script and testing your map so far:
return 0 // This line will never be executed. why don't you just leave this lilne out if will never be executed? shouldn't be a problem to pjass afaik

Another thing you might want to change is that currently the user has to create a lightning himself, and pass that one to your Lightning struct's create method. you might simply add a string to that create method which then takes the "DRAL" or w/e lightning the user wishes to use, so he doesn't have to clean up etc. else it also looks as if the user has to destroy this thing again.

then, you do a check whether the unit is null in the fromUnit method, however you only do that check in debug mode.
you should probably change this:
Collapse JASS:
        debug if u == null then // There can't be any lightning attached to null.
            debug call BJDebugMsg(SCOPE_PREFIX + "Error: Lightning.atUnit was called on a null unit.")
            debug return LightningLoc.fromCoords(0., 0., 0.)
        debug endif

into this:
Collapse JASS:
        if u == null then // There can't be any lightning attached to null.
            debug call BJDebugMsg(SCOPE_PREFIX + "Error: Lightning.atUnit was called on a null unit.")
            return LightningLoc.fromCoords(0., 0., 0.)
        endif

then, when looking at the test map, i saw that the fromUnit method you're using there actually creates very ugly lightnings, since they start at the feet of the soldier, and end at the feet of the other soldier. ugh. probably you should add something like 50. to the .z coord, or find another way to do that. also you should a possibility for the user to add an effect to the start and end unit, like this green or red glow which is also used by most standard spells, since else the beginning/end of each lightning look like they're "cut off".

Despite from that, I like this system very much, since it provides a good way to attach a lightning to a unit. very cool i also like the fader very much, since it looks very good ingame(why didn't you use vex' ARGB for that, btw?)

all in all, nice system
07-18-2009, 01:57 PM#3
0zyx0
Thank you for the feedback. I will update the script in the first post with the small changes. About the passing of a lightning to the struct, I did it that way so the color of the lightning would be configurable. Sacrificing that benefit would also improve the speed slightly, but I will probably make a more complicated (or advanced) way of changing the color, possibly using ARGB.

To fix the problem with lightning attached to the origin of units, I will probably add two Z-offset constants, one for buildings and one for normal units.

Finally, I actually made a way of attaching special effects at the end of the lightnings, but that turned out to complicate things a lot. A better solution would be to add special effects to units as usual. The problem then shifts to the destruction, which can be fixed by passing a function interface argument to the struct, which is evaluated when the lightning is destroyed.