HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Masslightning

05-08-2011, 01:37 PM#1
Malfurion
Hello Wc3c-community,
I have a problem with triggering a lightning spell. I want to make a spell which creates a
lightning effect to every unit within 500 of the casting units. The lightings are supposed to
refresh 30 times a second.
Now my problem is: I can only create one lightning to a unit in the unit group. How can I
choose more than only one unit per group?

This is my trigger:

Trigger:
Blitz
Collapse Events
Time - Every (1.00 / 30.00) seconds of game time
Conditions
Collapse Actions
Collapse Unit Group - Pick every unit in (Units within 500.00 of (Position of BLI_Caster)) and do (Actions)
Collapse Loop - Actions
Set BLI_Group = (Last created unit group)
Lightning - Destroy BLI_Blitz
Lightning - Create a Chain Lightning - primary lightning effect from source (Position of BLI_Caster) to target (Position of (Picked unit))
Set BLI_Blitz = (Last created lightning effect)
Lightning - Change color of BLI_Blitz to (1.00 0.10 1.00) with 1.00 alpha
05-08-2011, 04:26 PM#2
Anitarf
The problem you have is that you store your lightnings in a single variable. You think that you are destroying lightnings from the previous loop, but what you are in fact doing is destroying the lightning from the previous unit in the same loop.

What you need is a lightning array and an integer variable that tells you how many lightnings are active. Then, 30 times per second, you should first loop through the array and destroy all existing lightnings, then loop through the group and create new ones, storing them to increasing indexes in that array.

Note that your code is leaking locations as well as groups fairly rapidly, so it is recommended you at the very least fix that.

A more sensible solution than recreating lightnings would be to move them and only create new ones/destroy old ones whenever units enter/leave the area of your spell; you could even use dummy casters to cast auto-tracking lightning spells like life drain instead of moving lightnings yourself. Personally, regardless of the method used to display the lightnings, I would use the ABuffAura system to code such a spell.