• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Last created unit in unit group loop

Status
Not open for further replies.
Level 2
Joined
May 17, 2015
Messages
10
Good afternoon,
I am trying to do this loop, where I cast aerial shackles on all units in this unit group.

Aerial shackles has been modified to be able to be cast on the units, cost no mana, no casting time, no tech needed, increased range, etc.

The thing is, one unit is actually being shackled, and I'm sure more than one dummy is created because I've given them models, and I see several dummies.

I suspect it may have something to do with (last created unit).

Any help? Thank you.

upload_2020-12-28_21-28-26.png
 

Attachments

  • upload_2020-12-28_21-26-40.png
    upload_2020-12-28_21-26-40.png
    26.8 KB · Views: 20

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
So Casting Unit and practically every other Event Response is treated like a global variable. This means that it can only be set to one thing at a time. So whenever ANY unit, including your Dummy that's casting Aerial Shackles, casts an ability, they become the new Casting Unit. That's why it lost reference to the original caster of Binding Sun, Casting Unit was changed to the Dummy unit.

Triggering Unit, however, is a special case that ISN'T treated like a global variable and instead is treated like a local variable. This means that it can't be changed and will remain the same throughout your entire trigger.


Also, is it intentional that you're using the Event? -> A unit Begins casting an ability

In most cases you want to use: A unit Starts the effect of an ability

This Event happens the moment the ability goes on cooldown/spends mana/executes it's effects.

Otherwise, with Begins it's possible that the trigger will run even if the ability is canceled early.

You can test this out by ordering your Hero to cast Binding Sun, then immediately issue a Stop order before the ability finishes. The Event will go off because the unit technically "began casting" the ability, but the ability will not have spent any mana or gone on cooldown. This can be exploited by the player, allowing them to skip the cd/mana cost entirely while still getting the triggered effects of the ability.


Some other notes:

- You never get rid of your Dummy units, at least not in this trigger. You want to add an Expiration Timer to them so that they're removed after some time. If Aerial Shackles lasts 5.00 seconds then I would set their Expiration Timer to something like 5.50 seconds.

- You're leaking Points when you use (Position of Unit), (Target Point of ability being cast), and anything else that references some Point in the world. You can figure out how to deal with leaks here: Memory Leaks

- You're leaking a Unit Group when you use Pick every unit in... Again, see the link above for more details.

- You can reference Triggering Player instead of (Owner of Casting Unit) for this particular Event. Triggering Player will be set to the Owner of the Casting Unit by default. This is just a minor optimization.

- I have a feeling that your Dummy unit may not be setup correctly but this is just an assumption. My first post in this thread explains what settings you want: Dummy Casting Problem
 
Last edited:
Level 2
Joined
May 17, 2015
Messages
10
Hello Uncle,
Thanks for the reply, I did fix some of these on my own, but I will read on Point leaks.
 
Status
Not open for further replies.
Top