• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Detecting 2 or more items of same type carried by unit

Status
Not open for further replies.
Hello, dear Hivers :D

As title says, is there a way to check if hero/unit carries 2 same items in it's invertory, I know it does, I just can't figure it out.

Any ideas how to manage that?

Note:
Using two different variables for two same items, will result as there is only one item of that type in invertory, not as two. (I tried, it doesn't work) Seems WE just takes it as same :<

Thanks!

~Berz
 
Level 3
Joined
Jul 20, 2008
Messages
41
You could check for the item you want, remove it and then check for more same items. In the end you can return them all.
 
Level 3
Joined
Jul 20, 2008
Messages
41
What I meant was
You check than an item exists. If it does then remove it and set counter=counter+1
Repeat with a loop until the hero has no more items of the same type.
Counter is the number of these items your hero had at start so in the end you can give them all back.
:thumbs_up:
 
Level 19
Joined
Oct 29, 2007
Messages
1,184
  • Actions
    • Set tmp_unit = YOUR UNIT
    • For each (Integer A) from 1 to 6, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Item carried by tmp_unit in slot (Integer A)) Not equal to No item
            • (Item-type of (Item carried by tmp_unit in slot (Integer A))) Equal to Tome of Experience
          • Then - Actions
            • Set itemTOME = (itemTOME + 1)
          • Else - Actions
Then if itemTOME is equal to 2 or more the hero has two or more of the tome in his inventory. I think this would work.
 
Hmm... Thanks you two, I'll check it out :D

Edit:

Make it [Solved]

And for those who would like to know more about this...

  • Pendant of Energy
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set Item_Owner = (Triggering unit)
      • Set Item1 = Pendant of Mana
      • Set Item2 = Pendant of Energy
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item_Owner has an item of type Item1) Equal to True
        • Then - Actions
          • Set Item_Counter = (Item_Counter + 1)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Item_Counter Equal to 2
        • Then - Actions
          • Do your stuff
          • Set Item_Counter = 0
        • Else - Actions
Remember to do this at the end: Set Item_Counter = 0
 
Last edited:
Level 2
Joined
Jul 4, 2009
Messages
10
A bit offtopic:
Check item classification is better if you only need a weapon/armor/misc item system(one per type on hero at 1 time)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Just because I had some time, I created a trigger that checks for any two of the same items, no need to specify the item type.

  • Untitled Trigger 003 Copy
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set itemOwner = (Hero manipulating item)
      • Set itemType = (Item-type of (Item being manipulated))
      • For each (Integer loopA) from 1 to 5, do (Actions)
        • Loop - Actions
          • For each (Integer loopB) from 2 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 itemOwner in slot loopA)) Equal to (Item-type of (Item carried by itemOwner in slot loopB))
                  • (Item-type of (Item carried by itemOwner in slot loopA)) Equal to itemType
                  • loopA Not equal to loopB
                • Then - Actions
                • Else - Actions
You can break out of the loop by setting loopA = 5 and loopB = 6 at the "Then" branch to save some CPU time, or jump out of the trigger by using "Skip remaining actions".

Maybe it will be useful for someone one day :D
 
Status
Not open for further replies.
Top