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

[General] Spawn/despawn trigger

Status
Not open for further replies.
Level 8
Joined
Jun 13, 2010
Messages
344
Hi, I want to make a map initially empty from units to save CPU, but have them spawn as you progress to the area containing them.

Also it may not be the excact same number, type or position of units every time. Some positions and unit types are default.

So far I have concidered just placing a region for EVERY unit and just manually selecting every region for which to spawn what unit and checking conditions for certain vairities.

Is it really the easiest and simplest way?

To paint you a fast picture, units spawning is regarding a castle, where the units spawn when the enemy wave attacks, despawn at end and fully respawns/resets for the next wave. New units may be placed as you upgrade the castle. Like Legion TD map.

Full map idea here:
 
Level 6
Joined
Jun 4, 2009
Messages
91
I think the easiest way, from an editor perspective, would be to place the units on the map where you want them to be using the regular unit palette.
Then when the game initializes, go through all these units (maybe filter by unity type, player, or units in a region), store the properties you need (position and unit type) in some array, and remove the unit from the game.
Then, when you need to spawn them, you can go through each unit in the array, give it, say, 90% chance to spawn, and maybe some offset depending on how you want things to vary.

Whether that's actually practical (won't slow your game at launch) really depends on how many units you have to process. So I would recommend to give it a try and see if it works for you.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
For the Grid I would do something like this:
  • Create Grid Points
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet GridPoint[0] = (Center of Start <gen>)
      • Set VariableSet GridX = (X of GridPoint[0])
      • Set VariableSet GridY = (Y of GridPoint[0])
      • -------- --------
      • -------- 6 Columns, 6 Rows: --------
      • For each (Integer A) from 1 to 36, do (Actions)
        • Loop - Actions
          • Set VariableSet GridPoint[(Integer A)] = (Point(GridX, GridY))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Integer A) mod 6) Not equal to 0
            • Then - Actions
              • Set VariableSet GridX = (GridX + 128.00)
            • Else - Actions
              • Set VariableSet GridX = (X of GridPoint[0])
              • Set VariableSet GridY = (GridY - 128.00)
      • -------- --------
      • Custom script: call RemoveLocation(udg_GridPoint[0])
setting up grid.png


You can then reference these Points when spawning in units.
  • Unit - Create 1 Footman at GridPoint[1]
Keep in mind Floating Point precision when using Arithmetic with Reals. You can end up having a slight offset on your X/Y values which could screw things up. This is why it's usually better to work with Integers since they'll always be precise. There's better methods out there but this should at least get you started. GUI is rather limiting so using Lua/Jass would be ideal if you know how to code.

I don't fully understand what you mean by "spawn as you progress to the area containing them", because from what I gather based on your description of the map, waves of enemies are attacking you, not the other way around. So would there be any preplaced enemies in the first place? And for allied units, like the Castle, I imagine you could preplace the Buildings since there wouldn't be too many of them. 30 or so preplaced units won't be an issue.
 
Last edited:
Level 8
Joined
Jun 13, 2010
Messages
344
For the Grid I would do something like this:
  • Create Grid Points
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet GridPoint[0] = (Center of Start <gen>)
      • Set VariableSet GridX = (X of GridPoint[0])
      • Set VariableSet GridY = (Y of GridPoint[0])
      • -------- --------
      • -------- 6 Columns, 6 Rows: --------
      • For each (Integer A) from 1 to 36, do (Actions)
        • Loop - Actions
          • Set VariableSet GridPoint[(Integer A)] = (Point(GridX, GridY))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Integer A) mod 6) Not equal to 0
            • Then - Actions
              • Set VariableSet GridX = (GridX + 128.00)
            • Else - Actions
              • Set VariableSet GridX = (X of GridPoint[0])
              • Set VariableSet GridY = (GridY - 128.00)
      • -------- --------
      • Custom script: call RemoveLocation(udg_GridPoint[0])
View attachment 392172

You can then reference these Points when spawning in units.
  • Unit - Create 1 Footman at GridPoint[1]
Keep in mind Floating Point precision when using Arithmetic with Reals. You can end up having a slight offset on your X/Y values which could screw things up. This is why it's usually better to work with Integers since they'll always be precise. There's better methods out there but this should at least get you started. GUI is rather limiting so using Lua/Jass would be ideal if you know how to code.

I don't fully understand what you mean by "spawn as you progress to the area containing them", because from what I gather based on your description of the map, waves of enemies are attacking you, not the other way around. So would there be any preplaced enemies in the first place? And for allied units, like the Castle, I imagine you could preplace the Buildings since there wouldn't be too many of them. 30 or so preplaced units won't be an issue.

What I mean is, the castle spawns units to stand against every enemy wave. When the wave is over, castle units are reset.

Also randomizing units spawned for the castle won't work, as what may vairy is ypu may as the player unlock Knights as an example. So this will change the pattern of spawned units. Also you may increase the amount of spawned units for the castle.

By progressing I refer to the idea of the map where the castle is divided into 5 zones. I do not want all zones of the castle having spawned units as we may hit about 600+ units in total (without taking enemy units into account).
 
Status
Not open for further replies.
Top