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

[Solved] Spawning unit in selected locations

Status
Not open for further replies.
Level 10
Joined
Jun 20, 2017
Messages
333
The problem is that it will be randomly selected! I'm not sure how to do this
I have a shop that you can buy unit from it and there are several areas where you can select and get the units.
Let's say, I have a channel ability that you can select some locations(circle of power not regions), so when you buy a unit from the store that unit will be in the selected location.
  • Selecting closest locations
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Choose Summon Location
    • Actions
      • Set Points_Unit[1] = (Position of Shop 3 0027 <gen>)
      • Set Points_Unit[2] = (Position of Dark Portal Units 0118 <gen>)
      • Set Points_Unit[3] = (Position of Dark Portal Units 0119 <gen>)
      • Set Points_Unit[4] = (Position of Dark Portal Units 0118 <gen>)
      • Set Points_Unit[5] = (Position of Dark Portal Units 0118 <gen>)
      • Set PlayerGroup = (Player group((Owner of (Casting unit))))
      • Cinematic - Ping minimap for PlayerGroup at Points_Unit[(Random integer number between 1 and 5)] for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
      • Custom script: call DestroyForce(udg_PlayerGroup)
      • Custom script: call RemoveLocation(udg_Points_Unit[1])
      • Custom script: call RemoveLocation(udg_Points_Unit[2])
      • Custom script: call RemoveLocation(udg_Points_Unit[3])
      • Custom script: call RemoveLocation(udg_Points_Unit[4])
      • Custom script: call RemoveLocation(udg_Points_Unit[5])
  • Selecting closest locations2
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Selling unit)) Equal to (==) Shop 3
    • Actions
      • Set Points_Unit[1] = (Position of Shop 3 0027 <gen>)
      • Set Points_Unit[2] = (Position of Dark Portal Units 0118 <gen>)
      • Set Points_Unit[3] = (Position of Dark Portal Units 0119 <gen>)
      • Set Points_Unit[4] = (Position of Dark Portal Units 0118 <gen>)
      • Set Points_Unit[5] = (Position of Dark Portal Units 0118 <gen>)
      • Unit - Move (Sold unit) instantly to Points_Unit[(Random integer number between 1 and 5)]
      • Custom script: call RemoveLocation(udg_Points_Unit[1])
      • Custom script: call RemoveLocation(udg_Points_Unit[2])
      • Custom script: call RemoveLocation(udg_Points_Unit[3])
      • Custom script: call RemoveLocation(udg_Points_Unit[4])
      • Custom script: call RemoveLocation(udg_Points_Unit[5])
 
Level 10
Joined
Jun 20, 2017
Messages
333
As you said, the problem is random and I don't want the units to always be placed next to the store, so somehow I want to set a location for the store. For example, we have 5 locations, first one is for the store and others for the circles and you can pick one of the locations with ability.
 
Level 8
Joined
May 21, 2019
Messages
435
Alright, I am confused on multiple fronts here...
  • Your triggers are named "Select closests units" but that's not what they are doing at all.
  • 3 of your 5 points are assigned to the same location.
  • Why are you using random numbers if you want to select a location?
  • The 2 triggers aren't interacting at all.
Alright, so if we say that what you want is to select a destination which is marked by a unit, then all you need is 1 location/point variable in your first trigger, set to the location of the target of the ability being cast, then you use that variable in your second trigger as the location instead of the random thing as well as the location for the ping in your first trigger. That's it.
If your location units (circle of power) are able to be moved, then you should store the unit instead, and then generate the location every time a unit is moved.
 
Level 10
Joined
Jun 20, 2017
Messages
333
Well, then don't use the Random integer number between X and Y...
Ok, thanks :d
then all you need is 1 location/point variable in your first trigger, set to the location of the target of the ability being cast, then you use that variable in your second trigger as the location instead of the random thing as well as the location for the ping in your first trigger.
So now the problem is that the unit moves wherever that i want without the circles! should I set those locations into initialization trigger? and using loop/hashtable/dummy unit for the second trigger?!
  • Selecting closest locations
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Choose Summon Location
    • Actions
      • Set Point_Target = (Target point of ability being cast)
      • Set PlayerGroup = (Player group((Owner of (Casting unit))))
      • Cinematic - Ping minimap for PlayerGroup at Point_Target for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
      • Custom script: call DestroyForce(udg_PlayerGroup)
      • Trigger - Turn on Selecting closest locations2 <gen>
  • Selecting closest locations2
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Selling unit)) Equal to (==) Shop 3
    • Actions
      • Unit - Move (Sold unit) instantly to Point_Target
      • Custom script: call RemoveLocation(udg_Point_Target)
      • Trigger - Turn off (This trigger)
 
Level 8
Joined
May 21, 2019
Messages
435
Ok, thanks :d

So now the problem is that the unit moves wherever that i want without the circles! should I set those locations into initialization trigger? and using loop/hashtable/dummy unit for the second trigger?!
  • Selecting closest locations
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Choose Summon Location
    • Actions
      • Set Point_Target = (Target point of ability being cast)
      • Set PlayerGroup = (Player group((Owner of (Casting unit))))
      • Cinematic - Ping minimap for PlayerGroup at Point_Target for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
      • Custom script: call DestroyForce(udg_PlayerGroup)
      • Trigger - Turn on Selecting closest locations2 <gen>
  • Selecting closest locations2
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Selling unit)) Equal to (==) Shop 3
    • Actions
      • Unit - Move (Sold unit) instantly to Point_Target
      • Custom script: call RemoveLocation(udg_Point_Target)
      • Trigger - Turn off (This trigger)

It seems like "Choose Summon Location" is a gound target ability. It needs to be a unit target ability, and the trigger needs to check if the target is a circle of power.
 
Level 10
Joined
Jun 20, 2017
Messages
333
I got 3 problems. 1. The target should be vulnerable 2. The map should be shown to select the circle 3. The triggers work every time when you pick a circle(for example, when I choose a circle, then I buy a unit that the first unit only moves!).
  • Selecting closest locations2 Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Choose Summon Location
    • Actions
      • Set Point_Target = (Position of (Target unit of ability being cast))
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Target unit of ability being cast) Equal to (==) Dark Portal Units 0118 <gen>
          • Then - Actions
            • Set PlayerGroup = (Player group((Owner of (Casting unit))))
            • Cinematic - Ping minimap for PlayerGroup at Point_Target for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
            • Custom script: call DestroyForce(udg_PlayerGroup)
          • Else - Actions
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Target unit of ability being cast) Equal to (==) Dark Portal Units 0119 <gen>
              • Then - Actions
                • Set PlayerGroup = (Player group((Owner of (Casting unit))))
                • Cinematic - Ping minimap for PlayerGroup at Point_Target for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
                • Custom script: call DestroyForce(udg_PlayerGroup)
              • Else - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Target unit of ability being cast) Equal to (==) Dark Portal Units 0108 <gen>
                  • Then - Actions
                    • Set PlayerGroup = (Player group((Owner of (Casting unit))))
                    • Cinematic - Ping minimap for PlayerGroup at Point_Target for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
                    • Custom script: call DestroyForce(udg_PlayerGroup)
                  • Else - Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Target unit of ability being cast) Equal to (==) Dark Portal Units 0120 <gen>
                      • Then - Actions
                        • Set PlayerGroup = (Player group((Owner of (Casting unit))))
                        • Cinematic - Ping minimap for PlayerGroup at Point_Target for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
                        • Custom script: call DestroyForce(udg_PlayerGroup)
                      • Else - Actions
      • Trigger - Turn on Selecting closest locations3 Copy <gen>
  • Selecting closest locations3 Copy
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Selling unit)) Equal to (==) Shop 3
    • Actions
      • Unit - Move (Sold unit) instantly to Point_Target
      • Custom script: call RemoveLocation(udg_Point_Target)
      • Trigger - Turn off (This trigger)
 
Level 8
Joined
May 21, 2019
Messages
435
I got 3 problems. 1. The target should be vulnerable 2. The map should be shown to select the circle 3. The triggers work every time when you pick a circle(for example, when I choose a circle, then I buy a unit that the first unit only moves!).
1. Have you tried setting the allowed targets of the spell to allow invulnerable targets?
2. That's what the ping does, isn't it? I don't see the problem.
3. You need to delete the "Turn off this trigger" part in the move trigger, that's what's causing that one.
 
Level 10
Joined
Jun 20, 2017
Messages
333
Since number 1/2 have problem, I changed the triggers.
So the problem is that the ping is working for all locations and the unit is moving to the last location!
  • Selecting closest locations
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Rects[1] = Rect 078 <gen>
      • Set Rects[2] = Rect 074 <gen>
      • Set Rects[3] = Rect 075 <gen>
      • Set Rects[4] = Rect 076 <gen>
      • Set Rects[5] = Rect 077 <gen>
      • Set Integer_TotalRects = 5
  • Selecting closest locations2
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Choose Summon Location
    • Actions
      • Do Multiple ActionsFor each (Integer Integer) from 1 to Integer_TotalRects, do (Actions)
        • Loop - Actions
          • Set Points[1] = (Target point of ability being cast)
          • Set Points[2] = (Center of Rects[Integer])
          • Set Real = 99999.00
          • Set Real2 = (Distance between Points[1] and Points[2])
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Real2 Less than (<) Real
              • Then - Actions
                • Set Real = Real2
                • Set Rect = Rects[Integer]
                • Set PlayerGroup = (Player group((Owner of (Casting unit))))
                • Cinematic - Ping minimap for PlayerGroup at Points[2] for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
                • Custom script: call DestroyForce(udg_PlayerGroup)
              • Else - Actions
          • Custom script: call RemoveLocation(udg_Points[1])
      • Trigger - Turn on Selecting closest locations3 <gen>
  • Selecting closest locations3
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Selling unit)) Equal to (==) Shop 3
    • Actions
      • Unit - Move (Sold unit) instantly to Points[2]
      • Custom script: call RemoveLocation(udg_Points[2])
 
Last edited:
Level 8
Joined
May 21, 2019
Messages
435
Since number 1/2 have problem, I changed the triggers.
So the problem is that the ping is working for all locations and the unit is moving to the last location!
  • Selecting closest locations
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Rects[1] = Rect 078 <gen>
      • Set Rects[2] = Rect 074 <gen>
      • Set Rects[3] = Rect 075 <gen>
      • Set Rects[4] = Rect 076 <gen>
      • Set Rects[5] = Rect 077 <gen>
      • Set Integer_TotalRects = 5
  • Selecting closest locations2
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Choose Summon Location
    • Actions
      • Do Multiple ActionsFor each (Integer Integer) from 1 to Integer_TotalRects, do (Actions)
        • Loop - Actions
          • Set Points[1] = (Target point of ability being cast)
          • Set Points[2] = (Center of Rects[Integer])
          • Set Real = 99999.00
          • Set Real2 = (Distance between Points[1] and Points[2])
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Real2 Less than (<) Real
              • Then - Actions
                • Set Real = Real2
                • Set Rect = Rects[Integer]
                • Set PlayerGroup = (Player group((Owner of (Casting unit))))
                • Cinematic - Ping minimap for PlayerGroup at Points[2] for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
                • Custom script: call DestroyForce(udg_PlayerGroup)
              • Else - Actions
          • Custom script: call RemoveLocation(udg_Points[1])
      • Trigger - Turn on Selecting closest locations3 <gen>
  • Selecting closest locations3
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Selling unit)) Equal to (==) Shop 3
    • Actions
      • Unit - Move (Sold unit) instantly to Points[2]
      • Custom script: call RemoveLocation(udg_Points[2])

Well, I mean, for starters, you are looping through all of them, so the ping would obviously go off on all of them and the last one would be the location that gets saved. Not sure why you've built your trigger like this.
I'm not even certain what your entire if function is supposed to be doing. You are basically checking if the point is further away than 99.999 yards. That's an odd limitation, as that's a huge distance. Where exactly did you get this trigger from?
I guess this trigger would make some level of sense if what you were doing was comparing the allowed locations with the location of the spell being cast, with a much lower value than 99 999, as that would effectively give you an radius within the allowed location that you can target, but you'd need to account for the 2 scenarios of multiple hits and no hits on elligible locations.

Even then, all of this would be a lot simpler if you just made it set the location to the location of the target unit of your spell. It's like... 1 event, 2 conditions, 1 action...
In pseudocode it's something like:
Code:
A unit casts a spell.

Spell being cast is [your spell]
Unit-type of target unit is [your circle of power thing]

Set [your spawn location] to position of target of spell

Then you just need to take care of the memory leak on the location and you're good to go. Easy peasy.
 
Level 10
Joined
Jun 20, 2017
Messages
333
I've done this before, and I removed the locations, therefore I thought it would not work.
But again the problem is that the target must be shown on the map to select it (I cannot select it if the map is dark).
Not sure why you've built your trigger like this.
To compare which region is closer to the targeted point, so if I clicking the ability anywhere on the map, then it would pick the nearest circle in the area.
 
Level 8
Joined
May 21, 2019
Messages
435
I've done this before, and I removed the locations, therefore I thought it would not work.
But again the problem is that the target must be shown on the map to select it (I cannot select it if the map is dark).
The easy fix to this would be to create a vision modifier on the areas... but...
To compare which region is closer to the targeted point, so if I clicking the ability anywhere on the map, then it would pick the nearest circle in the area.
This sounds a hell of a lot more sleek, so lets go with that.

I have no idea what your current block of code is attempting to do, but I'd wager that the simplest way to do this is to loop through all 6 rects the way you are doing, but instead, compare their distance to Points[1]. Whenever one is lower than the current save, you overwrite the save, whenever it is higher, you maintain it. Then you do all of the actions after finding the closest point, rather than inside the distance determining loop.
Here's how I'd do it:

  • Setting closest locations1
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Rects[1] = (Center of PICK A REGION <gen>)
      • Set Rects[2] = (Center of PICK A REGION <gen>)
      • Set Rects[3] = (Center of PICK A REGION <gen>)
      • Set Rects[4] = (Center of PICK A REGION <gen>)
      • Set Rects[5] = (Center of PICK A REGION <gen>)
      • Set TotalRects = 5
  • Setting closest locations2
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to PICK A SPELL
    • Actions
      • Set Points[1] = (Target point of ability being cast)
      • Set ClosestPointDistance = 99999.00
      • For each (Integer A) from 1 to TotalRects, do (Actions)
        • Loop - Actions
          • Set Points[2] = Rects[(Integer A)]
          • Set Real = (Distance between Points[1] and Points[2])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Real Less than ClosestPointDistance
            • Then - Actions
              • Set ClosestPoint = Points[2]
              • Set ClosestPointDistance = Real
            • Else - Actions
      • Custom script: call RemoveLocation(udg_Points[1])
      • Cinematic - Ping minimap for (Player group((Owner of (Triggering unit)))) at ClosestPoint for 3.00 seconds, using a Simple ping of color (100.00%, 100.00%, 0.00%)
      • Trigger - Turn on Setting closest locations3 <gen>
  • Setting closest locations3
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Footman
    • Actions
      • Unit - Move (Sold unit) instantly to ClosestPoint, facing Default building facing degrees
      • -------- I'm not sure why you remove the point here, as that would mean that you would have to set the location each time --------
It's worth noting that in the first trigger, I set the Rects directly to points instead of regions, which means I don't have to find these points every time. It also prevents a memory leak apart from the 5 points you'd probably wanna use all the time anyway.
 
Last edited:
Status
Not open for further replies.
Top