# custom spell: kill first unit in direction

Status
Not open for further replies.

#### 69stehend

Level 7
i want to create a spell that is cast into a target direction (dummyspell carrion swarm)
the spell INSTANTLY kills the first enemy unit in the target direction
i dont manage to properly detect the unit, that should be killed

Level 17

#### Baintastic

Level 8
Pretty sure Mr Bean didn't read the question...

Anyway. Here is a rough idea of how you could do it:

variables:
Spell_Width:real - width of the angle of the spell (how wide you want the area of effect to be) let's call it 40 degrees
Spell_Angle:real - angle from caster to casting point of spell
Unit_Angle:real - angle from caster to possible closest unit
Unit_Distance:real - distance from caster to possible closest unit
Closest_Distance:real - self-explanatory
Closest_Unit:unit - self-explanatory

When the spell is cast:
- calculate Spell_Angle
- set Closest_Distance to whatever the spell range is (let's say 700)
- set Closest_Unit to No Unit
- Select each unit within a range of the caster (let's say 700):
- - calculate Unit_Angle
- - if (unit is enemy AND Unit_Angle > Spell_Angle - Spell_Width/2 AND Unit_Angle < Spell_Angle + Spell_Width/2)
- - - calculate Unit_Distance
- - - if (Unit_Distance < Closest_Distance)
- - - - set Closest_Distance to Unit_Distance
- - - - set Closest_Unit to Selected Unit
- kill Closest_Unit

Obviously, you can name the variables whatever you want.
Let me know if you need more explanation

#### 69stehend

Level 7
i should have been more exact in my description:
my spell will be a lightning that hits the first unit in its way
the problem about ur system is, that the area of possible units is not a narrow and long rect, it is a sector of a circle, close to a triangle
thx for trying to help me but ur suggestion sadly wont work

#### Baintastic

Level 8
Okay, I understand. I was under the impression that you wanted a cone AOE since your base-spell is Carrion Swarm.

Anyway, you have 2 options:
1. Settle for the cone AOE. I don't think there is much added value in having a linear width AOE for this spell.
2. Don't settle. See the attached picture for way to visualize how to do this.

I think either way, you should make it so if a closest unit is found, it should create a dummy unit at the caster's location and make it cast a chain lightning with a single target and 999999 damage on the found closest unit.

#### Attachments

• example.png
15 KB · Views: 82

#### 69stehend

Level 7
exactly what i was searching for and thx for the good idea, but i allready decided to do it another mathimatical way: just calculate the point on middle black line that is closest to the possible unit, and if the difference between the unit and the calculated point is smaller than the allowed width, the unit is a possible target

Status
Not open for further replies.

Replies
6
Views
683
Replies
9
Views
603
Replies
8
Views
762
Replies
4
Views
442
Replies
12
Views
1K