• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Spawn units outside of map bounds?

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
You can move the unit there using the SetUnitX/Y functions:
  • Set Variable MyPoint = (Somewhere out of bounds)
  • Unit - Create 1 Footman at MyPoint...
  • Set Variable MyUnit = (Last created unit)
  • Custom script: call SetUnitX( udg_MyUnit, GetLocationX(udg_MyPoint) )
  • Custom script: call SetUnitY( udg_MyUnit, GetLocationY(udg_MyPoint) )
  • Custom script: call RemoveLocation( udg_MyPoint)
 
Level 22
Joined
Dec 3, 2020
Messages
529
You can move the unit there using the SetUnitX/Y functions:
  • Set Variable MyPoint = (Somewhere out of bounds)
  • Unit - Create 1 Footman at MyPoint...
  • Set Variable MyUnit = (Last created unit)
  • Custom script: call SetUnitX( udg_MyUnit, GetLocationX(udg_MyPoint) )
  • Custom script: call SetUnitY( udg_MyUnit, GetLocationY(udg_MyPoint) )
  • Custom script: call RemoveLocation( udg_MyPoint)
Uh thx but i kinda didn't explain this well. This one's on me...

So I want to spawn in units such as gargoyles and frost wyrms. I want to spawn them like outside of the map bounds and make them move inside the map (map bounds) itself.
To make it look like they're just arriving from somewhere, not just magically spawn in since the player could discover that spot with his own flying units.

PS: I think I just found the solution for this. Create "fake" boundary which will encapsulate the "playable" part of the map and outside of this boundary there will be more playable parts of the map but only for spawning in these units and then giving them 0 collision or whatever so they can walk through the "fake" boundary I place and then restore their collision to normal.

I shall try that and when i do I shall either delete this thread (if possible) since it's stupid or mark it as solved.
But thanks for your help yet again! I shall require it very soon for something :D
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
I think you still want to do what I suggested. Just also add this:
  • Unit - Turn collision for (Last created unit) Off.
They can be spawned in the "boundary" that exists around the perimeter of the map, and thanks to the disabled collision they can move through it.

You could then continuously check their position to see if they're "within map bounds" and turn collision back on once they are.
 
Level 22
Joined
Dec 3, 2020
Messages
529
I think you still want to do what I suggested. Just also add this:
  • Unit - Turn collision for (Last created unit) Off.
They can be spawned in the "boundary" that exists around the perimeter of the map, and thanks to the disabled collision they can move through it.

You could then continuously check their position to see if they're "within map bounds" and turn collision back on once they are.
Yeah!!! Perfect, thank you once again Uncle!
 
Level 22
Joined
Dec 3, 2020
Messages
529
@Uncle , I made it work the way I want... I just have 1 more final question before I mark this as solved:
will the event "unit enters region" cause lag/crash if it activates non stop?
For example a trigger:
  • Events - A unit enters playable map area
  • Conditions -
  • Actions - Turn collision On for entering unit
So this will activate all the time for each single unit present in the playable map area non stop.
Let's say the map has 300 units; will the map eventually lag out or make the game crash?
 
Level 22
Joined
Dec 3, 2020
Messages
529
You could also place a few regions in the boundaries of the map and check when a unit leaves those regions, if there's indeed loads of units entering the game other than the gargoyles.
Very good idea, thank you!
Well there will be potentially hundreds of units entering the game since the player and the AI will train units.
But doing what you said is perfect and requires little to no effort to make!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Let's say the map has 300 units; will the map eventually lag out or make the game crash?
I'm sure that'd be fine but what Remixer suggested is a good idea.

Speaking on triggering in general, you should always try to do things using the proper Events + Event Responses for the situation.

Are you creating these units with triggers? Then run their logic immediately afterwards:
  • Actions
    • Unit - Create 1 Gargoyle for....
    • Set Variable OutOfBoundsUnit = (Last created unit)
    • Trigger - Run OutOfBoundsLogic (ignoring conditions)
Are you training these units with a Barracks of some sort?
  • Events
    • Unit - A unit Finishes training
  • Conditions
    • (Trained unit-type) Equal to Gargoyle
  • Actions
    • Set Variable OutOfBoundsUnit = (Trained unit)
    • Trigger - Run OutOfBoundsLogic (ignoring conditions)
Are you summoning them with an ability?
  • Events
    • Unit - A unit Spawns a summoned unit
  • Conditions
    • (Unit-type of (Summoned unit)) Equal to Gargoyle
  • Actions
    • Set Variable OutOfBoundsUnit = (Summoned unit)
    • Trigger - Run OutOfBoundsLogic (ignoring conditions)
There's always an efficient solution, it just depends on how your map works. I suggested "enters playable map area" because it's a general solution that should cover almost everything. However, if something can "do it all" then it's probably not that efficient, there's usually a price to convenience.

Another possible optimization would be to give all of your "out of bounds" units a unique hidden ability. Base it on Storm Hammers for example. Then you can check for this ability in your Conditions. This allows you to transform a difficult to manage design:
  • Conditions
    • Or - Multiple Conditions
      • (Trained unit-type) Equal to Gargoyle
      • (Trained unit-type) Equal to Frost Wyrm
      • (Trained unit-type) Equal to Blue Drake
      • (Trained unit-type) Equal to Big Bird
Into a single dynamic Condition like this:
  • Conditions
    • (Level of OutOfBounds (ability) for (Trained unit-type)) Equal to 1
Add this ability to your desired Units through the Object Editor and you'll have your very own efficient and expandable Classification system.
 
Last edited:
Level 22
Joined
Dec 3, 2020
Messages
529
I'm sure that'd be fine but what Remixer suggested is a good idea.

Speaking on triggering in general, you should always try to do things using the proper Events + Event Responses for the situation.

Are you creating these units with triggers? Then run their logic immediately afterwards:
  • Actions
    • Unit - Create 1 Gargoyle for....
    • Set Variable OutOfBoundsUnit = (Last created unit)
    • Trigger - Run OutOfBoundsLogic (ignoring conditions)
Are you training these units with a Barracks of some sort?
  • Events
    • Unit - A unit Finishes training
  • Conditions
    • (Trained unit-type) Equal to Gargoyle
  • Actions
    • Set Variable OutOfBoundsUnit = (Trained unit)
    • Trigger - Run OutOfBoundsLogic (ignoring conditions)
Are you summoning them with an ability?
  • Events
    • Unit - A unit Spawns a summoned unit
  • Conditions
    • (Unit-type of (Summoned unit)) Equal to Gargoyle
  • Actions
    • Set Variable OutOfBoundsUnit = (Summoned unit)
    • Trigger - Run OutOfBoundsLogic (ignoring conditions)
There's always an efficient solution, it just depends on how your map works. I suggested "enters playable map area" because it's a general solution that should cover almost everything. However, if something can "do it all" then it's probably not that efficient, there's usually a price to convenience.

Another possible optimization would be to give all of your "out of bounds" units a unique hidden ability. Base it on Storm Hammers for example. Then you can check for this ability in your Conditions. This allows you to transform a difficult to manage design:
  • Conditions
    • Or - Multiple Conditions
      • (Trained unit-type) Equal to Gargoyle
      • (Trained unit-type) Equal to Frost Wyrm
      • (Trained unit-type) Equal to Blue Drake
      • (Trained unit-type) Equal to Big Bird
Into a single dynamic Condition like this:
  • Conditions
    • (Level of OutOfBounds (ability) for (Trained unit-type)) Equal to 1
Add this ability to your desired Units through the Object Editor and you'll have your very own efficient and expandable Classification system.
Thank you so much!
And yeah I will just create them with triggers!
 
Top