| 05-08-2011, 04:26 PM | #2 |
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. |
