Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

How to get the number on items in a region

Discussion in 'Triggers & Scripts' started by Shiroaisu, Jan 18, 2010.

  1. Shiroaisu

    Shiroaisu

    Joined:
    Jul 17, 2008
    Messages:
    202
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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
     
  2. Cyclotrutan

    Cyclotrutan

    Joined:
    Dec 13, 2009
    Messages:
    181
    Resources:
    2
    Maps:
    2
    Resources:
    2
    there is a Unit - Count Items Carried function. returns integer.
     
  3. Shiroaisu

    Shiroaisu

    Joined:
    Jul 17, 2008
    Messages:
    202
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Yeah but that counts every item, i wanted to count only a specific item..

    help pls
     
  4. Cyclotrutan

    Cyclotrutan

    Joined:
    Dec 13, 2009
    Messages:
    181
    Resources:
    2
    Maps:
    2
    Resources:
    2
    set YourInteger = 1
    For each integer YourInteger from 1 to 6 do the following actions
    If Item carried by Hero YourHero in slot YourInteger = YourItem
    set YourOtherInteger = YourOtherInteger + 1

    dunno if its possible with an implemented function, that would be my first guess
     
  5. Shiroaisu

    Shiroaisu

    Joined:
    Jul 17, 2008
    Messages:
    202
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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...
     
  6. Cyclotrutan

    Cyclotrutan

    Joined:
    Dec 13, 2009
    Messages:
    181
    Resources:
    2
    Maps:
    2
    Resources:
    2
    then you must loop through all units on the map, in addition to the loop i posted above
     
  7. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    • 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))
     
  8. Shiroaisu

    Shiroaisu

    Joined:
    Jul 17, 2008
    Messages:
    202
    Resources:
    1
    Maps:
    1
    Resources:
    1
    ok tks that trigger works fine,

    but what about counting items droped in the map?

    sory for soooo many questions btw -.-
     
  9. Cyclotrutan

    Cyclotrutan

    Joined:
    Dec 13, 2009
    Messages:
    181
    Resources:
    2
    Maps:
    2
    Resources:
    2
    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
     
  10. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    Code (vJASS):
    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.
     
  11. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    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))
     
  12. Cyclotrutan

    Cyclotrutan

    Joined:
    Dec 13, 2009
    Messages:
    181
    Resources:
    2
    Maps:
    2
    Resources:
    2
    thats far better than my idea
     
  13. Shiroaisu

    Shiroaisu

    Joined:
    Jul 17, 2008
    Messages:
    202
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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: Jan 19, 2010
  14. Berb

    Berb

    Joined:
    Jan 21, 2006
    Messages:
    2,539
    Resources:
    2
    JASS:
    2
    Resources:
    2
    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.
     
  15. Shiroaisu

    Shiroaisu

    Joined:
    Jul 17, 2008
    Messages:
    202
    Resources:
    1
    Maps:
    1
    Resources:
    1
    ty dude, looks like it was really simple the solution xD