• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[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 33
Joined
Mar 27, 2008
Messages
8,035
Here's a test map.

EDIT:
On what Event do you want to check the item of the same type in inventory ???
Upon acquiring items ?
At any time ?

What I did was checking same item onAcquiring while ruler did onAnyTime.
 

Attachments

  • Check Same Item.w3x
    13 KB · Views: 58
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • 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