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

Need help with visibility modifier!

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
Hello everyone, I would like to request help to acomplish a system I'm developing. It's a system that makes unit able only to see what are in front of them, like this pic:
2017-04-26.png
To acomplish that, I've set the unit sight radius (both day and night) to 0, then I trigger a visibility modifier ahead of the unit so it won't show what's behind it too. Now I'm having the problem of removing the visibility modifier after the unit explores a new area, like this:
2017-04-26 (1).png
So my question is how can I destroy the first visibility modifier after the unit leaves it's reach?
I'm using the following code:
  • Stealth Periodic
    • Events
      • Time - Every 0.33 seconds of game time
    • Conditions
    • Actions
      • Set STSYS_TempGroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in STSYS_TempGroup and do (Actions)
        • Loop - Actions
          • Set STESYS_TempUnit1 = (Picked unit)
          • Set STESYS_TempPlayer = (Owner of (Picked unit))
          • -------- LOCATION IN FRONT --------
          • Set STSYS_TempReal = (Current acquisition range of STESYS_TempUnit1)
          • Set STSYS_TempReal1 = (STSYS_TempReal + 100.00)
          • Set STESYS_TempLoc1 = (Position of (Picked unit))
          • Set STESYS_TempLoc1 = (STESYS_TempLoc1 offset by STSYS_TempReal towards (Facing of (Picked unit)) degrees)
          • Visibility - Create an initially Enabled visibility modifier for STESYS_TempPlayer emitting Visibility from STESYS_TempLoc1 to a radius of STSYS_TempReal1
          • Set STESYS_TempVis = (Last created visibility modifier)
          • -------- LOCATION IN BACK --------
          • -------- HERE I TRY TO CREATE A FOG OF WAR BEHIND THE UNIT, BUT IT DOESN'T WORK --------
          • Set STSYS_TempReal = (STSYS_TempReal x 2.00)
          • Set STSYS_TempReal1 = (STSYS_TempReal + 100.00)
          • Set STESYS_TempLoc1 = (Position of (Picked unit))
          • Set STESYS_TempLoc1 = (STESYS_TempLoc1 offset by STSYS_TempReal towards ((Facing of STESYS_TempUnit1) + 180.00) degrees)
          • Visibility - Create an initially Enabled visibility modifier for STESYS_TempPlayer emitting Black mask from STESYS_TempLoc1 to a radius of STSYS_TempReal
          • Set STESYS_TempVis2 = (Last created visibility modifier)
          • Custom script: call RemoveLocation(udg_STESYS_TempLoc1)
 
Level 7
Joined
Mar 10, 2013
Messages
366
Instead of black mask, try to use FoW.

I think what you should do is another approach.

Since you have what should be visible to the character, make everything into fog of war except the area that should be visible.
 
Level 11
Joined
Oct 9, 2015
Messages
721
My first approach was to create a dummy unit which had it's vision set to the acquisition range of the unit, and it worked just fine. However I wanted to make it more efficient and to cost less memory as one would have to create a dummy unit for each unit on the map.
 
Level 7
Joined
Mar 10, 2013
Messages
366
My first approach was to create a dummy unit which had it's vision set to the acquisition range of the unit, and it worked just fine. However I wanted to make it more efficient and to cost less memory as one would have to create a dummy unit for each unit on the map.
That surely can be an overhead, but the major problem would lie into how many units would work with this mechanic.

Test what I suggested and tell me if it worked.
 
Level 11
Joined
Oct 9, 2015
Messages
721
Fog of war doesn't work either, I think it's because I'm creating a visibility modifier over another without destroying the previous one. I can see they are conflicting with each other as the minimap constantly shows fog of war then visibility and then fog of war again.
 
Level 7
Joined
Mar 10, 2013
Messages
366
Don't know if you have this in GUI, but you sure have in JASS: DestroyFogModifier takes fogmodifier whichFogModifier returns nothing
 
Level 7
Joined
Mar 10, 2013
Messages
366
Yes, there is
  • Visibility - Destroy (Last created visibility modifier)
but how can I know which modifier to destroy? Do I use a "unit leaves region" (region of the modifier) event ?
You will need two variables to keep track both Visibility modifiers. The new one and the last one.

Right before, saving the new one, save it as the last one, and right after you save the new modifier, destroy the last one.

It got a bit confusing, but it would works like this.

  • Set LastVisibleLocation = NewVisibleLocation
  • [...] // defining new visible location
  • Set NewVisibleLocation = ( Last created visibility modifier )
  • Visibility - Destroy ( LastVisibleLocation )
 
Level 11
Joined
Oct 9, 2015
Messages
721
I could't understand it very well, I'm using this functions:
  • Set STESYS_TempVis = STESYS_TempVis2
  • Visibility - Create an initially Enabled visibility modifier for STESYS_TempPlayer emitting Visibility from STESYS_TempLoc1 to a radius of STSYS_TempReal1
  • Set STESYS_TempVis2 = (Last created visibility modifier)
  • Visibility - Destroy STESYS_TempVis
And I'm having this effect:
2017-04-26 (3).png
 

Attachments

  • Stealth System2.w3x
    21.8 KB · Views: 18

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
You need to make your system MUI compatible in order to store a reference to the visibility modifiers for each unit. You can either map the visibility modifiers to the units using a hashtable, or you can use an array list containing all units you want this system to apply to (maximum number 8192 units simultaneously). I recommend the array list approach as it is like most MUI spells, is slightly faster and avoids potential leak hazards of the hashtable.

You will want 3 arrays in total, 2 visibility modifiers and 1 unit array. At map initialization and unit creation you add units to the system in an array list fashion. This means you start with the first unit at index 0, second unit in index 1 etc. In your periodic trigger you iterate through all elements in the array list starting with index 0 and going up to index N-1 where N is the number of units in the system. For each element you firstly destroy the existing visibility modifier, then you create the appropriate new ones and assign them back to the element in the appropriate arrays. On unit death or removal you remove them from the array list by first finding them (linear search), then replacing their position in the array list with the position at index N-1 and then decrement N.
 
Level 7
Joined
Mar 10, 2013
Messages
366
Basically it's working now.

But this system works for only one unit, you'll have to use an array indexing each unit, as @Dr Super Good suggested to make this work for multiple units.
 

Attachments

  • Stealth System2.w3x
    22.4 KB · Views: 25
Status
Not open for further replies.
Top