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

Creating unit in random region but random point within x unit

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,125
Hello everyone. I want to create unit near of your hero. But there are some conditions
Unit must be created random point within x of your range. Is there a way to do that? My methods are painful..

Extra detail: I am developing survival map and when night comes, random units will spawn and attack players. But it would be better if they will spawn at least 700-800 range far from hero.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,517
You want to use Point with Polar Offset.
  • Actions
    • Set VariableSet Point[0] = (Position of (Your Hero)
    • Set VariableSet Point[1] = (Point[0] offset by 800.00 towards (Random angle) degrees.)
    • Unit - Create 1 Footman for Player 1 (Red) at Point[1] facing Default building facing degrees

You can randomize the offset as well:
  • Set VariableSet Point[1] = (Point[0] offset by (Random real number between 700.00 and 800.00) towards (Random angle) degrees.)

And if you want to keep your game running smoothly and clean up the memory leaks then add these 2 extra lines at the end:
  • Actions
    • Set VariableSet Point[0] = (Position of (Your Hero)
    • Set VariableSet Point[1] = (Point[0] offset by (Random real number between 700.00 and 800.00) towards (Random angle) degrees.)
    • Unit - Create 1 Footman for Player 1 (Red) at Point[1] facing Default building facing degrees
    • Custom script: call RemoveLocation (udg_Point[0])
    • Custom script: call RemoveLocation (udg_Point[1])

Point is a Point variable with an Array.
 
Level 17
Joined
Jun 2, 2009
Messages
1,125
You want to use Point with Polar Offset.
  • Actions
    • Set VariableSet Point[0] = (Position of (Your Hero)
    • Set VariableSet Point[1] = (Point[0] offset by 800.00 towards (Random angle) degrees.)
    • Unit - Create 1 Footman for Player 1 (Red) at Point[1] facing Default building facing degrees

You can randomize the offset as well:
  • Set VariableSet Point[1] = (Point[0] offset by (Random real number between 700.00 and 800.00) towards (Random angle) degrees.)

And if you want to keep your game running smoothly and clean up the memory leaks then add these 2 extra lines at the end:
  • Actions
    • Set VariableSet Point[0] = (Position of (Your Hero)
    • Set VariableSet Point[1] = (Point[0] offset by (Random real number between 700.00 and 800.00) towards (Random angle) degrees.)
    • Unit - Create 1 Footman for Player 1 (Red) at Point[1] facing Default building facing degrees
    • Custom script: call RemoveLocation (udg_Point[0])
    • Custom script: call RemoveLocation (udg_Point[1])

Point is a Point variable with an Array.
Thank you so much my friend. By the way i am a bit of confused about the picture. It is working well but cleaning leaks trigger are working like this?

  • YaratikYaratma
    • Events
      • Player - Player 1 (Red) types a chat message containing 1 as An exact match
    • Conditions
    • Actions
      • Set VariableSet[0] = (Position of UnitP1)
      • Set VariableSet[1] = (VariableSet[0] offset by (Random real number between 700.00 and 800.00) towards (Random angle) degrees)
      • Unit - Create 1 Ghoul for Player 12 (Brown) at VariableSet[1] facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_VariableSet[0])
      • Custom script: call RemoveLocation (udg_VariableSet[1])
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,517
Set VariableSet is just the prefix stuff that the trigger editor places before the variable name. I'm using Reforged which is very unfinished/messy so some of my Actions look a little weird compared to yours.

My variable's name is Point.

  • Set Point[0] = (Position of UnitP1)
  • Set Point[1] = (Point[0] offset by (Random real number between 700.00 and 800.00) towards (Random angle) degrees)

You can name this variable whatever you want, it's entirely up to you. But I wouldn't recommend naming it VariableSet :p

And yes, that's how you clean up a Point (location) memory leak. We do this because once we've created the Ghoul we no longer need to keep track of those 2 Points. This frees up the game's memory which helps the game perform better. If you've ever used Dummy units before and gave them expiration timers so that they'd be removed this is the same concept. You don't need the Dummy after it's done casting it's spell so you get rid of it. As a result there's 1 less unit on the map which is always good for performance.
 
Last edited:
Status
Not open for further replies.
Top