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

[General] game does not realise when region contains unit

Status
Not open for further replies.
Level 12
Joined
Jan 13, 2008
Messages
559
Hi, for some reason the the trigger never passes the condition which checks if triggering unit is in that region. What am I missing? thank you

  • a1
    • Events
      • Unit - A unit enters a1 <gen>
      • Unit - A unit enters a2 <gen>
      • Unit - A unit enters a3 <gen>
      • Unit - A unit enters a4 <gen>
      • Unit - A unit enters a5 <gen>
      • Unit - A unit enters a6 <gen>
      • Unit - A unit enters a7 <gen>
      • Unit - A unit enters a8 <gen>
      • Unit - A unit enters a9 <gen>
      • Unit - A unit enters a10 <gen>
      • Unit - A unit enters a11 <gen>
      • Unit - A unit enters a12 <gen>
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (region_locations[((1 x 12) + 12)] contains (Triggering unit)) Equal to True
        • Then - Actions
          • Unit - Remove (Triggering unit) from the game
        • Else - Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (region_locations[((1 x 12) + (Integer A))] contains (Triggering unit)) Equal to True
            • Then - Actions
              • Game - Display to (All players) the text: 2
              • Set point_leakRemove = (Center of region_locations[((1 x 12) + ((Integer A) + 1))])
              • Unit - Order (Triggering unit) to Move To point_leakRemove
              • Custom script: call RemoveLocation(udg_point_leakRemove)
            • Else - Actions


  • locations init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- a --------
      • Set region_locations[((1 x 12) + 1)] = a1 <gen>
      • Set region_locations[((1 x 12) + 2)] = a2 <gen>
      • Set region_locations[((1 x 12) + 3)] = a3 <gen>
      • Set region_locations[((1 x 12) + 4)] = a4 <gen>
      • -------- b --------
      • Set region_locations[((2 x 12) + 1)] = b1 <gen>
 
Last edited:
JASS:
There are regions and rectangulars.
Regions is a set of cells, it does not need to be a rectangular.
There are functions to add rects and cells to a region.

GUI:
There are no regions.
Rects are called "Regions" in GUI.

==

There exists one "enter" event, which fires when a unit enters a region. (jass region)
But in GUI there are no regions, so it makes following:
The gui event internaly creates an empty region, and then adds the rectangular to the region.
After that it uses the normal jass event, which fires when a unit enters a region. (the region which contains the rect)

So far so good.

The bad thing with the function that adds rects to the region, RegionAddRect, is that it doesn't work correctly.
So when the GUI tries to add the rect to the region, always an extra cell (32x32) is added to MaxX and MaxY of the original rect.
This means for us, when a unit enters this new created extra cell, the event will fire, because the unit enets the region, though
the problem is, it is actually NOT inside our rect yet.

The problem should only occur, when units enters from right or from above (somewhere at corner), as there is the extra cell.
When units enter from left/bottom, it should always work correctly.

An easy fix is not to use the boolean condition which checks if a unit is inside a certain "rect", as it's not always right when the event fires.
For this, each "A unit enters region" event need it's seperate trigger, so don't have to check for the entered rect.
 
Level 13
Joined
May 10, 2009
Messages
868
All right. After looking into it, I found the problem by doing the following:

I've been displaying as text, in-game, the Min X,Y and Max X,Y of your very first region (rect): a1
Here's its properties:

0iHldc6.png


I'm also showing the current X and Y of a unit when it triggers the trigger:

pUrLfxP.jpg

You might have noticed that MaxX of a1 is 8160, and X of that unit is 8184.13. Whenever the function (Region contains Triggering Unit()) tries to check if that unit is within a1, it returns false, because the unit is not within it yet. I don't know exactly if it's either the region that is not precise when a unit triggers it, or if the unit triggers the region prior to their X/Y position be within the region (rect).

Either way, I recorded a video of it and uploaded it to gfycat.
As we can see, the region has exactly the size displayed by those blue effects in the GIF above.

I fixed your trigger by increasing the size of the "region" by +32 for each side. This doesn't seem to make sense at first. However, what you, perhaps, know as region is actually called rect, and there's an actual region in the editor. To be more clear, when you use the event a unit enters/leaves a region, the editor actually creates an actual region copying the size of the rect that you chose in the editor. The game uses the region instead.

So, when I increased the size of rect, region is not affected by that. It looks like this:

jkh2GKO.png


Whenever the unit enters the REGION, it should be already within RECT, so your trigger will return true.

EDIT: What IcemanBo said makes sense. So the image above might not be accurate. It could be both RECT and REGION having the same size, or just RECT being slightly bigger than REGION.

  • locations init
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Custom script: local rect r
      • -------- a --------
      • Set region_locations[((1 x 12) + 1)] = a1 <gen>
      • Set region_locations[((1 x 12) + 2)] = a2 <gen>
      • Set region_locations[((1 x 12) + 3)] = a3 <gen>
      • Set region_locations[((1 x 12) + 4)] = a4 <gen>
      • Set region_locations[((1 x 12) + 5)] = a5 <gen>
      • Set region_locations[((1 x 12) + 6)] = a6 <gen>
      • Set region_locations[((1 x 12) + 7)] = a7 <gen>
      • Set region_locations[((1 x 12) + 8)] = a8 <gen>
      • Set region_locations[((1 x 12) + 9)] = a9 <gen>
      • Set region_locations[((1 x 12) + 10)] = a10 <gen>
      • Set region_locations[((1 x 12) + 11)] = a11 <gen>
      • Set region_locations[((1 x 12) + 12)] = a12 <gen>
      • -------- b --------
      • Set region_locations[((2 x 12) + 1)] = b1 <gen>
      • -------- I've placed the func() at the top of your map. It displays those blue effects. --------
      • Custom script: //call func()
      • -------- Increase the size of the rects, so the event that triggers them won't make the conditions return false --------
      • For each (Integer loop) from 1 to 2, do (Actions)
        • Loop - Actions
          • For each (Integer A) from 1 to 12, do (Actions)
            • Loop - Actions
              • Custom script: set r = udg_region_locations[udg_loop * 12 + bj_forLoopAIndex]
              • Custom script: if r != null then
              • Custom script: call SetRect(r, GetRectMinX(r) - 32., GetRectMinY(r) - 32., GetRectMaxX(r) + 32., GetRectMaxY(r) + 32.)
              • Custom script: endif
      • Custom script: set r = null
  • a1
    • Events
      • Unit - A unit enters a1 <gen>
      • Unit - A unit enters a2 <gen>
      • Unit - A unit enters a3 <gen>
      • Unit - A unit enters a4 <gen>
      • Unit - A unit enters a5 <gen>
      • Unit - A unit enters a6 <gen>
      • Unit - A unit enters a7 <gen>
      • Unit - A unit enters a8 <gen>
      • Unit - A unit enters a9 <gen>
      • Unit - A unit enters a10 <gen>
      • Unit - A unit enters a11 <gen>
      • Unit - A unit enters a12 <gen>
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg("Unit: "+R2S(GetUnitX(GetTriggerUnit()))+", "+R2S(GetUnitY(GetTriggerUnit())))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (region_locations[24] contains (Triggering unit)) Equal to True
        • Then - Actions
          • Unit - Remove (Triggering unit) from the game
        • Else - Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Custom script: if RectContainsCoords(udg_region_locations[12 + bj_forLoopAIndex], GetUnitX(GetTriggerUnit()), GetUnitY(GetTriggerUnit())) then
          • Set point_leakRemove = (Center of region_locations[(12 + ((Integer A) + 1))])
          • Unit - Order (Triggering unit) to Move To point_leakRemove
          • Custom script: call RemoveLocation(udg_point_leakRemove)
          • Custom script: endif
 

Attachments

  • newTD.w3x
    23.1 KB · Views: 70
Last edited:
Status
Not open for further replies.
Top