[Trigger] How does one use a unit's name to activate a specific trigger?

Level 4
Joined
Oct 8, 2023
Messages
21
For instance,

I have an ability that "hails" a target. Adds them to a group, removes all previous hailed targets from the group. I'm not sure though, how do I tell the editor "the added unit's name is Sentry4, so run Sentry4Talk"? How do I combine unit's name with another word, in this case Talk, and then have the game run "Sentry4Talk"?
  • IntuitionFocus
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Casting unit) Equal to Player1Character
      • (Ability being cast) Equal to Intuition
    • Actions
      • Unit Group - Pick every unit in IntuitionTarget and do (Unit Group - Remove (Picked unit) from IntuitionTarget)
      • Unit Group - Add (Target unit of ability being cast) to IntuitionTarget
Does it have something to do with Hashtables? It feels simple but I've been durdling around with it for a while and can't figure it out.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Hashtables could be useful if you wanted a robust system, but if there's only going to be a few Sentrys then you could go the lazy route. Also, Arrays are an option, which are basically less advanced Hashtables.

1) You likely want to use the Event "A unit Starts the effect of an ability". This is because "Begins" occurs during the preparation stage which can be interrupted with a simple Stop order while still causing the trigger to fire. You may be making this mistake throughout your triggers, it's common since the Event phrasing is misleading.

2) There's an Action for clearing a Unit Group -> Remove all units from IntuitionGroup. But why do you need a Unit Group if you only ever track one unit at a time? That's what Unit variables are for, a Group is for when you need to track more than one.

3) Use an If Then Else to check the name during the Actions, and there's a String function for a Unit's name.
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Triggering unit) Equal to Player1Character
    • (Ability being cast) Equal to Intuition
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Name of (Target unit of ability being cast)) Equal to Sentry1
      • Then - Actions
        • Trigger - Run Sentry1Talk (ignoring conditions)
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Name of (Target unit of ability being cast)) Equal to Sentry2
      • Then - Actions
        • Trigger - Run Sentry2Talk (ignoring conditions)
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Name of (Target unit of ability being cast)) Equal to Sentry3
      • Then - Actions
        • Trigger - Run Sentry3Talk (ignoring conditions)
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Name of (Target unit of ability being cast)) Equal to Sentry4
      • Then - Actions
        • Trigger - Run Sentry4Talk (ignoring conditions)
      • Else - Actions
If you explain in greater detail what you're trying to accomplish I could provide a better solution than this, String comparisons seem very unnecessary.
 
Last edited:
Level 4
Joined
Oct 8, 2023
Messages
21
I'm looking to avoid the case-by-case condition of "sentry1234567" etc because my campaign features respawning enemies which you can use the skill Intuition on. Kinda like old Everquest's Consider feature if you're familiar with that? I'll change the trigger as well to be on start, I think I have it messed up in a few places. Thanks for pointing that out.

I'll gladly give a rundown of what I'm trying to do, to the best of my understanding;

So, I have the ability Intuition. It's a simple ability you can use on NPC targets. A trigger activates when the ability is used; this is the part I need help with. I need that trigger to store the name value of the NPC temporarily, so that I can then run another trigger based off of that stored name value. So, if I use Intuition on a Blue Crab, the name Blue Crab would be stored, and I could then use that stored name to run another specific trigger named something like BlueCrabIntuitionResponse. With this I could simplify adding more units in the future; like Burning Skeleton to activate BurningSkeletonIntuitionResponse, and it would work with named NPC's too. If I have to name NPC's BLUECRAB or COOLSKELETON to make this all work that's fine, I just need to directly combine their name with "IntuitionResponse" and then have, for instance, BLUECRABIntuitionResponse" run.

What the response itself does is simple and I've got that covered; it just gives some game relevant information like if the NPC has a quest, if it's dangerous, etc.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Okay, so Strings are generally a bad solution outside of their specific use cases, I would use Integers and Arrays. Remember, an Integer can represent anything:
  • Intuition Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- The number of unit types that you can cast Intuition on: -------
      • Set Variable Intuition_Total_Types = 2
      • -------- -------
      • -------- The different unit types that you can cast Intuition on: -------
      • Set Variable Intuition_Type[1] = Footman
      • Set Variable Intuition_Type[2] = Grunt
      • -------- -------
      • -------- The triggers that run in response to casting Intuition on one of the above unit-types: --------
      • Set Variable Intuition_Trigger[1] = FootmanIntuitionResponse <gen>
      • Set Variable Intuition_Trigger[2] = GruntIntuitionResponse <gen>
      • -------- -------
      • -------- A boolean to control whether a single trigger can run more than once (just an example, you probably don't even want this): --------
      • Set Variable Intuition_Trigger_Enabled[1] = True
      • Set Variable Intuition_Trigger_Enabled[2] = True
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Intuition
  • Actions
    • For each (Integer X) from 1 to Intution_Total_Types, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Unit-type of (Target unit of ability being cast)) Equal to Inuition_Type[X]
            • Intuition_Trigger_Enabled[X] Equal to True
          • Then - Actions
            • Set Variable Intuition_Trigger_Enabled[X] = False
            • Trigger - Run Intuition_Trigger[X] (ignoring conditions)
            • Skip remaining actions
          • Else - Actions
So with Arrays + For Loops you will not only organize your triggers but make them more dynamic and expandable. Now anytime you want to introduce a new Intuition target you simply visit the "Setup" trigger, increase the Intuition_Total_Types by 1, and copy and paste some existing Arrays to be filled with data related to your new unit.

I'm using Unit-Types in this example but you could easily switch that to a Unit variable. For example, here's the cast trigger using a Unit Comparison:
  • If - Conditions
    • (Target unit of ability being cast) Equal to Inuition_Type[X]
    • ...
Also, this solution can support a massive number of different targets, but at some point you would want to think about switching to a Hashtable or Unit Indexing to scale better. The performance should be perfectly fine even with ~100 units in the Array, but it's something to think about, especially if say the Ability was spammed 20+ times per second.
 
Last edited:
Top