Add unit covered in FOW to a Unit Group

Status
Not open for further replies.
Level 2
Joined
Sep 25, 2023
Messages
5
Hi. I want my Artillery to attack a random enemy's building, even if it's covered in FOW, just like in Castle Fight map. My problem is that I can't find a way to pick units from within fog of war.
When I do
"Unit - Order PDD_source to Attack (Random unit from (Units in EntireMap <gen> matching ((((Matching unit) belongs to an enemy of (Owner of PDD_source)) is true) and (((Unit-type of (Matching unit)) is Building) is true))))"
It only attacks a random enemy building which an owner of the attacking Artillery can see.

It's the only thing that couldn't really google at this point, sorry if the answer for this already exists :)
 
Last edited:

Uncle

Warcraft Moderator
Level 72
Joined
Aug 10, 2018
Messages
7,644
Hello, two options come to mind:

1) Grant vision of the target before ordering your unit to attack it. This is probably not ideal for you.
  • Set Variable Attack_Group = (Units in EntireMap <gen> matching...)
  • Set Variable Attack_Target = (Random unit from Attack_Group)
  • Custom script: call DestroyGroup( udg_Attack_Group )
  • Unit - Grant shared vision of Attack_Target to (Owner of PDD_source)
  • Unit - Order PDD_source to Attack Attack_Target
2) Since your unit is using an Artillery weapon then the unit should have the Attack Ground ability which doesn't require vision of the area you attack. Order the unit to Attack Ground the position of the random enemy unit rather than the enemy unit itself.
  • Set Variable Attack_Group = (Units in EntireMap <gen> matching...)
  • Set Variable Attack_Target = (Random unit from Attack_Group)
  • Custom script: call DestroyGroup( udg_Attack_Group )
  • Set Variable Attack_Point = (Position of Attack_Target)
  • Unit - Order PDD_source to Attack Ground Attack_Point
  • Custom script: call RemoveLocation( udg_Attack_Point )
You probably want to ensure that Attack_Target actually exists before proceeding to the "attack" portion of the trigger. This can be done with an If Then Else action and some simple logic. Here we're exiting the trigger early if Attack_Target failed to find a random unit:
  • Set Variable Attack_Group = (Units in EntireMap <gen> matching...)
  • Set Variable Attack_Target = (Random unit from Attack_Group)
  • Custom script: call DestroyGroup( udg_Attack_Group )
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Attack_Target Equal to No Unit
    • Then - Actions
      • Skip remaining actions
    • Else - Actions
  • Set Variable Attack_Point = (Position of Attack_Target)
  • Unit - Order PDD_source to Attack Ground Attack_Point
  • Custom script: call RemoveLocation( udg_Attack_Point )
Note how I'm cleaning up the memory leaks in these triggers, which is what the Custom Script is for. This will help keep the map performing well by clearing out unnecessary data that is no longer needed. It's basically like emptying your Recycle Bin of trashed files.

Also, it's really easy to share a trigger on Hive that you're struggling with:

Memory leak breakdown:
 
Last edited:
Level 2
Joined
Sep 25, 2023
Messages
5
Hello, two options come to mind:

1) Grant vision of the target before ordering your unit to attack it. This is probably not ideal for you.
  • Set Variable Attack_Group = (Units in EntireMap <gen> matching...)
  • Set Variable Attack_Target = (Random unit from Attack_Group)
  • Custom script: call DestroyGroup( udg_Attack_Group )
  • Unit - Grant shared vision of Attack_Target to (Owner of PDD_source)
  • Unit - Order PDD_source to Attack Attack_Target
2) Since your unit is using an Artillery weapon then the unit should have the Attack Ground ability which doesn't require vision of the area you attack. Order the unit to Attack Ground the position of the random enemy unit rather than the enemy unit itself.
  • Set Variable Attack_Group = (Units in EntireMap <gen> matching...)
  • Set Variable Attack_Target = (Random unit from Attack_Group)
  • Custom script: call DestroyGroup( udg_Attack_Group )
  • Set Variable Attack_Point = (Position of Attack_Target)
  • Unit - Order PDD_source to Attack Ground Attack_Point
  • Custom script: call RemoveLocation( udg_Attack_Point )
You probably want to ensure that Attack_Target actually exists before proceeding to the "attack" portion of the trigger. This can be done with an If Then Else action and some simple logic. Here we're exiting the trigger early if Attack_Target failed to find a random unit:
  • Set Variable Attack_Group = (Units in EntireMap <gen> matching...)
  • Set Variable Attack_Target = (Random unit from Attack_Group)
  • Custom script: call DestroyGroup( udg_Attack_Group )
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Attack_Target Equal to No Unit
    • Then - Actions
      • Skip remaining actions
    • Else - Actions
  • Set Variable Attack_Point = (Position of Attack_Target)
  • Unit - Order PDD_source to Attack Ground Attack_Point
  • Custom script: call RemoveLocation( udg_Attack_Point )
Note how I'm cleaning up the memory leaks in these triggers, which is what the Custom Script is for. This will help keep the map performing well by clearing out unnecessary data that is no longer needed. It's basically like emptying your Recycle Bin of trashed files.

Also, it's really easy to share a trigger on Hive that you're struggling with:

Memory leak breakdown:
Thanks a lot. Tried the second method and it does work pretty well.
Although this brings me to another issue - what's the most suitable event should happen for this trigger to be triggered? The Artillery attacks every 12 seconds. For now it's being triggered when the shell does damage:
  • ArtilleryFire
    • Events
      • Game - PDD_damageEventTrigger becomes equal 1.00
But it's really bad, because there can be a case when it won't do damage, therefore, an artillery will not pick it's next random target. I couldn't seem to find an event like "starts attack" or something.
But I guess it's off the scale of this thread.
 

Uncle

Warcraft Moderator
Level 72
Joined
Aug 10, 2018
Messages
7,644
How exactly does your map work and what is your end goal?

You have several Events to work with depending on your goal:

This runs when an attack starts. This won't detect Attack Ground since that targets a point rather than an actual unit:
  • Events
    • Unit - A unit is attacked
This runs when a unit is ordered to Attack Ground:
  • Events
    • Unit - A unit Is issued an order targeting a point
  • Conditions
    • (Issued order) Equal to (Order(attackground))
Note that this detects the order and not the actual execution. Your artillery may need move to get into range first. However, if your artillery can attack anywhere on the map then this order could serve useful.

Is there a reason an approach like this wouldn't work?
  • Events
    • Time - Every 12.00 seconds of game time
  • Conditions
  • Actions
    • Set Variable Attack_Source = ...
    • Set Variable Attack_Group = (Units in EntireMap <gen> matching...)
    • Set Variable Attack_Target = (Random unit from Attack_Group)
    • Custom script: call DestroyGroup( udg_Attack_Group )
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Attack_Target Equal to No Unit
      • Then - Actions
        • Skip remaining actions
      • Else - Actions
    • Set Variable Attack_Point = (Position of Attack_Target)
    • Unit - Order Attack_Source to Attack Ground Attack_Point
    • Custom script: call RemoveLocation( udg_Attack_Point )
You just need to get a reference to the Artillery (Attack_Source) which can be done in several ways.
 
Level 2
Joined
Sep 25, 2023
Messages
5
How exactly does your map work and what is your end goal?

You have several Events to work with depending on your goal:

This runs when an attack starts. This won't detect Attack Ground since that doesn't target a unit:
  • Events
    • Unit - A unit is attacked
This runs when an Artillery is ordered to Attack Ground:
  • Events
    • Unit - A unit Is issued an order targeting a point
  • Conditions
    • (Issued order) Equal to (Order(attackground))
Note that this detects the order and not the actual execution. Your artillery may need move to get into range first. However, if your artillery can attack anywhere on the map then this order could serve useful.[/trigger]
So my goal is to make a map similar to Castle Fight. A worker can build a dynamic amount of towers that make units, or he can make the artillery towers that can pick targets within the whole map (the range is 99999).
Every artillery shot should be at a random enemy structure.
 

Uncle

Warcraft Moderator
Level 72
Joined
Aug 10, 2018
Messages
7,644
So my goal is to make a map similar to Castle Fight. A worker can build a dynamic amount of towers that make units, or he can make the artillery towers that can pick targets within the whole map (the range is 99999).
Every artillery shot should be at a random enemy structure.
I've seen the map but I'm not 100% sure how their Artillery towers work. Do you know if they can be manually controlled or if it's all automated. I assume it'd be automated so that each tower has it's own timer which tells it when to attack. It wouldn't even be able to attack without being told to do so through the triggered system.
 
Level 2
Joined
Sep 25, 2023
Messages
5
I've seen the map but I'm not 100% sure how their Artillery towers work. Do you know if they can be manually controlled or if it's all automated. I assume it'd be automated so that each tower has it's own timer which tells it when to attack. It wouldn't even be able to attack without being told to do so through the triggered system.
I just copied their Artillery object and it's based on Blacksmith building with ward, with attack type "Artillery" and a cooldown time specified in object settings. If I just place their Artillery on the map, it automatically shoots at a nearest object, without any triggers.
I guess it really comes down to making timers for each artillery.
 
Last edited:

Uncle

Warcraft Moderator
Level 72
Joined
Aug 10, 2018
Messages
7,644
I just copied their Artillery object and it's based on Blacksmith building, but it's a ward with attack type "Artillery" and a cooldown time specified in object settings. If I just place their Artillery on the map, it automatically shoots at a nearest object, without any triggers.
I guess it really comes down to making timers for each artillery.
It seems there's many ways of going about this all with different pros and cons.

Here's something I came up with that was easy to do, hopefully you're on the latest version and can open the map. It's using a little system I made for making timers easier to manage in GUI (the standard trigger editor). I'm not saying that you should use this exact design but it could help point you in the right direction.
 

Attachments

  • Artillery 1.w3m
    35.1 KB · Views: 5
Last edited:
Level 2
Joined
Sep 25, 2023
Messages
5
It seems there's many ways of going about this all with different pros and cons.

Here's something I came up with that was easy to do, hopefully you're on the latest version and can open the map. It's using a little system I made for making timers easier to manage in GUI (the standard trigger editor). I'm not saying that you should use this exact design but it could help point you in the right direction.
Thank you, but unfortunately I'm doing for the old 1.26 game version. :)
 
Level 17
Joined
Apr 13, 2008
Messages
1,608
Thank you, but unfortunately I'm doing for the old 1.26 game version. :)

I used to stick to 1.26 until just a few months ago, because I wanted JNGP's features.
I learned that you can actually use TESH with the live version, and some features similar to JNGP's are in the normal editor now.

However, let me tell you, that the current live editor is MUCH more powerful than 1.26. There are a lot of extremely useful functions that you will love.

Unless you are making maps for some private server in mind, I strongly suggest to use the current patch's editor. (It comes with some bugs, but I would say it's a 100 steps forward, 5 steps back).
 
Status
Not open for further replies.
Top