• 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.

[Solved] Global Unit Event for Specific Type Help

Level 8
Joined
Jul 21, 2015
Messages
143
Hi I would like to create a trigger,

I want it to make it so that when an item is dropped by a (specific unit type 1) of (specific item type), then a (specific unit type 2) will do an action. The problem I'm having is storing a unit that doesn't exist as a variable to sequence the rest of the trigger to occur. This is what I have so far.

CURRENT TRIGGER:

  • Tame a Panther
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Night Elf Runner
          • Or - Any (Conditions) are true
            • Conditions
              • (Item-type of (Item being manipulated)) Equal to Deer Meat
              • (Item-type of (Item being manipulated)) Equal to Frog Meat
              • (Item-type of (Item being manipulated)) Equal to Rabbit Meat
              • (Item-type of (Item being manipulated)) Equal to Raccoon Meat
    • Actions
      • Wait 4.00 seconds
      • Set VariableSet TamePanther = Panther 0017 <gen>
      • Unit - Order TamePanther to Right-Click (Item being manipulated)
The Panther 0017 unit is just for testing purposes.
I want it to be global because I want any panther to be able to be tamed (or to pick up an item) if its dropped in front of them. Like a treat.
So once again I would like a (specific unit type 2) to pick up an item when it is dropped in front of them. I would like it to occur globally, and not have to do a periodic timer. I am assuming I have to store the (specific unit type 2) as a temporary variable but don't know enough if hashtables are needed or if I should just create a unit group (but that could get messy). Thanks for any assistance!
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Trigger conditions are an "and" by default so you don't need that outer And. If there are many panthers then it will be a little difficult to find the 'correct' one every time. The 'best' messy method is to look in a small circle around the caster to see if there are any panthers near the caster, and then assume that's the right one if it exists. You could pick the closest, I suppose, but that's a little more work.
 
Level 30
Joined
Aug 29, 2012
Messages
1,382
Something like that could be a starting point

  • Actions
    • Set VariableSet MeatPosition = (Position of (Item being manipulated))
    • Set VariableSet PanthersGroup = (Units within 600.00 of MeatPosition matching (((Unit-type of (Matching unit)) Equal to Panther) and (((Matching unit) is alive) Equal to True)).)
    • Set VariableSet MyPanther = (Random unit from PanthersGroup)
    • Unit - Order MyPanther to Right-Click (Item being manipulated)
The wait could potentially create some problems though I think
 
Level 8
Joined
Jul 21, 2015
Messages
143
Trigger conditions are an "and" by default so you don't need that outer And. If there are many panthers then it will be a little difficult to find the 'correct' one every time. The 'best' messy method is to look in a small circle around the caster to see if there are any panthers near the caster, and then assume that's the right one if it exists. You could pick the closest, I suppose, but that's a little more work.
Thank you sir very much I appreicate the guidance and the tip! I will go down this route then I believe! You're the best!
 
Level 8
Joined
Jul 21, 2015
Messages
143
Something like that could be a starting point

  • Actions
    • Set VariableSet MeatPosition = (Position of (Item being manipulated))
    • Set VariableSet PanthersGroup = (Units within 600.00 of MeatPosition matching (((Unit-type of (Matching unit)) Equal to Panther) and (((Matching unit) is alive) Equal to True)).)
    • Set VariableSet MyPanther = (Random unit from PanthersGroup)
    • Unit - Order MyPanther to Right-Click (Item being manipulated)
The wait could potentially create some problems though I think
This is perfect for me because I need to see things visually. I appreciate you writing this down in trigger format. My map project appreciates it!
 
Level 8
Joined
Jul 21, 2015
Messages
143
Thanks for the help. I'm marking this as SOLVED. Thanks for the help, if i knew how to give karma i would to the helpful people. I know there are probably leaks but I'll address them later. Thanks!

New Trigger:

  • Tame a Panther
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Night Elf Runner
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Deer Meat
          • (Item-type of (Item being manipulated)) Equal to Frog Meat
          • (Item-type of (Item being manipulated)) Equal to Rabbit Meat
          • (Item-type of (Item being manipulated)) Equal to Raccoon Meat
    • Actions
      • Set VariableSet MeatPosition = (Position of (Item being manipulated))
      • Set VariableSet PantherGroup = (Units within 600.00 of MeatPosition matching (((Unit-type of (Matching unit)) Equal to Panther) and (((Matching unit) is alive) Equal to True)).)
      • Set VariableSet TamePanther = (Random unit from PantherGroup)
      • Wait 4.00 seconds
      • Unit - Order TamePanther to Right-Click (Item being manipulated)
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
One problem I can see is that if 2 meats are dropped in less than 4 seconds, then the 1st tamepanther variable would be overwritten by the next one and not right click the item, you might want to keep that in mind
A quick and dirty fix, shadow the global variable:
  • Tame a Panther
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Night Elf Runner
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Deer Meat
          • (Item-type of (Item being manipulated)) Equal to Frog Meat
          • (Item-type of (Item being manipulated)) Equal to Rabbit Meat
          • (Item-type of (Item being manipulated)) Equal to Raccoon Meat
    • Actions
      • Custom script: local unit udg_TamePanther
      • Set VariableSet MeatPosition = (Position of (Item being manipulated))
      • Set VariableSet PantherGroup = (Units within 600.00 of MeatPosition matching (((Unit-type of (Matching unit)) Equal to Panther) and (((Matching unit) is alive) Equal to True)).)
      • Set VariableSet TamePanther = (Random unit from PantherGroup)
      • Custom script: call RemoveLocation( udg_MeatPosition )
      • Custom script: call DestroyGroup( udg_PantherGroup )
      • Wait 4.00 seconds
      • Unit - Order TamePanther to Right-Click (Item being manipulated)
      • Custom script: set udg_TamePanther = null
Now TamePanther is treated as a local variable. (Item being manipulated) may need the same treatment as well.

I also cleared the two memory leaks plus the new one I introduced (null).
 
Level 8
Joined
Jul 21, 2015
Messages
143
One problem I can see is that if 2 meats are dropped in less than 4 seconds, then the 1st tamepanther variable would be overwritten by the next one and not right click the item, you might want to keep that in mind
Oh crap on a stick, yeah I didn't even think about that. I will have to maybe, solve for that pre-emptively. Thanks for the heads up dude!
 
Level 8
Joined
Jul 21, 2015
Messages
143
A quick and dirty fix, shadow the global variable:
  • Tame a Panther
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Night Elf Runner
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Deer Meat
          • (Item-type of (Item being manipulated)) Equal to Frog Meat
          • (Item-type of (Item being manipulated)) Equal to Rabbit Meat
          • (Item-type of (Item being manipulated)) Equal to Raccoon Meat
    • Actions
      • Custom script: local unit udg_TamePanther
      • Set VariableSet MeatPosition = (Position of (Item being manipulated))
      • Set VariableSet PantherGroup = (Units within 600.00 of MeatPosition matching (((Unit-type of (Matching unit)) Equal to Panther) and (((Matching unit) is alive) Equal to True)).)
      • Set VariableSet TamePanther = (Random unit from PantherGroup)
      • Custom script: call RemoveLocation( udg_MeatPosition )
      • Custom script: call DestroyGroup( udg_PantherGroup )
      • Wait 4.00 seconds
      • Unit - Order TamePanther to Right-Click (Item being manipulated)
      • Custom script: set udg_TamePanther = null
Now TamePanther is treated as a local variable. (Item being manipulated) may need the same treatment as well.

I also cleared the two memory leaks plus the new one I introduced (null).
damn dude this very very helpful, I will incorporate this trigger instead!! you're the best Uncle! thanks a bunch
 
Level 8
Joined
Jul 21, 2015
Messages
143
New and Updated Trigger

  • Tame a Panther
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Night Elf Runner
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Deer Meat
          • (Item-type of (Item being manipulated)) Equal to Frog Meat
          • (Item-type of (Item being manipulated)) Equal to Rabbit Meat
          • (Item-type of (Item being manipulated)) Equal to Raccoon Meat
    • Actions
      • Custom script: local unit udg_TamePanther
      • Set VariableSet MeatPosition = (Position of (Item being manipulated))
      • Set VariableSet GroupPanther = (Units within 600.00 of MeatPosition matching (((Unit-type of (Matching unit)) Equal to Panther) and ((((Matching unit) is alive) Equal to True) and ((Owner of (Matching unit)) Equal to Neutral Passive))).)
      • Set VariableSet TamePanther = (Random unit from GroupPanther)
      • Custom script: call RemoveLocation( udg_MeatPosition )
      • Custom script: call DestroyGroup( udg_GroupPanther )
      • Wait 4.00 seconds
      • Unit - Order TamePanther to Right-Click (Item being manipulated)
      • Wait 4.00 seconds
      • Unit - Change ownership of TamePanther to (Owner of (Triggering unit)) and Change color
      • Custom script: set udg_TamePanther = null
thanks again to all of yall for the assistance!
 
Last edited:
Level 8
Joined
Jul 21, 2015
Messages
143
Make sure you Null the TamePanther variable when you're finally done referencing it. Your Change ownership action won't work since you've nulled the variable beforehand. Nulling a variable sets it's value to "nothing".
thank you I believe i ran into that problem when i tested it, but then I edited the trigger (so its at the end) like you suggested, hopefully no more issues bro
 
Level 8
Joined
Jul 21, 2015
Messages
143
Edit: for some reason only frog meat item type triggers the trigger to work correctly (as in raccoon meat, deer meat, and rabbit meat dont work), anyone have any insight as to why this is? I can probably figure it out but im not sure what the cause could be
 
Top