• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] How do I store a targeted unit's name in a variable?

Status
Not open for further replies.
Level 4
Joined
Oct 8, 2023
Messages
21
New to this. Trying to get a "Talk" ability working. I've created a base ability through channel and can cast it without issue, and even have a trigger say "h" in response to it. However I'm trying to get a unique response depending on which NPC I had targeted when using Talk.

worldedit_t8n7bxojXg.png


Figured something like this would work, but it doesn't. How do I store the name of the unit targeted by "Talk" into a variable for further use?
 
Level 24
Joined
Feb 27, 2019
Messages
833
Its better to use the Event - Starts the effect on an ability. Finishes casting an ability only triggers if the ability finishes casting which sounds neat except the units cast animation has to finish and if its interrupted the event doesnt fire even if the ability properly fires. Stops casting an ability triggers even if the ability is interrupted. For a faster event one can use Begins channeling an ability but that occurs before the ability has properly fired.

The condition ability being cast is only true for abilities being cast and not for order events. Targeted unit refers to something else entirely. When choosing a function for an action inside the editor there is often a small text in the window under it that explains what the function is used for.
 
Level 4
Joined
Oct 8, 2023
Messages
21
Its better to use the Event - Starts the effect on an ability. Finishes casting an ability only triggers if the ability finishes casting which sounds neat except the units cast animation has to finish and if its interrupted the event doesnt fire even if the ability properly fires. Stops casting an ability triggers even if the ability is interrupted. For a faster event one can use Begins channeling an ability but that occurs before the ability has properly fired.

The condition ability being cast is only true for abilities being cast and not for order events. Targeted unit refers to something else entirely. When choosing a function for an action inside the editor there is often a small text in the window under it that explains what the function is used for.
Any wisdom for how I go about storing a unit's name when I use this ability on them? Because I had already checked what the whole Targeted Unit thing was for and couldn't understand it, nor could I find a way to do what I wanted with other functions or a google search, hence why I'm asking here directly
 
Level 24
Joined
Feb 27, 2019
Messages
833
What is known is that the event is triggered by an ABILITY. That ABILITY being cast is Talk.

There are only that many choices for which units name to set to the variable. Go through them and read their description. I am sure youll find what youre looking for in a couple of minutes.

To clarify: (Name of ()) is correct, the wrong part is (Targeted unit)
 
Last edited:
Level 4
Joined
Oct 8, 2023
Messages
21
It's always easy to say that sort of thing when you already know what you're doing. Instead of wasting my time through an hour of trial and error I was hoping to get an actual response here.

Edit:

worldedit_hXxW9aA2Kz.png


Genuinely not understanding what to try next. I can set TestArray1[1] and [2] to whatever I feel like on the map initialization and they show up on cast, but I can't get this value to change to the unit I'm targeting. I can get it to change to the spell's name, "Talk", through a similar action but not the targeted unit which is the goal.
 
Last edited:
Level 24
Joined
Feb 27, 2019
Messages
833
I am attempting to explain and point in the right direction rather than show directly so that hopefully the basic principles can be understood which can be more useful in the long run.

I seem to have misunderstood the finishes casting an ability event, apparently it doesnt even fire at all for some abilities but as I said before A unit starts the effect of an ability is better. Change the Event to A unit starts the effect of an ability and itll work great. Its a reliable event to use when dealing with detecting abilities being cast unless one specifically desires a different outcome or if a specific ability behaves in a unique way.

My best way to debug that I use all the time is to display a game message as you are doing, except in your case if the variable is empty it wont display any message anyway so there is no way to distinguish if the variable gets set wrong or if the event doesnt trigger or the condition is wrong.

EDIT: Another thing with Finishes casting an ability is that there doesnt seem to be any way to reference the target of the ability being cast, which seems to be the problem you are experiencing. Target unit of ability being cast is only valid as long as the spell is cast but when it finishes casting its not valid.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
@Duckfarter
I believe it should Display (null) in-game as well, so even if you're using the wrong event response the debug message will be of assistance. Also, I found the primary use of Finishes Casting is to detect when a Channeled ability has completed. That's because this Event only runs on a FULL channel and does so the exact moment the channeling stops without fail. I could be misremembering though.

@skemmerblef

Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime​


I'm not using you as an example and I don't want to point any fingers, but there are people on this site who seem to refuse to learn and have been asking for quick fix solutions that they can copy and paste for YEARS now. These people, and I mean no offense, are screwing themselves over in the long run since they still don't understand the basic fundamentals of the Trigger Editor. They're wasting their own time by trying to save time - they'd be able to solve their own problems in a few minutes had they just spent the time to learn the basics and advance from there.

The way I see it, you can do the following:

1) Spend many hours creating forum posts asking for quick fix triggers that you can mindlessly copy and paste. Then come back whenever you need to expand the given triggers because you don't understand them, which will happen anytime you want to add a new feature to them - so often. This problem grows as you pile on more and more triggers that you don't understand until your map is one big mess.

2) Spend a few hours on the forum asking for help or searching for an existing thread and then the rest of that time can be spent learning and understanding the trigger editor through trial and error and trying to do things yourself. Trial and error is the very thing that allowed Duckfarter to be able to answer your question.

(Note: When searching for existing threads, just about every question has been answered multiple times already on these forums - Just make sure to check the thread date and I recommend using Google search)

I prefer #2 for obvious reasons, and you will too if you want to make a great map. There's no better feeling than being able to do it yourself!

Again, I'm not trying to use you as an example, I can sympathize with your want for a quick solution in what is definitely a simple problem. It's just that you can save some time in the future by learning how to debug this now rather than us giving you the quick fix.
 
Last edited:
Level 4
Joined
Oct 8, 2023
Messages
21
"It's just that you can save some time in the future by learning how to debug this now rather than us giving you the quick fix."

If you'll entertain my rambling for a moment, that seems to be the disconnect between seasoned vets in a field and newcomers. You need a degree to teach, and to get one, you need to be taught, by a teacher, how to teach. You cannot say "learn how to teach :) it's easy, just be kind to students except when they're mean, and speak slowly so they can understand, give them quizzes and encourage them" and expect the would-be teacher to know why all of those things help another person retain knowledge for their own good. You cannot teach a newborn how to run without first teaching it to walk. In this case, after starting up the editor for the first time yesterday, I'm still learning how to walk. I did everything I could on my own within reason, but without more knowledge of things such as the terminology used for my problem for the sake of delving for another user with the same problem, I simply cannot find an answer without spending unnecessary hours slogging through unrelated forum responses that are more likely to confuse me than help me until I manage to brute force an answer. I can't speak for others who may be asking for quick fixes, but my intent with this thread's question was to learn what I was doing wrong, and using that knowledge gain insight into how other similar functions work so I didn't have to make another thread in 5 minutes. I understand your irritation there.

My point here is that while I appreciate the breadcrumbs, at this point someone like myself doesn't know that they came from bread, only that they are food. Due to the simplicity of the request (and the fact that it only seems to be an issue due to oddities with how the game engine processes things) it would be far more helpful to give a direct answer and let me figure out what went wrong in-between. Surely you've had to reverse-engineer for an assignment in tech school -- it's as valid of a method of learning as coding something from scratch.

With that said, it seems that my initial suspicions were confirmed; thank you Duck. I had a sinking feeling it was just a weird engine quirk that I had to learn somehow. My initial reasoning for using the on-casting-finish setup was because of a video I had watched on custom spells:
I suppose since this video was one of the very first things I'd watched to learn about the editor, I hadn't thought of the trigger's timing and how it would interact with other triggers that only seem to work "in the middle" of a sequence. Definitely felt like that possibility was buried underneath the hundreds of other things I was trying to grasp at the time. A tricky part of being a newcomer to any tricky hobby...

Below is my now-functioning trigger that does exactly as I wanted it to; gives a text response whenever I use "Talk", based on a certain value of the target.

  • JohnTalk
    • Events
      • Unit - John Mrgl 0007 <gen> Begins casting an ability
      • Unit - John Mrgl 0007 <gen> Is issued an order targeting an object
    • Conditions
      • (Ability being cast) Equal to Talk
    • Actions
      • Set TestArray1[3] = (Name of (Target unit of ability being cast))
      • Game - Display to (All players) the text: (Hello + TestArray1[3])
And a screenshot! Hello, Bailey, and Hello, John Mrgl!

war3_zr3nWoRjjw.jpg


Plenty of places for lessons, plenty of people willing to listen. I appreciate the help.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I understand exactly what you mean and again I wasn't trying to single you out, I simply wanted to use this opportunity to make a message to everyone. Lately I feel bombarded with "I don't understand, do it for me", which is rather frustrating and is the reason why I said what I said. Here's hoping that others will read this and be more open to learning!

Duckfarter could've been a bit more specific but I still think he explained things well. But for someone brand new it may have been better to say something along the lines of, "When you select an Event Response there is often a tip at the bottom of the window which explains which Event this Event Response is meant to be paired with". That and an explanation of how Events and Event Responses work together, but based on your trigger it appeared as though you knew already.

That aside, looking at your current "fixed" trigger, there's still an issue as well as a potential issue:

1)
  • Unit - John Mrgl 0007 <gen> Is issued an order targeting an object
This Event is doing nothing at the moment and serves no purpose here, which DuckFarter explained. If it appears to work, it's for the wrong reasons and you should delete it.

Events and Event Responses work like so:

For each Event in the game you have very specific Event Responses which can be used with them. These Event Responses are nothing more than global variables which get set automatically by the game - the same way that you Set your own variables. For example, here's an Event:
  • Events
    • Unit - A unit dies
And here are the Event Responses that can be used with it:
  • (Triggering unit)
  • (Dying unit)
  • (Killing unit)
Through these Event Responses you can also run functions to get the Player that these units belong to and other important information.

It's important to understand that NO other Event Responses will get set in response to this Event, so trying to reference them is a major mistake! So when you're trying to get the (Ability being cast) in response to an "A unit Issued an order" Event you're making this mistake - these are not paired together.

In the case of most casting Events you can use the following Event Responses:
  • (Ability being cast)
  • (Triggering unit)
  • (Casting unit)
  • (Target unit of ability being cast)
  • (Target point of ability being cast)
Note that (Target point of ability being cast) is only set if the ability actually targeted a Point, which can be used with abilities like Shockwave, Serpent Ward, Earthquake, etc. Also, the Finishes Casting event loses reference to everything target related.

You may have noticed the (Triggering unit) Event Response being used in both of these examples. This always gets set to the UNIT that is mentioned in a Unit Event -> A UNIT dies, A UNIT casts an ability, A UNIT enters a region, etc. It's recommended to use this Event over others as it retains it's reference even after the Wait action - an issue I imagine you'll run into in the future.

2)
  • Unit - John Mrgl 0007 <gen> Begins casting an ability
This Event fires when the unit begins winding up to cast the spell, so before the ability is actually executed. Executed is a term I use to describe that the ability has spent it's mana (if any), gone on cooldown (if any), and unleashed it's effects like summoning a pair wolves or throwing a hammer at the enemy unit.

The potential problem here is that you could interrupt the ability before it's executed and still cause the trigger to run. For example, if you issue a "Stop" order to your Murloc immediately after pressing the hotkey for Talk, the JohnTalk trigger will still run. The unit BEGAN to cast the ability, but it was never successful because you interrupted it. The user could exploit this by constantly casting/cancelling the ability, causing the trigger to run repeatedly while the ability is never actually executed and thus it's mana cost is never spent and cooldown never starts.

This may be fine and even ideal for your Talk ability since I imagine it doesn't have a cooldown or mana cost in the first place, however, it can cause A LOT of problems for other types of abilities/triggers.

One last thing. These casting Events are tied to the animation system used in Warcraft 3. To explain:

Unit's have a field called Cast Point, which is the amount of time it takes for their spells to execute.

This value is meant to be synced with the unit's "Spell" animation that their Model uses in order to execute the effects at an ideal time. In other words, this is used so that our Wizard's magical Fireball comes out of his staff after he has waved it around a bit, not before he has even lifted a finger. The added delay is also a nice mechanic for balancing combat and making things look pretty.

Unit's also have a field called Cast Backswing, which is the amount of time they spend playing the rest of their "Spell" animation after it's been executed. This can actually be cancelled and if you've ever heard of the term "animation cancelling" this is exactly what it applies to. Much like Cast Point this mechanic is here to make the animations play out nicely.

Taking those two Cast fields into consideration when dealing with the different Cast Events should help clear some stuff up.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Also, in that video, the guy teaches you how to create a Dummy unit the incorrect way.

To create a proper Dummy unit do the following:

First, copy and paste the Locust unit, as this covers almost everything needed. Second, change it's Model, Shadow, Attacks Enabled, and Movement Type to None and set it's Speed Base to 0. Third, you can use Vexorian's custom Dummy model instead of setting the Model to None, this is actually preferable as it has the proper Attachment Points needed to support Special Effects.

With these settings the Dummy unit can cast any number of abilities "instantly" at any number of targets. It also doesn't need to turn to face it's target to do so.

It's a shame but there's a lot of misinformation out there. The rest of the video seemed legit though, although I did notice some little things that bothered me.
 
Last edited:
Level 4
Joined
Oct 8, 2023
Messages
21
Thank you for the informative write-up! It's unfortunate that even a more recent tutorial like the mentioned one can have small bits of misinformation, but I suppose things like that can happen when muddling in a system's complexities. Any time I'm considering a write-up of my own for a niche hobby I stress about that. As for my code, that particular line was definitely unnecessary. I forgot to delete it after seeing how it didn't connect with the previously mentioned "target unit" stuff (and admittedly the thought hadn't even crossed my mind lol) but I'm happy the rest is functional. Clean code is good code.

With that odd quirk out of the way I should be able to get the rest of my dialogue system running. Just need to plug the unit's name into a check and have it spit out unique dialogue based on it... I'm thinking like, a string of 3 responses being picked at random should make things fun when exploring towns. Did something like that years ago when messing with C# so I'm sure I'll remember how after a bit of fiddling.

Thanks again for the assistance, and to anyone else in the future reading this thread, hope the discussion in this thread proves useful :peasant-grin:
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Thank you for the informative write-up! It's unfortunate that even a more recent tutorial like the mentioned one can have small bits of misinformation, but I suppose things like that can happen when muddling in a system's complexities. Any time I'm considering a write-up of my own for a niche hobby I stress about that. As for my code, that particular line was definitely unnecessary. I forgot to delete it after seeing how it didn't connect with the previously mentioned "target unit" stuff (and admittedly the thought hadn't even crossed my mind lol) but I'm happy the rest is functional. Clean code is good code.

With that odd quirk out of the way I should be able to get the rest of my dialogue system running. Just need to plug the unit's name into a check and have it spit out unique dialogue based on it... I'm thinking like, a string of 3 responses being picked at random should make things fun when exploring towns. Did something like that years ago when messing with C# so I'm sure I'll remember how after a bit of fiddling.

Thanks again for the assistance, and to anyone else in the future reading this thread, hope the discussion in this thread proves useful :peasant-grin:
No problem, if you are interested in programming and like C#, I'd check this out:
It's leagues above using the standard trigger editor and what I personally use.
 
Status
Not open for further replies.
Top