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

Hiding and Unhiding Units

Status
Not open for further replies.
Do a periodic event in which you enumerate all units within the group of hidden units, check each unit against the unit you want to test the range for, then unhide the picked unit if it is within range and remove it from the group.
Add this unit to a group containing all visible units and do the same periodic checks for those in reverse (if range > 400, hide and add to hidden group again).

Try it on your own! It's not hard to do and you'll learn a few things.
 
You can use these 3 triggers:
trigger 1. This will set the peasant as our unit to be hidden and unhidden.
  • set
  • Events
    • Time-Elapsed game time is 0.01 seconds
  • Conditions
  • Actions
    • Set unit_X=Peasant 000<gen>
    • Unit - Hide unit_X
Trigger 2. This will unhide our unit when a triggering unit comes within 250.00 to the peasant.
  • unhide
  • Events
    • Unit - A unit comes within 250.00 of Peasant 000<gen>
  • Conditions
    • (Triggering unit) Equal to Archmage 0002<gen>
  • Actions
    • Unit - Unhide unit_X
Trigger 3. We convert a point with size to region with reference to our peasant so when a triggering unit leaves there, our peasant will be hidden.
  • hide
  • Events
    • Unit - A unit leaves (Region centered at (Position of Peasant 0000<gen>) with size (300.00, 300.00))
  • Conditions
    • (Triggering unit) Equal to Archmage 0002<gen>
  • Actions
    • Unit - Hide unit_X
 
The problem is that picking units in range does not detect hidden units. You have to manually add the hidden units to a group, then cycle through the group of hidden units to evaluate if they get unhidden or not.
Hm, I think that's not true. Hidden units also should be picked up with the function "PickAllUnitsInRange". So it might save you some work here.
Trigger 3. We convert a point with size to region with reference to our peasant so when a triggering unit leaves there, our peasant will be hidden.
  • hide
  • Events
    • Unit - A unit leaves (Region centered at (Position of Peasant 0000<gen>) with size (300.00, 300.00))
  • Conditions
    • (Triggering unit) Equal to Archmage 0002<gen>
  • Actions
    • Unit - Hide unit_X
That's static. If the peasant moves it won't work anymore and might cause bugs I think. Me would go with periodic checks as Zwiebelchen suggested.
 
Status
Not open for further replies.
Top