This one is tough, and I've been trying to make it flawlessly with only GUI for years now but it's still not perfect.
I need a trigger/JASS code that detects every time a unit attacks (that knows when a unit attacks, and not only the first attack, but all the ones that come after it as well). There needs to be no delay between when the unit starts its new attack and when the trigger records this attack. What makes this hard is that the attack is similar to that of a catapult: ranged, slow moving projectile that can be launched using the "attack ground" command.
This is how I went about doing it:
Unfortunately there is no event "when unit attacks". it works for when you target a unit or the ground but does not loop for when the unit attacks every other time after that. "unit takes damage" would work, but the attack does not necessarily deal damage, nor does it have a specific target (target ground).
I needed to take into account the fact that a unit might be ordered to attack before it can actually attack (out of range, etc.) I also needed to take into account the fact that there is a small delay depending on how much the unit has to turn to face the target before it can attack.
Using the distance from the target and the original facing degrees my code can find how many degrees the unit has to turn and add a delay in seconds using a linear function. If the unit is out of range I simply looped a check every 10 ms until it was in range, or until the order was changed. Now all I need is something that loops for every time the unit attacks.
Simply:
(Unit attacks)
Loop (until unit stops given attack order)
Wait (cooldown of unit)
(Unit attacks)
Every time the wait is finished, I know the unit attacks once again. Unfortunately this does not work for some reason. Not only is the cooldown value incredibly hard to convert into seconds using a function, for some reason the Wait (in-game seconds) command does not wait a fixed value: i get different wait times for the exact same cooldown Does anyone know why this happens? I can explain in more detail and give an example if you need me to.
If anyone had the answer to this with JASS or even GUI that would be great. Also, if anyone knows how to convert unit cooldown values into seconds, that would help a lot!
If you have any suggestions or ideas feel free to post!
I've been trying to approach this with different methods:
Have small invisible neutral buildings with no collision and infinite regeneration in a grid all over the map, add an extra, invisible attack to the unit that has an infinite projectile speed, and use a simple trigger saying if (one of these) buildings is under attack (the buildings will have a defense only affected by this invisible attack) then I know the unit has just attacked once. But how do I add a second attack to a unit that stacks on top of its original attack?
I'm curious to see if anyone can figure this one out.
Many thanks,
Axel
I need a trigger/JASS code that detects every time a unit attacks (that knows when a unit attacks, and not only the first attack, but all the ones that come after it as well). There needs to be no delay between when the unit starts its new attack and when the trigger records this attack. What makes this hard is that the attack is similar to that of a catapult: ranged, slow moving projectile that can be launched using the "attack ground" command.
This is how I went about doing it:
Unfortunately there is no event "when unit attacks". it works for when you target a unit or the ground but does not loop for when the unit attacks every other time after that. "unit takes damage" would work, but the attack does not necessarily deal damage, nor does it have a specific target (target ground).
I needed to take into account the fact that a unit might be ordered to attack before it can actually attack (out of range, etc.) I also needed to take into account the fact that there is a small delay depending on how much the unit has to turn to face the target before it can attack.
Using the distance from the target and the original facing degrees my code can find how many degrees the unit has to turn and add a delay in seconds using a linear function. If the unit is out of range I simply looped a check every 10 ms until it was in range, or until the order was changed. Now all I need is something that loops for every time the unit attacks.
Simply:
(Unit attacks)
Loop (until unit stops given attack order)
Wait (cooldown of unit)
(Unit attacks)
Every time the wait is finished, I know the unit attacks once again. Unfortunately this does not work for some reason. Not only is the cooldown value incredibly hard to convert into seconds using a function, for some reason the Wait (in-game seconds) command does not wait a fixed value: i get different wait times for the exact same cooldown Does anyone know why this happens? I can explain in more detail and give an example if you need me to.
If anyone had the answer to this with JASS or even GUI that would be great. Also, if anyone knows how to convert unit cooldown values into seconds, that would help a lot!
If you have any suggestions or ideas feel free to post!
I've been trying to approach this with different methods:
Have small invisible neutral buildings with no collision and infinite regeneration in a grid all over the map, add an extra, invisible attack to the unit that has an infinite projectile speed, and use a simple trigger saying if (one of these) buildings is under attack (the buildings will have a defense only affected by this invisible attack) then I know the unit has just attacked once. But how do I add a second attack to a unit that stacks on top of its original attack?
I'm curious to see if anyone can figure this one out.
Many thanks,
Axel