I'm creating a Chain Lightning-esque ability with some pretty complicated mechanics which would be better suited to triggers. I have the basics in place, but I'm struggling with the targeting. Each time the ability jumps, I can add the target to a unit group so that I can remember what targets I've already hit. And I can pick a random target within a given range of the last target. But I'm struggling with how to pick the closest unit, not just a random one. And I'm also struggling with how to ignore units that I've already hit (I thought storing them in a unit group would work well for this.. but maybe not. Another idea would be to add a buff and look for units without the buff - I've seen that mentioned before - but I'd like subsequent casts by the same player and casts by other players to be able to hit the same units so I think a buff would prevent that).
Any ideas?
ANSWER:
Answered my own question again. I do add all units to the PreviouslyHitUnits unit group as I hit them, then when finding a new target, I do this:
Variable - Set UnitsInRange = (Any units within SearchRange of CenterPoint where player SourcePlayer matches filter Exluded: Player, Ally, Neutral, Missile, Dead, Hidden, with at most Any Amount)
Unit Group - Remove all units in PreviouslyHitUnits from UnitsInRange
Variable - Set TargetUnit = (Closest unit to CenterPoint in UnitsInRange)
If anyone has any alternate ideas, feel free to comment.
I'm creating a Chain Lightning-esque ability with some pretty complicated mechanics which would be better suited to triggers. I have the basics in place, but I'm struggling with the targeting. Each time the ability jumps, I can add the target to a unit group so that I can remember what targets I've already hit. And I can pick a random target within a given range of the last target. But I'm struggling with how to pick the closest unit, not just a random one. And I'm also struggling with how to ignore units that I've already hit (I thought storing them in a unit group would work well for this.. but maybe not. Another idea would be to add a buff and look for units without the buff - I've seen that mentioned before - but I'd like subsequent casts by the same player and casts by other players to be able to hit the same units so I think a buff would prevent that).
Any ideas?
ANSWER:
Answered my own question again. I do add all units to the PreviouslyHitUnits unit group as I hit them, then when finding a new target, I do this:
Variable - Set UnitsInRange = (Any units within SearchRange of CenterPoint where player SourcePlayer matches filter Exluded: Player, Ally, Neutral, Missile, Dead, Hidden, with at most Any Amount) Unit Group - Remove all units in PreviouslyHitUnits from UnitsInRange Variable - Set TargetUnit = (Closest unit to CenterPoint in UnitsInRange)
If anyone has any alternate ideas, feel free to comment.