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

[Trigger] Dynamic Gate Triggers

Status
Not open for further replies.
Level 3
Joined
Nov 18, 2015
Messages
41
I guess today just isn't my day. Gate doesn't like me, won't open. I'm awful tired and could probably use a fresh pair of eyes to take a gander and find what I'm doing wrong here.

EDIT: My apologies, I JUST realized I was in the wrong section. I'm sorry.

EDIT2: After a few tests I determined my first problem lies with the first condition...

  • If - Conditions
    • ((Triggering unit) is in (Units in gateRegion[tempInt])) Equal to True
    • (gateRegion[tempInt] contains tempLoc) Equal to True
    • (gateRegion[tempInt] contains (Triggering unit)) Equal to True
All of these seemed to return the same thing. False.

  • Main
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Trigger - Run InitGates <gen> (ignoring conditions)
  • InitGates
    • Events
    • Conditions
    • Actions
      • Set gate[0] = Icy Gate (Horizontal downwards) 0100 <gen>
      • Set gateRegion[0] = gate01 <gen>
      • Set gateCount = 1
      • For each (Integer tempInt) from 0 to (gateCount - 1), do (Actions)
        • Loop - Actions
          • Set gateOpen[tempInt] = False
          • Trigger - Add to Gate Open <gen> the event (Unit - A unit enters gateRegion[tempInt])
          • Trigger - Add to Gate Close <gen> the event (Unit - A unit leaves gateRegion[tempInt])
  • Gate Open
    • Events
    • Conditions
    • Actions
      • For each (Integer tempInt) from 0 to (gateCount - 1), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is in (Units in gateRegion[tempInt])) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • gateOpen[tempInt] Equal to False
                • Then - Actions
                  • Destructible - Open gate[tempInt]
                  • Set gateOpen[tempInt] = True
                • Else - Actions
            • Else - Actions
  • Gate Close
    • Events
    • Conditions
    • Actions
      • For each (Integer tempInt) from 0 to (gateCount - 1), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in (Units in gateRegion[tempInt])) Equal to 0
              • gateOpen[tempInt] Equal to True
            • Then - Actions
              • Destructible - Close gate[tempInt]
              • Set gateOpen[tempInt] = False
            • Else - Actions
 
Last edited:
Level 8
Joined
Jan 28, 2016
Messages
486
In your Init Gate trigger, you have the loop going "from 0 to (GateCount - 1)" but you're setting GateCount to 1 just prior to the loop so it ends up as "from 0 to 0" and never runs the loop actions (hence the events to the other triggers are never added).
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
In your Init Gate trigger, you have the loop going "from 0 to (GateCount - 1)" but you're setting GateCount to 1 just prior to the loop so it ends up as "from 0 to 0" and never runs the loop actions (hence the events to the other triggers are never added).
Regular "For Loop Integer A" etc work just fine in GUI from 1 to 1. The structure is:
JASS:
loop
    exitwhen Iterator > Max
    //stuff
    set Iterator = Iterator + 1
endloop
 
Level 8
Joined
Jan 28, 2016
Messages
486
Regular "For Loop Integer A" etc work just fine in GUI from 1 to 1. The structure is:
JASS:
loop
    exitwhen Iterator > Max
    //stuff
    set Iterator = Iterator + 1
endloop

This is sad because I typically code in Jass and I usually structure my loops like this... -_____-

In that case, the triggers should work. The only other possible issue I can think of might be due to an inherent bug with regions as demonstrated in a test map in this thread: Compact Hero Selector help!!. There's also a link in the last post to a thread from the Warcraft 3 Campaigns explaining the bugs in quite some detail.
 
Level 3
Joined
Nov 18, 2015
Messages
41
Ahhh, so the truth unfolds. So GUI "unit-in-region" detection is not the way to go. I've no problem with using JASS or custom scripts if y'all have any input to give?
I'll start looking in to it a bit on my own while I wait for you guys, maybe see if I can't figure it out myself while I'm waiting.

Thank you for the replies.

EDIT: It just occured to me that I can detect if the unit is in range of the gate instead. I used this.

  • Gate Open
    • Events
    • Conditions
    • Actions
      • For each (Integer tempInt) from 0 to (gateCount - 1), do (Actions)
        • Loop - Actions
          • Set tempLoc = (Position of gate[tempInt])
          • Set tempUGroup = (Units within 250.00 of tempLoc)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) is in tempUGroup) Equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • gateOpen[tempInt] Equal to False
                • Then - Actions
                  • Destructible - Open gate[tempInt]
                  • Set gateOpen[tempInt] = True
                • Else - Actions
            • Else - Actions
          • Custom script: call RemoveLocation(udg_tempLoc)
          • Custom script: call DestroyGroup(udg_tempUGroup)
It struck me that if the triggering unit is entering the region he will always be within range of the gate. I pulled the number 250 out of my ass but as long as none of my gates are that close together then I don't foresee any problems.

However, as far as closing the gate, I still detect if there are any other units within that region, and if there aren't I close the gate. But if a unit is on that border of the region where he will trigger the event of entering but not quite in the region itself, he won't be found when searching for units to close the gate, and thus the gate will close with him still inside the region and he will have to re-enter the region to get it to open again.
 
Last edited:
Level 10
Joined
Oct 5, 2008
Messages
355
You could circuvent this by increasing the closing range to 300 while leaving the opening range at 250. so this case shouldnt come up in the first case since when the door closes, then the last unit would be still farther away than the opening range and nit at the edge of it.
 
Level 3
Joined
Nov 18, 2015
Messages
41
You could circuvent this by increasing the closing range to 300 while leaving the opening range at 250. so this case shouldnt come up in the first case since when the door closes, then the last unit would be still farther away than the opening range and nit at the edge of it.
Yes but then if a unit was caught in that radius, but definitely outside the region, then if they left without ever entering the region to trigger the event then the gate would be stuck open.
That's why I'm not selecting units based on radius for closing, you can't define a rectangular region with a radius.
 
Level 10
Joined
Oct 5, 2008
Messages
355
Well, you can detect if a unit enters and leaves an area near an unit. So insead of a region, you could create atmap initiation a dummy at the doors location and add the event "unit comes within (range) of (dummy). Always make the checking radius a bit larger than the event radius, since it isnt qute exact.
This could even save sone map space by nit needing to create rects
 
Level 3
Joined
Nov 18, 2015
Messages
41
Well, you can detect if a unit enters and leaves an area near an unit. So insead of a region, you could create atmap initiation a dummy at the doors location and add the event "unit comes within (range) of (dummy). Always make the checking radius a bit larger than the event radius, since it isnt qute exact.
This could even save sone map space by nit needing to create rects

Using the range of the position of the gate works just fine I don't need a dummy, but I can't use range for closing the gate, I need a region.
 
Level 39
Joined
Feb 27, 2007
Messages
5,010
Why not a simpler method:

Use the unit in range with the gate to know when to open it. Every 1-2 seconds loop through all your gates and check how many units are within <Unit in range radius + a little bit> of each one. If 0 for any given gate and it is presently open, then close the gate.
 
Status
Not open for further replies.
Top