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

Item drops! [Solved]

Level 11
Joined
Jun 20, 2017
Messages
380
Hey,
I have this trigger that randomly drops some items!
My problem is that it should not drop items when your hero is still near the enemy!
  • Gold Drops
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Owner of (Dying unit)) is in PlayerGroup_Humans.) Equal to True
    • Actions
      • Set VariableSet KillingUnit = (Killing unit)
      • Set VariableSet DyingUnit = (Dying unit)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Boolean_IsHunterNear Equal to True
        • Then - Actions
          • Set VariableSet Boolean_IsHunterNear = False
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of KillingUnit) is an enemy of (Owner of DyingUnit).) Equal to True
            • Then - Actions
              • Set VariableSet Integer_GoldDrops = (Random integer number between 1 and 100)
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Integer_GoldDrops Less than or equal to 30
                • Then - Actions
                  • Set VariableSet PositionOfUnit = (Position of DyingUnit)
                  • Item - Create Small Gold Coin at PositionOfUnit
                  • Set VariableSet Items_GoldDrops[1] = (Last created item)
                  • Custom script: call RemoveLocation(udg_PositionOfUnit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Integer_GoldDrops Less than or equal to 5
                • Then - Actions
                  • Set VariableSet PositionOfUnit = (Position of DyingUnit)
                  • Item - Create Large Gold Coin at PositionOfUnit
                  • Set VariableSet Items_GoldDrops[2] = (Last created item)
                  • Custom script: call RemoveLocation(udg_PositionOfUnit)
                • Else - Actions
            • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Boolean_IsHunterNear Equal to False
            • Then - Actions
              • Set VariableSet Boolean_IsHunterNear = True
              • -------- --------
              • Custom script: set bj_wantDestroyGroup = true
              • Set VariableSet PositionOfUnit = (Position of DyingUnit)
              • Unit Group - Pick every unit in (Units within 512.00 of PositionOfUnit.) and do (Actions)
                • Loop - Actions
                  • Set VariableSet PickedUnit = (Picked unit)
                  • -------- --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Unit-type of PickedUnit) Equal to Arthas Hunter
                          • (Unit-type of PickedUnit) Equal to Original Hunter
                    • Then - Actions
                      • Item - Remove Items_GoldDrops[1]
                      • Item - Remove Items_GoldDrops[2]
                    • Else - Actions
              • Custom script: call RemoveLocation(udg_PositionOfUnit)
            • Else - Actions

Also does this leak?
  • Custom script: set bj_wantDestroyGroup = true
  • Unit Group - Pick every unit in (Units within 512.00 of (Position of (Dying unit)).) and do (Actions)
    • Loop - Actions
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
If you see the words "Position of" you're creating a Point memory leak. UNLESS of course you're storing that in a Point variable, referencing the variable, and then removing it using RemoveLocation() before setting it again. Your use of bj_wantDestroyGroup will prevent the Unit Group leak, though.

Anyway, how about maintaining your heroes in a Unit Group throughout the game:
  • Events
    • A unit comes into play (sold, trained, created, etc)
  • Conditions
    • ((Triggering unit) is a Hero) Equal to True
    • ((Triggering unit) is an Illusion) Equal to False
    • ((Owner of (Triggering unit)) is in PlayerGroup_Hunters.) Equal to True
  • Actions
    • Unit Group - Add (Triggering unit) to UnitGroup_Hunters
Then when trying to determine if loot should drop you can take advantage of it:
  • Gold Drops
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Owner of (Dying unit)) is in PlayerGroup_Humans.) Equal to True
    • Actions
      • Set VariableSet KillingUnit = (Killing unit)
      • Set VariableSet DyingUnit = (Dying unit)
      • Set VariableSet Boolean_IsHunterNear = False
      • Set VariableSet Point_DropLootA = (Position of DyingUnit)
      • -------- --------
      • Unit Group - Pick every unit in UnitGroup_Hunters and do (Actions)
        • Loop - Actions
          • Set VariableSet Point_DropLootB = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Boolean_IsHunterNear Equal to False
              • (Distance between Point_DropLootA and Point_DropLootB Less than or equal to 512.00)
            • Then - Actions
              • Set VariableSet Boolean_IsHunterNear = True
              • Else - Actions
          • Custom script: call RemoveLocation( udg_Point_DropLootB )
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Boolean_IsHunterNear Equal to False
        • Then - Actions
          • -------- No nearby hunters, create the items --------
          • Item - Create Small Gold Coin at Point_DropLootA
        • Else - Actions
          • -------- Found nearby hunters, do nothing --------
      • -------- --------
      • Custom script: call RemoveLocation( udg_Point_DropLootA )
No need to create a brand new Unit Group and fill it with nearby units when you can simply compare the position of the Dead unit with all of the appropriate Heroes. This will be super efficient!

Note: You likely want to exclude dead heroes from being detected, in which case you can add a condition to the first If Then Else to exclude these:
  • If - Conditions
    • Boolean_IsHunterNear Equal to False
    • (Picked unit) is Alive Equal to True
    • (Distance between Point_DropLootA and Point_DropLootB Less than or equal to 512.00)
 
Last edited:
Level 11
Joined
Jun 20, 2017
Messages
380
Thanks.
I thought if I remove the group it would also remove the point!
Somehow it still drops the loot near the hero!
  • Hunters Create And Bonus
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Trained unit)) Equal to Arthas Hunter
          • (Unit-type of (Trained unit)) Equal to Original Hunter
    • Actions
      • Set VariableSet TrainedUnit = (Trained unit)
      • Unit Group - Add TrainedUnit to UnitGroup_Hunters
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
        • Then - Actions
          • Sound - Play gg_snd_Hint
          • Set VariableSet LastPlayedSound = (Last played sound)
          • Sound - Set volume of LastPlayedSound to 100.00%
          • Sound - Destroy LastPlayedSound
          • -------- --------
          • Hero - Set TrainedUnit Hero-level to ((Level of TrainedUnit) + 3), Hide level-up graphics
          • -------- --------
          • Game - Display to (All players) the text: ((Strings_PlayersColor[(Player number of (Owner of TrainedUnit))] + ((Name of (Owner of TrainedUnit)) + |r)) + ( has created the first Hunter at + (((String(Integers_Hours[1])) + ((String(Integers_Hours[0])) + :)) + (((String(Integers_Minutes[1])) + ((String
          • -------- --------
          • Set VariableSet PlayerGroup_Hunters = (Player group((Owner of TrainedUnit)))
          • Set VariableSet CenterOfRegion = (Center of 000 Hunters Pool <gen>)
          • Cinematic - Ping minimap for PlayerGroup_Hunters at CenterOfRegion for 5.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
          • Custom script: call RemoveLocation(udg_CenterOfRegion)
          • Custom script: call DestroyForce(udg_PlayerGroup_Hunters)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
              • Sound - Play gg_snd_Hint
              • Set VariableSet LastPlayedSound = (Last played sound)
              • Sound - Set volume of LastPlayedSound to 100.00%
              • Sound - Destroy LastPlayedSound
              • -------- --------
              • Hero - Set TrainedUnit Hero-level to ((Level of TrainedUnit) + 2), Hide level-up graphics
              • -------- --------
              • Game - Display to (All players) the text: ((Strings_PlayersColor[(Player number of (Owner of TrainedUnit))] + ((Name of (Owner of TrainedUnit)) + |r)) + ( has created the second Hunter at + (((String(Integers_Hours[1])) + ((String(Integers_Hours[0])) + :)) + (((String(Integers_Minutes[1])) + ((Strin
              • -------- --------
              • Set VariableSet PlayerGroup_Hunters = (Player group((Owner of TrainedUnit)))
              • Set VariableSet CenterOfRegion = (Center of 000 Hunters Pool <gen>)
              • Cinematic - Ping minimap for PlayerGroup_Hunters at CenterOfRegion for 5.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
              • Custom script: call RemoveLocation(udg_CenterOfRegion)
              • Custom script: call DestroyForce(udg_PlayerGroup_Hunters)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                • Then - Actions
                  • Sound - Play gg_snd_Hint
                  • Set VariableSet LastPlayedSound = (Last played sound)
                  • Sound - Set volume of LastPlayedSound to 100.00%
                  • Sound - Destroy LastPlayedSound
                  • -------- --------
                  • Hero - Set TrainedUnit Hero-level to ((Level of TrainedUnit) + 1), Hide level-up graphics
                  • -------- --------
                  • Game - Display to (All players) the text: ((Strings_PlayersColor[(Player number of (Owner of TrainedUnit))] + ((Name of (Owner of TrainedUnit)) + |r)) + ( has created the third Hunter at + (((String(Integers_Hours[1])) + ((String(Integers_Hours[0])) + :)) + (((String(Integers_Minutes[1])) + ((String
                  • -------- --------
                  • Set VariableSet PlayerGroup_Hunters = (Player group((Owner of TrainedUnit)))
                  • Set VariableSet CenterOfRegion = (Center of 000 Hunters Pool <gen>)
                  • Cinematic - Ping minimap for PlayerGroup_Hunters at CenterOfRegion for 5.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
                  • Custom script: call RemoveLocation(udg_CenterOfRegion)
                  • Custom script: call DestroyForce(udg_PlayerGroup_Hunters)
                • Else - Actions
  • Gold Drops
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Owner of (Dying unit)) is in PlayerGroup_Humans.) Equal to True
    • Actions
      • Set VariableSet KillingUnit = (Killing unit)
      • Set VariableSet DyingUnit = (Dying unit)
      • Set VariableSet Boolean_IsHunterNear = False
      • Set VariableSet Point_GoldDropsA = (Position of DyingUnit)
      • -------- --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in UnitGroup_Hunters and do (Actions)
        • Loop - Actions
          • Set VariableSet PickedUnit = (Picked unit)
          • Set VariableSet Point_GoldDropsB = (Position of PickedUnit)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Boolean_IsHunterNear Equal to False
              • (PickedUnit is alive) Equal to True
              • (Distance between Point_GoldDropsA and Point_GoldDropsB) Less than or equal to 512.00
            • Then - Actions
              • Set VariableSet Boolean_IsHunterNear = True
            • Else - Actions
          • -------- --------
          • Custom script: call RemoveLocation(udg_Point_GoldDropsB)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Boolean_IsHunterNear Equal to False
        • Then - Actions
          • -------- No nearby hunters, create the items. --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Owner of KillingUnit) is an enemy of (Owner of DyingUnit).) Equal to True
            • Then - Actions
              • Set VariableSet Integer_GoldDrops = (Random integer number between 1 and 100)
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Integer_GoldDrops Less than or equal to 30
                • Then - Actions
                  • Set VariableSet PositionOfUnit = (Position of DyingUnit)
                  • Item - Create Small Gold Coin at PositionOfUnit
                  • Custom script: call RemoveLocation(udg_PositionOfUnit)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Integer_GoldDrops Less than or equal to 3
                • Then - Actions
                  • Set VariableSet PositionOfUnit = (Position of DyingUnit)
                  • Item - Create Large Gold Coin at PositionOfUnit
                  • Custom script: call RemoveLocation(udg_PositionOfUnit)
                • Else - Actions
            • Else - Actions
              • -------- Found nearby hunters, do nothing. --------
        • Else - Actions
      • -------- --------
      • Custom script: call RemoveLocation(udg_Point_GoldDropsA)

I also have this follow up trigger that can collect those dropped items,
The problem is that I have a number of units with this ability, so if one of them uses this ability, even if it's far away from those items, it can still collect them! How can I prevent that?
  • Gold Collector
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Gold Collector [Custom]
    • Actions
      • Set VariableSet CastingUnit = (Casting unit)
      • -------- --------
      • Set VariableSet PositionOfUnits[1] = (Position of CastingUnit)
      • Item - Pick every item in (Playable map area) and do (Actions)
        • Loop - Actions
          • Set VariableSet PickedItem = (Picked item)
          • Set VariableSet PositionOfUnits[2] = (Position of PickedItem)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between PositionOfUnits[1] and PositionOfUnits[2]) Less than or equal to 512.00
            • Then - Actions
              • Hero - Give PickedItem to CastingUnit
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of PickedItem) Equal to Small Gold Coin
                • Then - Actions
                  • Custom script: set bj_wantDestroyGroup = true
                  • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of CastingUnit)) and do (Actions)
                    • Loop - Actions
                      • Set VariableSet PickedUnit = (Picked unit)
                      • -------- --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Or - Any (Conditions) are true
                            • Conditions
                              • (Unit-type of PickedUnit) Equal to Arthas Hunter
                        • Then - Actions
                          • Hero - Set PickedUnit Hero-level to ((Hero level of PickedUnit) + 1), Show level-up graphics
                        • Else - Actions
                • Else - Actions
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Item-type of PickedItem) Equal to Large Gold Coin
                • Then - Actions
                  • Custom script: set bj_wantDestroyGroup = true
                  • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of CastingUnit)) and do (Actions)
                    • Loop - Actions
                      • Set VariableSet PickedUnit = (Picked unit)
                      • -------- --------
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Or - Any (Conditions) are true
                            • Conditions
                              • (Unit-type of PickedUnit) Equal to Arthas Hunter
                        • Then - Actions
                          • Hero - Set PickedUnit Hero-level to ((Hero level of PickedUnit) + 2), Show level-up graphics
                        • Else - Actions
                • Else - Actions
            • Else - Actions
          • -------- --------
          • Item - Remove PickedItem
          • Custom script: call RemoveLocation(udg_PositionOfUnits[2])
      • -------- --------
      • Custom script: call RemoveLocation(udg_PositionOfUnits[1])
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
I think you're confused about memory leaks and the concept of a temporary variable and a constant variable. Here's the basic idea:

A temporary variable is something that you set, use, and then destroy (although destroying depends on whether it's a variable type that can leak). The idea is that the value of the variable can differ each time you set it. For example, you would use a temporary Unit Group variable when damaging "nearby units" in one of your triggers. This is because you don't need to track those units for more than a moment as you damage them. Furthermore, you don't want to have leftover units from before getting damaged again. So you create a brand new Unit Group each time.

A constant variable is something that you set ONCE and NEVER destroy. In some cases you don't even need to Set it. UnitGroup_Hunters is meant to be constant, meaning it exists throughout the entire game and never gets set to anything else or destroyed/removed. HOWEVER, you can still manually Add/Remove heroes to and from it. This is fine since that doesn't destroy or create a new Unit Group, it simply modifies the existing one.

Memory leaks only apply to temporary variables. For this to make sense, first you need to understand that a Variable is simply a reference to a piece of data and not the data itself. So a Unit Group variable is a reference to a Unit Group object. Also, this Unit Group variable can only reference one Unit Group object at a time. So ask yourself, what happens to the old Unit Group object that you were referencing when you tell your variable to reference a new one? The answer is simple: That old Unit Group object becomes a memory leak. This is because 1) It wasn't destroyed and more importantly 2) It can no longer be destroyed, you literally have no way of accessing it anymore. That's why our constant variables never leak -> We never change what they're set to, so we never lose our original reference. All of this would make more sense with a bit of Jass knowledge, I recommend messing around with Points, Unit Groups and Timers in Jass to understand the concept of a variable and the creation of the object that it's tracking.

With that in mind, let's address some issues in your triggers:
  • Hunters Create And Bonus
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Trained unit-type) Equal to Arthas Hunter
          • (Trained unit-type) Equal to Original Hunter
    • Actions
      • Set VariableSet TrainedUnit = (Trained unit)
      • Unit Group - Add TrainedUnit to UnitGroup_Hunters
      • Set VariableSet Hunter_Hero[(Player number of (Owner of TrainedUnit)) = TrainedUnit
      • -------- ... --------
1) I changed the Conditions to use the (Trained unit-type) function. This was probably unnecessary but it's needed when using the other "training" Events.

2) I added a new constant variable for tracking the Hero for the Player. This could serve useful in your other triggers to get a direct reference to a Hero instead of relying on Unit Groups to "search" for them. Note that this Hunter_Hero array won't work if a Player can control more than one Hunter. Instead, you could rely on a Unit Group array to track their multiple Hunters.

  • Gold Drops
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Owner of (Dying unit)) is in PlayerGroup_Humans.) Equal to True
      • ((Owner of Killing unit) is an enemy of (Owner of (Dying unit)).) Equal to True
    • Actions
      • Set VariableSet DyingUnit = (Dying unit)
      • Set VariableSet KillingUnit = (Killing unit)
      • Set VariableSet Boolean_IsHunterNear = False
      • Set VariableSet Point_GoldDropsA = (Position of DyingUnit)
      • -------- --------
      • Unit Group - Pick every unit in UnitGroup_Hunters and do (Actions)
        • Loop - Actions
          • Set VariableSet PickedUnit = (Picked unit)
          • Set VariableSet Point_GoldDropsB = (Position of PickedUnit)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Boolean_IsHunterNear Equal to False
              • (PickedUnit is alive) Equal to True
              • (Distance between Point_GoldDropsA and Point_GoldDropsB) Less than or equal to 512.00
            • Then - Actions
              • Set VariableSet Boolean_IsHunterNear = True
            • Else - Actions
          • -------- --------
          • Custom script: call RemoveLocation(udg_Point_GoldDropsB)
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Boolean_IsHunterNear Equal to False
        • Then - Actions
          • -------- No nearby hunters -> Create items! --------
          • Set VariableSet Integer_GoldDrops = (Random integer number between 1 and 100)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Integer_GoldDrops Less than or equal to 30
            • Then - Actions
              • Item - Create Small Gold Coin at Point_GoldDropsA
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Integer_GoldDrops Less than or equal to 3
            • Then - Actions
              • Item - Create Large Gold Coin at Point_GoldDropsA
            • Else - Actions
        • Else - Actions
          • -------- We found some nearby hunters -> Do nothing! --------
      • -------- --------
      • Custom script: call RemoveLocation(udg_Point_GoldDropsA)
1) I removed the "set bj_wantDestroyGroup = true" action since it was destroying our constant variable. Like I said before, UnitGroup_Hunters should never be set to something new and it should never be destroyed. You wouldn't be able to use the Unit Group after destroying it, thus breaking any triggers that rely on it.

2) I moved the "killing unit is an enemy" logic into the initial Conditions since it made no sense to check for that so late into the trigger. In other words, there's no reason to calculate if a Hunter is nearby if you're just going to do nothing with that information.

3) I made use of our Point_GoldDropsA variable when creating the coins since that was already set to the position of the (Dying unit).


Regarding your follow up question, that trigger SHOULD work once you fix the above problems.
But one thing to note is that you're Removing the item regardless of whether you give it to the caster:
  • Item - Remove PickedItem
You probably want to place it beneath the "Give Item" action. That being said, I don't really understand why you'd want to Remove the item in the first place... Are all of the items guaranteed to be Power-Ups or something?
 
Last edited:
Level 11
Joined
Jun 20, 2017
Messages
380
Thanks for the useful information.
I changed the Conditions to use the (Trained unit-type) function
  • Or - Any (Conditions) are true
    • Conditions
      • (Trained unit-type) Equal to Arthas Hunter
      • (Trained unit-type) Equal to Original Hunter
Is this the same? Because I could not find that!
  • Or - Any (Conditions) are true
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Arthas Hunter
      • (Unit-type of (Trained unit)) Equal to Original Hunter
How can I prevent that trigger from dropping 2 gold?
Like it shouldn't drop 1 small coin and 1 big coin at the same time in the same position!

I don't really understand why you'd want to Remove the item in the first place... Are all of the items guaranteed to be Power-Ups or something?
Yeah, they are.

Is there a better way to do this?
  • Gold Collector
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Gold Collector [Custom]
    • Actions
      • Set VariableSet CastingUnit = (Casting unit)
      • -------- --------
      • Set VariableSet PositionOfUnits[1] = (Position of CastingUnit)
      • Item - Pick every item in (Playable map area) and do (Actions)
        • Loop - Actions
          • Set VariableSet PickedItem = (Picked item)
          • Set VariableSet PositionOfUnits[2] = (Position of PickedItem)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-class of PickedItem) Equal to Powerup
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between PositionOfUnits[1] and PositionOfUnits[2]) Less than or equal to 512.00
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Item-type of PickedItem) Equal to Small Gold Coin
                    • Then - Actions
                      • Custom script: set bj_wantDestroyGroup = true
                      • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of CastingUnit)) and do (Actions)
                        • Loop - Actions
                          • Set VariableSet PickedUnit = (Picked unit)
                          • -------- --------
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • Or - Any (Conditions) are true
                                • Conditions
                                  • (Unit-type of PickedUnit) Equal to Arthas Hunter
                              • (PickedUnit is alive) Equal to True
                            • Then - Actions
                              • Hero - Give PickedItem to Units_Hunters[(Player number of (Owner of CastingUnit))]
                              • Item - Remove PickedItem
                            • Else - Actions
                    • Else - Actions
                  • -------- --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Item-type of PickedItem) Equal to Large Gold Coin
                    • Then - Actions
                      • Custom script: set bj_wantDestroyGroup = true
                      • Unit Group - Pick every unit in (Units in (Playable map area) owned by (Owner of CastingUnit)) and do (Actions)
                        • Loop - Actions
                          • Set VariableSet PickedUnit = (Picked unit)
                          • -------- --------
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • Or - Any (Conditions) are true
                                • Conditions
                                  • (Unit-type of PickedUnit) Equal to Arthas Hunter
                              • (PickedUnit is alive) Equal to True
                            • Then - Actions
                              • Hero - Give PickedItem to Units_Hunters[(Player number of (Owner of CastingUnit))]
                              • Item - Remove PickedItem
                            • Else - Actions
                    • Else - Actions
                • Else - Actions
            • Else - Actions
          • -------- --------
          • Custom script: call RemoveLocation(udg_PositionOfUnits[2])
      • -------- --------
      • Custom script: call RemoveLocation(udg_PositionOfUnits[1])
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
1) (Trained unit-type) is a Function, it's found in the window prior to where you found (Trained unit). Not very important though, both should work here.

2) If you want to prevent both items from dropping then take advantage of the ELSE section of your If Then Else actions.

IF you rolled a 3 or less -> THEN create a big coin ELSE IF you rolled a 30 or less -> THEN create a small coin.

3) The better way would be to delete the Unit Group stuff in there and simplify it to this:
  • Gold Collector
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Gold Collector [Custom]
      • (Unit-type of Units_Hunters[(Player number of (Owner of (Casting unit)))]) Equal to Arthas Hunter
    • Actions
      • Set VariableSet CastingUnit = (Casting unit)
      • -------- --------
      • Set VariableSet PositionOfUnits[1] = (Position of CastingUnit)
      • -------- --------
      • Item - Pick every item in (Playable map area) and do (Actions)
        • Loop - Actions
          • Set VariableSet PickedItem = (Picked item)
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-class of PickedItem) Equal to Powerup
            • Then - Actions
              • Set VariableSet PositionOfUnits[2] = (Position of PickedItem)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between PositionOfUnits[1] and PositionOfUnits[2]) Less than or equal to 512.00
                • Then - Actions
                  • Hero - Give PickedItem to Units_Hunters[(Player number of (Owner of CastingUnit))]
                  • Item - Remove PickedItem
                • Else - Actions
              • Custom script: call RemoveLocation(udg_PositionOfUnits[2])
            • Else - Actions
          • -------- --------
      • -------- --------
      • Custom script: call RemoveLocation(udg_PositionOfUnits[1])
Now the trigger only runs if the caster owns an Arthas Hunter. It also references the Arthas Hunter directly instead of looking for it in a Unit Group. I also organized things in a way that will be more efficient. Note how I only Set variables that I'm actually going to use.
 
Last edited:
Top