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

Unit loses an item

Level 5
Joined
Mar 18, 2023
Messages
52
I feel like something so simple should be easy to do but for some reason I can't get it to work lol. I only need a simple fix as this is just to detect if a player has multiple copies of the item and it doesn't remove them from the unit group. I've only recently started working with items so lmk if there should be anything else I need to know
  • aaa
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to |cffff0000Dragonslayer Bow|r
    • Actions
      • Set VariableSet TempUnit[0] = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (TempUnit[0] has an item of type |cffff0000Dragonslayer Bow|r) Equal to False
        • Then - Actions
          • Unit - Remove Draconic Force Agi (Dragonslayer Bow) from TempUnit[0]
          • Unit Group - Remove TempUnit[0] from DragonslayBowUG.
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,877
The "Acquired/Lost Item" Events seem to run too early, therefore the unit still "has the item" in this case. In other words, it's detecting the lost item.

Here's a neat fix that you can reuse throughout your triggers.

Create a new trigger and create these new variables:
  • Get Item Count
    • Events
    • Conditions
    • Actions
      • -------- HOW TO USE: You must Set the G_Item_Unit and G_Item_Type variables before running this trigger! --------
      • Set Variable G_Item_Count = 0
      • For each integer (G_Item_Slot) from 1 to 6 do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by G_Item_Unit in slot G_Item_Slot)) Equal to G_Item_Type
            • Then - Actions
              • Set Variable G_Item_Count = (G_Item_Count + 1)
            • Else - Actions
This counts up how many of a specific Item-Type the given Unit has.

Now in your "aaa" trigger you can rely on this trigger + some of it's variables to determine if the Unit has the item or not:
  • aaa
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to |cffff0000Dragonslayer Bow|r
    • Actions
      • Set Variable G_Item_Unit = (Triggering unit)
      • Set Variable G_Item_Type = |cffff0000Dragonslayer Bow|r
      • Trigger - Run Get Item Count <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • G_Item_Count Less than or equal to 1
        • Then - Actions
          • Unit Group - Remove G_Item_Unit from DragonslayBowUG.
          • Unit - Remove Draconic Force Agi (Dragonslayer Bow) from G_Item_Unit
        • Else - Actions
If the unit had two of these bows and lost one, G_Item_Count would be equal to 2 (since it'll count the lost one as well). If it only had one bow then it would be equal to 1.
 
Last edited:
Level 5
Joined
Mar 18, 2023
Messages
52
The "Acquired/Lost Item" Events seem to run too early, therefore the unit still "has the item" in this case. In other words, it's detecting the lost item.

Here's a neat fix that you can reuse throughout your triggers.

Create a new trigger and create these new variables:
  • Get Item Count
    • Events
    • Conditions
    • Actions
      • -------- HOW TO USE: You must Set the G_Item_Unit and G_Item_Type variables before running this trigger! --------
      • Set Variable G_Item_Count = 0
      • For each integer (G_Item_Slot) from 1 to 6 do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item carried by G_Item_Unit in slot G_Item_Slot)) Equal to G_Item_Type
            • Then - Actions
              • Set Variable G_Item_Count = (G_Item_Count + 1)
            • Else - Actions
This counts up how many of a specific Item-Type the given Unit has.

Now in your "aaa" trigger you can rely on this trigger + some of it's variables to determine if the Unit has the item or not:
  • aaa
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to |cffff0000Dragonslayer Bow|r
    • Actions
      • Set Variable G_Item_Unit = (Triggering unit)
      • Set Variable G_Item_Type = |cffff0000Dragonslayer Bow|r
      • Trigger - Run Get Item Count <gen> (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • G_Item_Count Less than or equal to 1
        • Then - Actions
          • Unit Group - Remove G_Item_Unit from DragonslayBowUG.
          • Unit - Remove Draconic Force Agi (Dragonslayer Bow) from G_Item_Unit
        • Else - Actions
If the unit had two of these bows and lost one, G_Item_Count would be equal to 2 (since it'll count the lost one as well). If it only had one bow then it would be equal to 1.
OH its a timing issue. Ight well that's really good to know. I have 1 for Acquire item with same condition that works, so I'm assuming I leave that be. I recreate what you posted later today and get back to you on it. Thank you Uncle!
 
Top