• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Spawning units in interval from UnitTypeArray

Status
Not open for further replies.
Level 2
Joined
May 25, 2020
Messages
13
Hello everyone. I have a problem with my own Tower defense map.

I have a simple trigger when player buys a unit from shop, the units gets teleported to "unit queue region" from which I want the units to be summoned by 2 periodicaly in like 0.5s interval.

For instance - Player 1 buys like 20 units, they all go into queue and each 0.5s only 2 random units are summoned to go somewhere until the queue is empty.

I have tried adding each bought unit to UnitTypeArray and then using FOREACH summoning the units in interval but with players buying like 1000+ units in 1 game, this array will be brutally big and might cause problems, doesnt it?


Thanks for any help. BTW. I am a bit newbie and don't know a lot about JASS.
 
Level 12
Joined
Jan 30, 2020
Messages
875
There is no reason your array could not handle 1000+ units.

I am not really accustomed to these new TDs as I returned after 16 years, but I suppose these units do not spawn at every level ?
Because if they don't, you just need to reset the index to 1 because the old values won't matter anymore (and unit-types are integers so they don't need to be destroyed / nulled because they cannot leak).

Or, if the players can buy units to send at any moment, just store the current max index, increase it every time a player buys a unit and that you save this unit-type, and decrease it by 1 it every time you spawn one of these units.
 
Level 2
Joined
May 25, 2020
Messages
13
There is no reason your array could not handle 1000+ units.

I am not really accustomed to these new TDs as I returned after 16 years, but I suppose these units do not spawn at every level ?
Because if they don't, you just need to reset the index to 1 because the old values won't matter anymore (and unit-types are integers so they don't need to be destroyed / nulled because they cannot leak).

Or, if the players can buy units to send at any moment, just store the current max index, increase it every time a player buys a unit and that you save this unit-type, and decrease it by 1 it every time you spawn one of these units.


Hello Macadamia and thanks for reply.

Just like you said. Units do not spawn every level - there are no levels at all. Its PVP TD where one player can send units to another player anytime he wants. Good example is - Tower Wars 1.1, or Line tower wars.

I am doing the periodical sending because i do not want some player to SPAM the units which will result in units going in 1 big group. So I want the units to be sent in like 0.5s interval so they go one at the time from the unit queue.

I will try doing what you said, helped me a lot.

So If i get it right for instance:

globalvar = 1

//Player buys unit:
Unittype_array[globalvar]=boughtunit
globalvar=globalvar+1

//Sending that unit
Event -Every 0.5s
Create 1 Unittype_array[globalvar] at Center_of_myregion facing xxxxx....
globalvar=globalvar-1
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,510
If the Units are chosen at random then you could just use a Unit Group (Array). Note: I believe you need to adjust the Unit Group's size to the maximum number of players or it won't work.

Edit:
Attached an example map.

This is the trigger for setting up all of the variables.
QueueRegion = where your units go while queued.
SpawnRegion = where the units are moved to after being picked from the queue.
PeriodicTrigger = the periodic interval associated with the player.
  • UQ Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- P1 Variables --------
      • Set VariableSet UQ_QueueRegion[1] = P1QueueRegion <gen>
      • Set VariableSet UQ_SpawnRegion[1] = P1Spawn <gen>
      • Set VariableSet UQ_PeriodicTrigger[1] = UQ Move Units P1 <gen>
      • -------- --------
      • -------- P2 Variables --------
      • Set VariableSet UQ_QueueRegion[2] = P2QueueRegion <gen>
      • Set VariableSet UQ_SpawnRegion[2] = P2Spawn <gen>
      • Set VariableSet UQ_PeriodicTrigger[2] = UQ Move Units P2 <gen>
This is the trigger for Buying Units (Adds the Sold Unit to your Unit Group and turns on the Periodic Interval)
  • UQ Buy Unit
    • Events
      • Unit - A unit Sells a unit
    • Conditions
    • Actions
      • Set VariableSet PN = (Player number of (Triggering player))
      • Unit Group - Add (Sold unit) to UQ_Group[PN]
      • Set VariableSet TempPoint = (Center of UQ_QueueRegion[PN])
      • Unit - Move (Sold unit) instantly to TempPoint
      • Custom script: call RemoveLocation (udg_TempPoint)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in UQ_Group[PN]) Equal to 1
        • Then - Actions
          • Trigger - Turn on UQ_PeriodicTrigger[PN]
        • Else - Actions
This is the Periodic Interval trigger that moves the Player's Units out of the Queue zone. Each Player needs one of these triggers, but they're very easy to setup, all you have to do is set PN to be equal to the desired player's number. This trigger is for Player 1 (Red), so PN is set to 1:
  • UQ Move Units P1
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • -------- Set PN to be equal to the desired Player's Number (1 = Player 1 (Red), 2 = Player 2 (Blue), etc...) and the trigger will do the rest --------
      • Set VariableSet PN = 1
      • Set VariableSet TempInteger = 0
      • Unit Group - Pick every unit in UQ_Group[PN] and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInteger Less than 2
            • Then - Actions
              • Set VariableSet TempInteger = (TempInteger + 1)
              • Set VariableSet TempPoint = (Center of UQ_SpawnRegion[PN])
              • Unit - Move (Picked unit) instantly to TempPoint
              • Custom script: call RemoveLocation (udg_TempPoint)
              • Unit Group - Remove (Picked unit) from UQ_Group[PN].
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in UQ_Group[PN]) Equal to 0
        • Then - Actions
          • Trigger - Turn off UQ_PeriodicTrigger[PN]
        • Else - Actions
 

Attachments

  • Unit Queue 1.w3m
    20.4 KB · Views: 31
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
Nice, @Uncle !

Thats quite a smart alternative. I don't expect any performance issue with handling this kind of group vs an array, because there is absolutely nothing intensive at play there.

This seems to be the best way to achieve what OP is trying to !
 
Level 2
Joined
May 25, 2020
Messages
13
@Macadamia and @Uncle,

thank you both for effort! Sorry for my replies, unfortunately my posts have to be moderated before they are revealed to public. It helped me a lot, i am currently working on it and it looks that it is going to work perfectly as I wanted! :) Cheers
 
Level 12
Joined
Jan 30, 2020
Messages
875
Great news, I hope everything will get fine.
If you encounter any other issue on the matter, don't hesitate !
 
Status
Not open for further replies.
Top