• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Dinamic BlackMask

Status
Not open for further replies.
Level 3
Joined
Feb 13, 2014
Messages
26
I'm trying to set a a system that overrides unit exploration, on my map I'm doing it by periodically creating and destroying visibility modifiers that follow the unit around, and so far it works but is kinda buggy since unit sight is a circular area which I cant completely surround using squared regions, so far I cant think of a way to fix that. Any ideas on how to make this system more efficient? . Also is it possible for a visibility modifier to work on "everything but a region" ?

Since it depends on movement I don't think i can explain it good with pictures so I attached an a little example map file :) thanks in advance for the help:thumbs_up:
 

Attachments

  • DinamicBlackMask.w3x
    23.2 KB · Views: 36
At first I post trigger for others (german editor, but you can use power of imagination:p)
  • BlackMask
    • Ereignisse
      • Zeit - Every 0.10 seconds of game time
    • Bedingungen
    • Aktionen
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • 'IF'-Bedingungen
          • B Gleich 0
        • 'THEN'-Aktionen
          • Set Position[0] = (X of (Position of Unit))
          • Set Position[1] = (Y of (Position of Unit))
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point(Position[0], (Position[1] + 2050.00))) with size (4600.00, 500.00))
          • Set VisMod[0] = (Last created visibility modifier)
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point((Position[0] + 2050.00), Position[1])) with size (500.00, 3600.00))
          • Set VisMod[1] = (Last created visibility modifier)
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point(Position[0], (Position[1] - 2050.00))) with size (4600.00, 500.00))
          • Set VisMod[2] = (Last created visibility modifier)
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point((Position[0] - 2050.00), Position[1])) with size (500.00, 3600.00))
          • Set VisMod[3] = (Last created visibility modifier)
          • Set B = 1
        • 'ELSE'-Aktionen
          • For each (Integer A) from 0 to 3, do (Actions)
            • Schleifen - Aktionen
              • Sichtbarkeit - Destroy VisMod[(Integer A)]
          • Set Position[0] = (X of (Position of Unit))
          • Set Position[1] = (Y of (Position of Unit))
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point(Position[0], (Position[1] + 2050.00))) with size (4600.00, 500.00))
          • Set VisMod[0] = (Last created visibility modifier)
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point((Position[0] + 2050.00), Position[1])) with size (500.00, 3600.00))
          • Set VisMod[1] = (Last created visibility modifier)
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point(Position[0], (Position[1] - 2050.00))) with size (4600.00, 500.00))
          • Set VisMod[2] = (Last created visibility modifier)
          • Sichtbarkeit - Create an initially Aktiviert visibility modifier for Spieler 1 (Rot) emitting Schwarze Maske across (Region centered at (Point((Position[0] - 2050.00), Position[1])) with size (500.00, 3600.00))
          • Set VisMod[3] = (Last created visibility modifier)
Any ideas on how to make this system more efficient?
If I see this right you only use this "B" integer variable once, to check if trigger runs first time.
You could just run these actions once in an other trigger instead of making a check each 0.1 seconds which is not needed. And this B would also be useless.
And for further situations if you need checks like this, just use a boolean which is TRUE or FALSE. (bools are cooler :d)

  • Set Position[0] = (X of (Position of Unit))
  • Set Position[1] = (Y of (Position of Unit))
-->
better
best
  • Set PointVariable
  • Set Position[0] = (X of (PointVariable))
  • Set Position[1] = (Y of (PointVariable))
  • Custom script: call RemoveLocation(udg_PointVariable)
  • Custom script: set udg_Position[0] = GetUnitX(udg_Unit)
  • Custom script: set udg_Position[1] = GetUnitY(udg_Unit)
And you should create 2 normal real variables and call them x and y instead of "position" and array.

Then you could create these 3 rects once and then only refresh their position to unit instead of re-creating and destroying them.
(I know you seem to be only GUI user but just wanna show you the cool native function, and you could use it in custom script)

Imagine we already have the coordinates of your unit called x,y and rects are r [array].
  • For each i from 0 to 3, do (Actions)
    • Loop - Actions
      • Custom script: call MoveRectTo(udg_r[udg_i], udg_x, udg_y)
I cant completely surround using squared regions
In case you don't know: Circles are also an option, not only rects.

note:
If you would change it as I said you would not, but currently you leak more than 10~ locations in your periodic event.
Read about MemoryLeaks and how to prevent it. You find a tutorial in my signature under "Links".
 
Level 3
Joined
Feb 13, 2014
Messages
26
Is not working :C

I fixed somethings you mentioned.
1. made the first run of the trigger in a different one, which made B not needed anymore.
2. Changed the Position array for two variables instead, X and Y
question: the reason behind this is that I should avoid arrays when possible?
3. used the custom script instead of the = (x of (Position of Unit))
  • Custom script: set udg_X = GetUnitX(udg_Unit)
  • Custom script: set udg_Y = GetUnitY(udg_Unit)
4. here is were i got the problem.
For starters xD I am a GUI person since I'm new at this , but I don't reject at all custom scripts I plan on learning JASS eventually.

well the function you gave me makes regions move. Since I didn't work with regions , only with the VisModifiers I had to work around it making 4 starter regions and setting them into an array variable at map Init.

1tYXZduEdh4ncLORJT5lWo

  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Unit creation, Day/Night cycle.. bla bla bla. --------
      • Set MaskR[0] = Top <gen>
      • Set MaskR[1] = Right <gen>
      • Set MaskR[2] = Bot <gen>
      • Set MaskR[3] = Left <gen>

Now the problem I get resides on Vision modifiers creating on the region position but being unattached of the region. What I mean is that even if I move the regions. the VisMod will not move with it... I even tried Disable /Enable In hopes for them to be refreshed which brings me to needing to destroy and re-create them in the new region position making it just a harder way to do what I initially did. Im doing something wrong?.

Ill attach the 2 triggers the initial(runs one time) and the periodic ones.

  • BlackMask Init
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Black mask across Top <gen>
      • Set VisMod[0] = (Last created visibility modifier)
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Black mask across Right <gen>
      • Set VisMod[1] = (Last created visibility modifier)
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Black mask across Bot <gen>
      • Set VisMod[2] = (Last created visibility modifier)
      • Visibility - Create an initially Enabled visibility modifier for Player 1 (Red) emitting Black mask across Left <gen>
      • Set VisMod[3] = (Last created visibility modifier)
      • Trigger - Turn off (This trigger)
      • Trigger - Turn on BlackMask <gen>


Periodic one

  • BlackMask
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set udg_X = GetUnitX(udg_Unit)
      • Custom script: set udg_Y = GetUnitY(udg_Unit)
      • Custom script: call MoveRectTo(udg_MaskR[0], udg_X, udg_Y)
      • -------- I know this will not make the regions move as a Square. Since they all are being moved to the same place but ill fix that when the VisionModifiers actualy move. xD --------
      • Custom script: call MoveRectTo(udg_MaskR[1], udg_X, udg_Y)
      • Custom script: call MoveRectTo(udg_MaskR[2], udg_X, udg_Y)
      • Custom script: call MoveRectTo(udg_MaskR[3], udg_X, udg_Y)
      • -------- Debug --------
      • Floating Text - Create floating text that reads Region is here but ... at (Center of MaskR[0]) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
      • -------- Debug --------
      • For each (Integer A) from 0 to 3, do (Actions)
        • Loop - Actions
          • Visibility - Disable VisMod[(Integer A)]
          • Visibility - Enable VisMod[(Integer A)]

Also Three out of curiosity questions...
1) Custom scripts are compatible with "For each Integer A... do actions" actions?
because this will not pass the syntaxis test

  • For each (Integer A) from 0 to 3, do (Actions)
    • Loop - Actions
      • Custom script: call MoveRectTo(udg_MaskR[Integer A], udg_X, udg_Y)
If yes how do I refer to the "Integer A" in custom scripts ?

2) The fields of funtions like
native MoveRectTo takes rect whichRect, real newCenterX, real newCenterY returns nothing

were they take "Real newCenterX, real newCenterY"
can take aritmetic expresions instead of the pure variable? like..
(...,udg_X+2500,udg_Y)

3) I've seen in some post a "Hide/Show" tab to organize all this triggers mess. I cant figure out how :C. so... how? <---Fixed

Sorry for the mess.:thumbs_down:
 
Last edited:
Look at The Things That Leak tutorial.
This leaks. (Center of MaskR[0])

Post your triggers that are the problem please.
Don't use integer A / B. They are slower and less efficient than using your own variable.
Regions always move with the move region action. The reason you are thinking that they do not move is that the trigger events never get updated. So the old location is still being used for the triggers events.
Arrays are almost the same as using non arrayed variables. The differences is that they are an array of one type of variable. The look up is slightly slower but nothing that you would ever notice. Not even when using a few thousand look ups.

Look at my tutorial things a GUIer should know. It is in my sig.
 
bj_forLoopAIndex = Integer A in custom script. But use your own integer, A/B is nap.

And yes you can use custom script in loops.

Yes, "takes real" also may take (50+10*44-10).

For starters xD I am a GUI person since I'm new at this , but I don't reject at all custom scripts I plan on learning JASS eventually.
Working with many custom scripts is very good to get used to JASS slowly. :)

Could you attach your map?
 
Level 3
Joined
Feb 13, 2014
Messages
26
Look at The Things That Leak tutorial. This leaks. (Center of MaskR[0])
I'm aware of the leaks so far (at least now) ill fix them when the triggers work :c...

I'm sorry if the extra triggers I posted are un-needed I like to fill my questions with all the info I find pertinent so I can get a nice single answer... instead of making a series of post were I try to explain what I really need making people waste time because I failed to explain with my main question that lacked info.

Regions always move with the move region action.

Erm no, I KNOW the regions move, I even made a debug message to make sure of that , the problem is that the Vision modifiers don't move with the region... the problem are them not the regions.

... is that the trigger events never get updated. So the old location is still being used for the triggers events.

How is not updated? when a periodic event is setting X and Y to a new value (if the unit moved ofc) every 1s . What do you mean?.

What im trying to evade is the multiple creation and destruction of visibility modifiers. Do you know how to update their positions(Aka move them) ?


XD and coincidence, I already had your tutorial in favorites I will give it a read with notebook and pencil on hand.



Edit: IcemanBo here I attached new map (BTW that was your 666 Post, evil post o_O xD)
 

Attachments

  • DinamicBlackMask.w3x
    24.7 KB · Views: 26
Level 3
Joined
Feb 13, 2014
Messages
26
Solved :D thanks

Yes i gave up on moving the Visibility modifier, although would be nice discovering if is even possible to move them.

I Saw your solutions I like it! is similar to my first idea but fixes those ugly rectangular corners on vision and is amazingly much simpler.

Also it reminds me of a early idea I rejected before even making this post. which was pretty much the same thing... creating a global black mask and making a visibility modifier (circular) around the unit but It was buggy ... some how that plain "emitting visibility" did not override the black mask, I was getting a intermittent vision.

Learning GUI is can demotivate you sometime xD knowing that the power tools reside on JASS, but o well I suppose one should start with the basics.

Btw in that script( yes im using JassCraft to help me understand scripts for a time now)

native SetFogStateRadius takes player forWhichPlayer, fogstate whichState, real centerx, real centerY, real radius, boolean useSharedVision returns nothing

Focus on " fogstate whichState "
I saw that you wrote:
...,FOG_OF_WAR_VISIBLE,...

What other options are there to use in that field? just out of curiosity so i can play with it.
by the way thanks for the amazing attention and help I really appreciate it
you too deathismyfriend :p
 
What im trying to evade is the multiple creation and destruction of visibility modifiers. Do you know how to update their positions(Aka move them) ?

From what I know you can't move the modifiers. You have to destroy and create them. You can create multiples though for common areas then you can check if the x and y values is at the common area and hide and show the already created modifier instead of creating and destroying them.

Yes i gave up on moving the Visibility modifier, although would be nice discovering if is even possible to move them.

native SetFogStateRadius takes player forWhichPlayer, fogstate whichState, real centerx, real centerY, real radius, boolean useSharedVision returns nothing

Focus on " fogstate whichState "
I saw that you wrote:
...,FOG_OF_WAR_VISIBLE,...

What other options are there to use in that field? just out of curiosity so i can play with it.

If you use JNGP you can go to the trigger editor then you can click on the function list and click constants. Then type in fog and it will come up with these that you can use.
JASS:
FOG_OF_WAR_FOGGED
FOG_OF_WAR_MASKED
FOG_OF_WAR_VISIBLE

If you are thinking about switching to JASS you should take a look at my GUI to efficient JASS tutorial. That is the way I learned. I tried to make it as easy as possible and you can post on the tutorial for any questions.
 
Status
Not open for further replies.
Top