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

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!
 
Level 7
Joined
May 30, 2018
Messages
290
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?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
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
 
Level 7
Joined
May 30, 2018
Messages
290
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!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
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.
Top