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

Any way to do these things?

Status
Not open for further replies.
Level 4
Joined
Nov 26, 2008
Messages
25
Any ways to detect "Unit types within range of Unit Types"?
I want to be able to detect when multiple of a unit type are in close proximity of each other.


Attach units to trees (similar to a wisp) & also enable basic attack at same time.
(any information is appreciated since google seems to have a tree tag fetish)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,539
Here's a map with an example of "Unit types within range". Press ESCAPE to create some Footmen and you'll see their damage increase based on the number of Footmen near them. Each Footman gains +1 damage for each OTHER Footman within 800 range of it.

I don't recommend using this with a lot of units. And if it does start to slow the game then increase the Periodic Interval to something like 1.00 second.

I don't think it leaks but it definitely causes some performance issues when a lot of Footman are created. Maybe someone else knows how to improve the performance. I'm sure there's a better way of doing it.

  • Footman Aura
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in FootmanUG and do (Actions)
        • Loop - Actions
          • Set TempUnit = (Picked unit)
          • Set TempPoint = (Position of TempUnit)
          • Set FootmanCount = -1
          • -------- - --------
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 800.00 of TempPoint matching (((Matching unit) is in FootmanUG) Equal to True)) and do (Actions)
            • Loop - Actions
              • -------- FootmanCount is how many OTHER Footman are near TempUnit --------
              • Set FootmanCount = (FootmanCount + 1)
          • -------- - --------
          • -------- If 2 or more Footmen are near each other then add damage to them. Otherwise, check if they had gained damage previously and remove it --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • FootmanCount Greater than 0
            • Then - Actions
              • -------- This runs if at least 1 OTHER Footman was found --------
              • -------- If the Footman doesn't have the Damage ability then add it first --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Footman Damage Bonus (Test) for TempUnit) Greater than 0
                • Then - Actions
                  • Unit - Set level of Footman Damage Bonus (Test) for TempUnit to FootmanCount
                • Else - Actions
                  • Unit - Add Footman Damage Bonus (Test) to TempUnit
                  • Unit - Set level of Footman Damage Bonus (Test) for TempUnit to FootmanCount
            • Else - Actions
              • -------- This ELSE runs if no OTHER Footman were found --------
              • -------- If the Footman still has the damage ability from before then remove it --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Level of Footman Damage Bonus (Test) for TempUnit) Greater than 0
                • Then - Actions
                  • Unit - Remove Footman Damage Bonus (Test) from TempUnit
                • Else - Actions
          • -------- - --------
          • -------- Clean up Leaks --------
          • Custom script: call RemoveLocation (udg_TempPoint)
 

Attachments

  • Unit Type Aura.w3x
    19.8 KB · Views: 17
Last edited:
Here's a map with an example of "Unit types within range". Press ESCAPE to create some Footmen and you'll see their damage increase based on the number of Footmen near them. Each Footman gains +1 damage for each OTHER Footman within 800 range of it.

I don't recommend using this with a lot of units. And if it does start to slow the game then increase the Periodic Interval to something like 1.00 second.

I don't think it leaks but it definitely causes some performance issues when a lot of Footman are created. Maybe someone else knows how to improve the performance. I'm sure there's a better way of doing it.

This can be made somewhat faster in pure GUI by using an array instead of a unit group to store all the footmen. However, having a ForGroup loop for every footman is going to slow things down a lot. Unfortunately the only way to fix this would be using a FirstOfGroup loop, which would require JASS (or custom script lines in GUI). In general, these sorts of periodic and computation-heavy systems are unsuitable for GUI, due to how much slower it is. The logic is pretty sound, though, and this is a workable solution.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Any ways to detect "Unit types within range of Unit Types"?
I want to be able to detect when multiple of a unit type are in close proximity of each other.
Yes it is possible however doing so requires non trivial trigger logic. Fundamentally it is quite a complex operation you are asking.

As far as I am aware someone (Nes… something or other, I am bad at names sorry) attempted such a thing for a "morale" system many years ago. His conclusion was that doing it with satisfactory performance was not possible. However he did not have the power of Lua as well as x86-64, which might have solved some of the scaling issues he had.

If one used unit enters range events then one would have to track how many of the appropriate unit types are in range of each unit of the desired type. One would also need to periodically check if the units are still in reach of each other. Due to the nature of the event you would need to map the unit to the trigger. The trigger would also need to be dynamically destroyed with the unit. Checking if the units are in range of each other would need to be executed in a staggered way for performance and that would result in latency detecting when units left the range.
Attach units to trees (similar to a wisp) & also enable basic attack at same time.
If you can detect when they are attached to trees then you could create dummy units to do the attacks. If spell damage is alright then the phoenix fire ability could be used to deal damage and added/removed from the unit when attached/not attached to a tree.
 
Level 8
Joined
May 21, 2019
Messages
435
Any ways to detect "Unit types within range of Unit Types"?
I want to be able to detect when multiple of a unit type are in close proximity of each other.
As everyone else said, this is a massive undertaking. I generally advice against it, as it's bound to have scaling issues if the system is 100% dynamic.
You may however run a pseudo-dynamic system to ease the load of this task considerably, if the way in which this is used happens to fit within a fairly limited amount of scenarios. You can also redesign your system around this limitation, for example, through the use of a "commander" type unit, which has the sole purpose of being the center of this effect, so that you're only really checking for the amount of units around this commander, rather than checking every single unit.

If the effect you're trying to accomplish is the sense of being "overrun" by a horde/swarm of some minor enemies, you may quite simply achieve the same effect by using the stacking damage debuff from the Firelord, which increases the damage of each attack against the target. This could quickly end up being OP in some scenarios, but for "event" type maps, this may create the desired effect rather easily.


Attach units to trees (similar to a wisp) & also enable basic attack at same time.
(any information is appreciated since google seems to have a tree tag fetish)
As far as I can reason, the best way to do this is through dummy units.
I've never heard of a system like this before, but I imagine it could be done with something like this:

You give the unit some sort of ability that finds a nearby tree, either targeting it directly or finding it with a trigger (Ancients and Mountain Giants have abilities that target trees) You then cancel whatever effect that ability would have, and summon a Wisp which you order to attach itself to the tree.
You then place a few restrictions on the unit casting the spell. There may be a nicer way to do this, but off the top of my head, what I would do, is order the unit to "hold position", and save its location in a hashtable. Then you run a periodic event to check if the unit has moved away from that location, and cancel the effect by removing the Wisp.. You'd also want a way to prevent the unit from attaching itself to multiple trees, such as using a group to track all units currently attached to trees.
 
Status
Not open for further replies.
Top