• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Count Items in Region

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
Hey People,

I made this trigger.
  • Spawn Items
    • Events
      • Time - Every 0.35 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet ItemLocation = (Random point in Region 000 <gen>)
      • Item - Create SpawnedItems[(Random integer number between 1 and 2)] at ItemLocation
      • Custom script: call RemoveLocation (udg_ItemLocation)
Now I need a way to count the amount of spawned items, so they stop spawning when a certain number of items is reached in the region. When the number falls under the max value, items should start Spawning again.

I just find the integer for "Count Units" , but is there something similar for items?

Thanks!
 
The exact trigger you're looking for is in this thread:
Help, pick every item region < 5 then spawn item.

And the action:
  • Item - Pick every item in Region000 <gen> and do (Actions)

So I came up with this:

  • Limit 1
    • Events
      • Time - Every 0.45 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet ItemLocation = (Random point in Region 000 <gen>)
      • Set VariableSet IntegerVariable = 0
      • Item - Pick every item in Region 000 <gen> and do (Actions)
        • Loop - Actions
          • Set VariableSet IntegerVariable = (IntegerVariable + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerVariable Less than or equal to 500
            • Then - Actions
              • Item - Create SpawnedItems[(Random integer number between 1 and 3)] at ItemLocation
            • Else - Actions
      • Custom script: call RemoveLocation (udg_ItemLocation)
Did I do the leak clear of the location in the right spot or does it need to be inside the if then else function?
 
Move:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
So it's right above:
  • Custom script: call RemoveLocation (udg_ItemLocation)
So it's outside of the Pick every Item function.

And yes, that's the correct spot for the remove location. Otherwise, you'd attempt to remove the location X times, X being the total number of Items in Region 000.

If you did it the wrong way it would look like this:
Create a Point
Pick every Item and do:
Remove Point <-- this happens once for EACH picked item
 
Move:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
So it's right above:
  • Custom script: call RemoveLocation (udg_ItemLocation)
So it's outside of the Pick every Item function.

And yes, that's the correct spot for the remove location. Otherwise, you'd attempt to remove the location X times, X being the total number of Items in Region 000.

If you did it the wrong way it would look like this:
Create a Point
Pick every Item and do:
Remove Point <-- this happens once for EACH picked item

Works perfect!
 
Also, a very minor optimization would be to only create the Point if you actually create the Item.
  • Actions
    • Set VariableSet IntegerVariable = 0
    • Item - Pick every item in Region 000 and do (Actions)
      • Loop - Actions
        • Set VariableSet IntegerVariable = (IntegerVariable + 1)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • IntegerVariable Less than 500
      • Then - Actions
        • Set VariableSet ItemLocation = (Random point in Region 000)
        • Item - Create SpawnedItems[(Random integer number between 1 and 3)] at ItemLocation
        • Custom script: call RemoveLocation (udg_ItemLocation)
      • Else - Actions
 
Last edited:
Status
Not open for further replies.
Back
Top