• 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] Same item check

Status
Not open for further replies.
Level 3
Joined
Sep 20, 2010
Messages
29
Hey guys. How to check if hero has two items of same type in inventory? If checking using boolean condition (hero manipulating item has item of type (item type of item being manipulated)) it will return true anyway, because it's checking taken item as item of this type in inventory
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
  • Checkem
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • For each (Integer B) from 1 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Integer A) Not equal to (Integer B)
                  • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to (Item-type of (Item carried by (Triggering unit) in slot (Integer B)))
                  • (Item carried by (Triggering unit) in slot (Integer A)) Not equal to No item
                  • (Item carried by (Triggering unit) in slot (Integer B)) Not equal to No item
                • Then - Actions
                  • Game - Display to (All players) the text: yep
                • Else - Actions
This will print a result for each item in the pair. If you're only looking for one pair, just add a Skip Remaining Actions, otherwise the trigger becomes a bit more complicated as it has to record a list of items.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
  • Checkem
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • For each (Integer B) from 2 to 6, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Integer A) Not equal to (Integer B)
                  • (Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to (Item-type of (Item carried by (Triggering unit) in slot (Integer B)))
                  • (Item carried by (Triggering unit) in slot (Integer A)) Not equal to No item
                • Then - Actions
                  • Game - Display to (All players) the text: yep
                • Else - Actions

I optimized it a lot, with just small edits. Now instead of looping 36 times, it loops only 25 times. And no need to thest if both compared items are null.

Optimally you would do only 15 loops with a looping method.

1-2 | 1-3 | 1-4 | 1-5 | 1-6
2-3 | 2-4 | 2-5 | 2-6
3-4 | 3-5 | 3-6
4-5 | 4-6
5-6

That would be:

  • Untitled Trigger 048
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
    • Actions
      • Set i1 = 1
      • Custom script: loop
      • Set i2 = (i1 + 1)
      • Custom script: loop
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Item carried by (Triggering unit) in slot i1) Not equal to No item
          • (Item-type of (Item carried by (Triggering unit) in slot i1)) Equal to (Item-type of (Item carried by (Triggering unit) in slot i2))
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: (yes + ((String(i1)) + ( and + (String(i2)))))
        • Else - Actions
      • Custom script: exitwhen udg_i2 == 6
      • Set i2 = (i2 + 1)
      • Custom script: endloop
      • Custom script: exitwhen udg_i1 == 5
      • Set i1 = (i1 + 1)
      • Custom script: endloop
 
Level 3
Joined
Sep 20, 2010
Messages
29
Thx guys! Used Maker's one. +rep to all for help=)
Sorry for late responce, was afk theese days
 
Status
Not open for further replies.
Top