• 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 faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

How to spawn units in game

Status
Not open for further replies.
Level 12
Joined
Jul 17, 2013
Messages
544
I never thought i would have to ask such question, i generaly know how to make spawn action you set location then do action and remove location.
the problem lies somewhere else, i got way too much units put in editor so i would like to make some of them being spawned in game. but in editor i can easily set their roation position and everything i would like to spawn unit for them in game to be in such formation, what can u recommend me?
upload_2020-2-16_0-8-24.png


also will i have to use regions? i would have to create like 200 regions for all units in game i think so its not good idea too
 
Level 2
Joined
Feb 14, 2020
Messages
19
If you wanna spawn in a formation I recommend using a loop. Sometimes a loop in a loop.

This trigger for example spawns one row of 3 units.
  • Spawn
    • Events
      • Player - Player 1 (Red) issues Mouse Up event
    • Conditions
    • Actions
      • Set VariableSet ORIGINPOINT = (Mouse Position for Triggered Mouse Event)
      • Set VariableSet DIRECTION = 270.00
      • For each (Integer A) from 0 to 2, do (Actions)
        • Loop - Actions
          • Set VariableSet SPAWNPOINT = (ORIGINPOINT offset by (100.00 x (Real((Integer A)))) towards (DIRECTION + 90.00) degrees.)
          • Unit - Create 1 Footman for Player 1 (Red) at SPAWNPOINT facing DIRECTION degrees
          • Custom script: call RemoveLocation(udg_SPAWNPOINT)
      • Custom script: call RemoveLocation(udg_ORIGINPOINT)
By using the counter for the loop (Integer A) we can define spacing between the units.
(ORIGINPOINT offset by (100.00 x (Real((Integer A))))

The first iteration will spawn the unit in a place because 100 x 0 equals 0. In the next iteration its gonna be 100 x 1 which equals 100. The next unit is spawned with a distance of 100 from the first. And so it continues.

The direction is where theyre facing in the.. I dont know how to explain this in english. But the circle.
0 = Right
90 = Up
180 = Left
270 = Down

It is intervalbased so 0 = 360 = 720 and so on.

This means that when you take DIRECTION + 90 degrees we are suddenly not going the way the unit is facing but left of it. 0 = 360 = Right (left from our units pov)
In the same manner, + or - 180 would take you straight behind the unit.

By adding the loop to a loop you now not only expand by width but also by heigth!
  • Spawn
    • Events
      • Player - Player 1 (Red) issues Mouse Up event
    • Conditions
    • Actions
      • Set VariableSet DIRECTION = 270.00
      • Set VariableSet ORIGINPOINT = (Mouse Position for Triggered Mouse Event)
      • For each (Integer B) from 0 to 1, do (Actions)
        • Loop - Actions
          • Set VariableSet ANCHORPOINT = (ORIGINPOINT offset by (100.00 x (Real((Integer B)))) towards (DIRECTION - 180.00) degrees.)
          • For each (Integer A) from 0 to 2, do (Actions)
            • Loop - Actions
              • Set VariableSet SPAWNPOINT = (ANCHORPOINT offset by (100.00 x (Real((Integer A)))) towards (DIRECTION + 90.00) degrees.)
              • Unit - Create 1 Footman for Player 1 (Red) at SPAWNPOINT facing DIRECTION degrees
              • Custom script: call RemoveLocation(udg_SPAWNPOINT)
          • Custom script: call RemoveLocation(udg_ANCHORPOINT)
      • Custom script: call RemoveLocation(udg_ORIGINPOINT)
Attached the test map I used. If anything is unclear, feel free to ask.
 

Attachments

  • formationTest.w3m
    13.6 KB · Views: 36
Last edited:
Level 12
Joined
Jul 17, 2013
Messages
544
You can pre-place them in the editor, then during map initialization pick them all, add them to a spawn system and then remove them. This is how a lot of RPG maps do their creep respawn systems.
But still editor will count all the unit while saving? And thats my problem, i want to have less units pre placed for editor to work faster. But i need way to spawn them in same location as i pre placed them
 
But still editor will count all the unit while saving? And thats my problem, i want to have less units pre placed for editor to work faster. But i need way to spawn them in same location as i pre placed them
Do it with regions or points, then set the degrees at which they spawn manually.
 
Level 2
Joined
Feb 14, 2020
Messages
19
I expanded the test map to support pyramid formation so you have something to compare to. I left my first reply unedited since I modified the same test map.

  • Spawn
    • Events
      • Player - Player 1 (Red) issues Mouse Up event
    • Conditions
    • Actions
      • Set VariableSet DIRECTION = 270.00
      • Set VariableSet ORIGINPOINT = (Mouse Position for Triggered Mouse Event)
      • For each (Integer B) from 0 to 2, do (Actions)
        • Loop - Actions
          • Set VariableSet ANCHORPOINT = (ORIGINPOINT offset by (100.00 x (Real((Integer B)))) towards (DIRECTION - 180.00) degrees.)
          • Unit - Create 1 Footman for Player 1 (Red) at ANCHORPOINT facing DIRECTION degrees
          • For each (Integer A) from 1 to (Integer B), do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Integer B) Not equal to 0
                • Then - Actions
                  • Set VariableSet SPAWNPOINT = (ANCHORPOINT offset by (100.00 x (Real((Integer A)))) towards (DIRECTION + 90.00) degrees.)
                  • Unit - Create 1 Footman for Player 1 (Red) at SPAWNPOINT facing DIRECTION degrees
                  • Custom script: call RemoveLocation(udg_SPAWNPOINT)
                  • Set VariableSet SPAWNPOINT = (ANCHORPOINT offset by (100.00 x (Real((Integer A)))) towards (DIRECTION - 90.00) degrees.)
                  • Unit - Create 1 Footman for Player 1 (Red) at SPAWNPOINT facing DIRECTION degrees
                  • Custom script: call RemoveLocation(udg_SPAWNPOINT)
                • Else - Actions
                  • Do nothing
          • Custom script: call RemoveLocation(udg_ANCHORPOINT)
      • Custom script: call RemoveLocation(udg_ORIGINPOINT)
 

Attachments

  • formationTest.w3m
    13.8 KB · Views: 22
Level 11
Joined
Dec 11, 2009
Messages
234
You can place units in the Editor, then extract "war3map.j" file, find functions like CreateUnitsForPlayer0 and copy-paste the lines from there and paste to some trigger.
But it's kinda cancerous way of doing things. I would at least place them for, say, Player 23, or find some other way to "mark" them easily.
JASS:
//===========================================================================
function CreateUnitsForPlayer0 takes nothing returns nothing
    local player p= Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u=CreateUnit(p, 'Hblm', - 416.1, - 225.0, 207.263)
    set u=CreateUnit(p, 'hfoo', - 662.1, - 538.8, 128.478)
    set u=CreateUnit(p, 'hpea', - 843.3, - 475.1, 308.593)
    set u=CreateUnit(p, 'hrif', - 781.5, - 298.8, 1.681)
endfunction

//===========================================================================
function CreateUnitsForPlayer1 takes nothing returns nothing
    local player p= Player(1)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u=CreateUnit(p, 'hrif', 492.9, - 769.6, 80.115)
    set u=CreateUnit(p, 'hfoo', 297.5, - 863.1, 198.276)
    set u=CreateUnit(p, 'Hpal', 436.0, - 909.2, 147.660)
    call SelectHeroSkill(u, 'AHhb')
endfunction

//===========================================================================
function CreatePlayerBuildings takes nothing returns nothing
endfunction

//===========================================================================
function CreatePlayerUnits takes nothing returns nothing
    call CreateUnitsForPlayer0()
    call CreateUnitsForPlayer1()
endfunction

//===========================================================================
function CreateAllUnits takes nothing returns nothing
    call CreatePlayerBuildings()
    call CreatePlayerUnits()
endfunction
 
Status
Not open for further replies.
Top