• 🏆 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!

How can I detect more than one item of the same type in region?

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
As said above you haven't exactly stated what you want to do...

However, you can do a "pick all items in region" function, then add a condition that the item is the specific item type. If you an integer variable you could then add the number of charges to this variable, depends how/what you want to count though
 
Level 11
Joined
Oct 9, 2015
Messages
721
I'm making a crafting system that uses itens on the ground to create refined itens. Example: to make a sharp stones, you would need two stones (with 1 charge each) on the grund or one stone with 2 charges (two stones stacked together). After the crafting is done, if the stone has no charges left it is then removed. After that process, a Sharp Stone item is created on the ground. I'm not sure if you can compreend my objective perfectly.
 
Level 14
Joined
Jul 1, 2008
Messages
1,314
Do, what Karzama said: Pick all items in region.

You can check for the item type as well for the item charges (integer comparisson).

I would check first for all stones in your region/range, if there is a stone with >=2 charges for your example. If there is reduce charges (if 0 remove stone) and create sharp stone. If there is no item with >=2 charges, then do a second loop, which searches for several items of type stone.

I think this is your question? Just save the first item of type stone in a temp variable ot type item called Stone_1. and ask before storing a stone into it, if it is null or if there is already a stone saved. If there was one saved, you obviously found a second stone and can combine them. Dont forget to set Stone_1 = null (no item) after the search algorythm.
 
Level 11
Joined
Oct 9, 2015
Messages
721
this is what I've got so far, but I'm not sure of what I'm doing:

  • Pedra Afiada
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Sharp Stone (Crafting)
    • Actions
      • Item - Pick every item in (Region centered at (Position of (Triggering unit)) with size (500.00, 500.00)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Picked item)) Equal to Stone
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Charges remaining in (Picked item)) Greater than or equal to 2
                • Then - Actions
                  • Item - Set charges remaining in (Picked item) to ((Charges remaining in (Picked item)) - 2)
                  • Item - Create Sharp Stone at (Position of (Picked item))
                  • Item - Set charges remaining in (Last created item) to 1
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Charges remaining in (Picked item)) Equal to 0
                    • Then - Actions
                      • Item - Remove (Picked item)
                    • Else - Actions
                • Else - Actions
                  • Set Stone_1 = (Picked item)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Stone_1 Equal to No item
                    • Then - Actions
                      • Set Stone_1 = (Picked item)
                    • Else - Actions
            • Else - Actions
 
Last edited:
Level 14
Joined
Jul 1, 2008
Messages
1,314
I would use 2 loops: I inserted a boolean Found_Stone for the search in to your example.

  • Pedra Afiada
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Sharp Stone (Crafting)
    • Actions
      • Set Found_Stone = false
      • Item - Pick every item in (Region centered at (Position of (Triggering unit)) with size (500.00, 500.00)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Picked item)) Equal to Stone
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Charges remaining in (Picked item)) Greater than or equal to 2
                • Then - Actions
                  • Item - Set charges remaining in (Picked item) to ((Charges remaining in (Picked item)) - 2)
                  • Item - Create Sharp Stone at (Position of (Picked item))
                  • Item - Set charges remaining in (Last created item) to 1
                  • Set Found_Stone = true
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Charges remaining in (Picked item)) Equal to 0
                    • Then - Actions
                      • Item - Remove (Picked item)
                    • Else - Actions
                • Else - Actions
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Found_Stone = false
    • Then - Actions
    • Set Stone_1 = no item
    • Item - Pick every item in (Region centered at (Position of (Triggering unit)) with size (500.00, 500.00)) and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Item-type of (Picked item)) Equal to Stone
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Stone_Found == False
              • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Stone_1 == no item
                • Then - Actions
                  • Set Stone_1 = Picked Item
                • Else - Actions
                  • Item - Remove (Picked item)
                  • Item - Remove (Stone_1)
                  • Item - Create Sharp Stone at (Position of (Picked item))
                  • Item - Set charges remaining in (Last created item) to 1
                  • Set Found_Stone = true
  • Set Found_Stone = false
  • Set Stone_1 = no item
of course it would be possible and nicer to have only one loop, but I have a hard time with these giant walls of GUI code. But it works like this. You could optimize it later to have one loop doing this
 
Status
Not open for further replies.
Top