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

How to get the number on items in a region

Status
Not open for further replies.
Level 6
Joined
Jul 17, 2008
Messages
185
hi...

Basically what i wanna do is to check how many items of a single type there are in map so I can use this is a condition, for example:

If number of *Item* in (playable map area) equal to 10

then kill everyone

and i also want to know how to count with the items the heroes or other units have in their inventories.

Pls help
 
Level 6
Joined
Jul 17, 2008
Messages
185
that would probably work but that's not what I'm looking for :p

that trigger would only count the items in 1 unit, and i want it to count the items of every unit in map, a totality of how much items of that type are in all the units in the map...
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
  • Untitled Trigger 089
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set Temp_Integer_1 = 0
      • Set Temp_Group_1 = (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))
      • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
        • Loop - Actions
          • 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-type of (Item carried by (Picked unit) in slot (Integer A))) Equal to Claws of Attack +15
                • Then - Actions
                  • Set Temp_Integer_1 = (Temp_Integer_1 + 1)
                • Else - Actions
      • Custom script: call DestroyGroup(udg_Temp_Group_1)
      • Game - Display to (All players) the text: (String(Temp_Integer_1))
 
that is complicated, but at least it should work.

set Item = Random item from your region matching Custom value of matching item = 0

now something to check if an item has been set to the variable or if there is no item matching the conditions. (getting coordinates of the item for example)

if an item was found:
set Custom value of item = 1
set CountItems = CountItems + 1

if no item was found, reset the custom value to zero.
Pick every item matching Custom value of Matching Item = 1
set Custom value of picked items = 0
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
JASS:
function EnumItemsInRect takes rect r, boolexpr condition, code action returns nothing

This function does not account for items in unit inventories.

  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Item - Pick every item in (Playable map area) and do (Item - Move (Picked item) to (Center of (Playable map area)))
This is an example of the function being used in GUI code. The function will pick every item in the Playable map area and move it to the center of the Playable map area.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
And here it is added to the trigger:

  • Untitled Trigger 089
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set Temp_Integer_1 = 0
      • Set Temp_Group_1 = (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))
      • Unit Group - Pick every unit in Temp_Group_1 and do (Actions)
        • Loop - Actions
          • 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-type of (Item carried by (Picked unit) in slot (Integer A))) Equal to Claws of Attack +15
                • Then - Actions
                  • Set Temp_Integer_1 = (Temp_Integer_1 + 1)
                • Else - Actions
      • Custom script: call DestroyGroup(udg_Temp_Group_1)
      • Item - Pick every item in (Playable map area) 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 Claws of Attack +15
            • Then - Actions
              • Set Temp_Integer_1 = (Temp_Integer_1 + 1)
            • Else - Actions
      • Game - Display to (All players) the text: (String(Temp_Integer_1))
 
Level 6
Joined
Jul 17, 2008
Messages
185
ok tks everyone... ^^

Hmm just another question:

  • count eggs
    • Events
      • Player - Player 1 (Red) types a chat message containing a as An exact match
    • Conditions
    • Actions
      • Set EggInGame = 0
      • Item - Pick every item in (Playable map area) 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 Teleporting Egg
            • Then - Actions
              • Set EggInGame = (EggInGame + 1)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • EggInGame Greater than or equal to 10
        • Then - Actions
        • Else - Actions
          • Item - Create Teleporting Egg at (Center of (Playable map area))
          • Game - Display to (All players) the text: (String(EggInGame))
      • Set EggInGame = 0
using this trigger...

imagine that there are 10 eggs on the floor, we write "a" nothing happens, ok till here, then a unit picks 1 egg, we write "a" a new egg is spawned, till here its working as intended, BUT when a egg is destroyed it doesnt count :S imagine that i destroy one of those 10 eggs, we write "a" but... no egg even with only 9 ingame :S Help pls

Infact... i tried this simple trigger:

  • count eggs
    • Events
      • Player - Player 1 (Red) types a chat message containing a as An exact match
    • Conditions
    • Actions
      • Set EggInGame = 0
      • Item - Pick every item in (Playable map area) 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 Teleporting Egg
            • Then - Actions
              • Set EggInGame = (EggInGame + 1)
            • Else - Actions
      • Game - Display to (All players) the text: (String(EggInGame))
and i started with 10 eggs in the ground... wen i killed one it would give me 10 eggs instead of 9

When i kill the items i guess they are not removed from the game.. how can i fixx this??
 
Last edited:
Level 18
Joined
Jan 21, 2006
Messages
2,552
Don't add one if the item's life (real comparison) is below 0.405. There is a better function in JASS called GetWidgetLife but you don't have that, so just use Item life.

Also, if an item is "hidden" this means that it is in a unit's inventory. I don't think that the Item region enumerator recognizes these items anyways though.
 
Status
Not open for further replies.
Top