| 01-13-2008, 07:21 PM | #1 |
try this : JASS:globals region REG real R1=0 real R2=300 endglobals JASS:function Trig_Init_Actions takes nothing returns nothing local rect r=Rect(R1,R1,R2,R2) set REG=CreateRegion() call CreateUnit(Player(0),'hpea',R1,R1,0) call CreateUnit(Player(0),'hpea',R2,R2,0) call CreateUnit(Player(0),'hpea',R1,R2,0) call CreateUnit(Player(0),'hpea',R2,R1,0) call CreateUnit(Player(0),'hfoo',-50,-50,0) call RegionAddRect(REG,r) call TriggerRegisterEnterRegion( gg_trg_Enter, REG,null ) endfunction //=========================================================================== function InitTrig_Init takes nothing returns nothing set gg_trg_Init = CreateTrigger( ) call TriggerAddAction( gg_trg_Init, function Trig_Init_Actions ) endfunction JASS:function Trig_Enter_Actions takes nothing returns nothing local unit u=GetTriggerUnit() local real x=GetUnitX(u) local real y=GetUnitY(u) local boolean array b local string array s local integer i=0 call BJDebugMsg(" ") call BJDebugMsg("enter") call BJDebugMsg("X = " + R2S(x) ) call BJDebugMsg("Y = " + R2S(y) ) set b[0]= x>=R1 set b[1]= y>=R1 set b[2]= x<=R2 set b[3]= y<=R2 set s[0]= "x>=R1" set s[1]= "y>=R1" set s[2]= "x<=R2" set s[3]= "y<=R2" loop exitwhen i==4 if b[i] then call BJDebugMsg(s[i]) endif set i=i+1 endloop if b[0] and b[1] and b[2] and b[3] then call BJDebugMsg("the unit is in rect") else call BJDebugMsg("the unit is not in rect") endif endfunction //=========================================================================== function InitTrig_Enter takes nothing returns nothing set gg_trg_Enter = CreateTrigger( ) call TriggerAddAction( gg_trg_Enter, function Trig_Enter_Actions ) endfunction Move the footman in the region (position of the 4 peasants). And see what's happen when the footman is coming to right and up side when the footman is coming to rigth side, GetUnitX > Xmax of the region when the footman is coming to up side, GetUnitY > Ymax of the region |
| 01-13-2008, 08:11 PM | #2 |
Depends on what R1 and R2 are. Regions are only precise to 32 units, and IIRC the enters region occurs when any part of the model (not the origin) enters the region. Maybe I'm not remembering right... |
| 01-13-2008, 08:16 PM | #3 |
R1 is the min value (x and y) R2 is the max value (x and y) region REG : Xmin = 0 Ymin = 0 Xmax = 300 Ymax = 300 Try and you will see what i want say Edit : Oh sorry i've forgotten the globals JASS:globals region REG real R1=0 real R2=300 endglobals |
| 01-14-2008, 11:30 AM | #4 | |
Quote:
Here is the new code for use faster : JASS:globals constant integer UNIT = 'hmtt' endglobals globals region REG real R1 = 1 real R2 = 32*10 trigger T endglobals library Initialisation initializer Init function Trig_Enter_Actions takes nothing returns nothing local unit u=GetTriggerUnit() local real x=GetUnitX(u) local real y=GetUnitY(u) local boolean array b local string array s local integer i=0 call BJDebugMsg(" ") call BJDebugMsg("enter") call BJDebugMsg("X = " + R2S(x) ) call BJDebugMsg("Y = " + R2S(y) ) set b[0]= x>=R1 set b[1]= y>=R1 set b[2]= x<=R2 set b[3]= y<=R2 set s[0]= "x>=R1" set s[1]= "y>=R1" set s[2]= "x<=R2" set s[3]= "y<=R2" loop exitwhen i==4 if b[i] then call BJDebugMsg(s[i]) endif set i=i+1 endloop if b[0] and b[1] and b[2] and b[3] then call BJDebugMsg("the unit is in rect") else call BJDebugMsg("the unit is not in rect") endif endfunction //=========================================================================== function Init takes nothing returns nothing local rect r set r=Rect(R1,R1,R2,R2) set T=CreateTrigger() set REG=CreateRegion() call CreateUnit(Player(0),'hpea',R1,R1,0) call CreateUnit(Player(0),'hpea',R2,R2,0) call CreateUnit(Player(0),'hpea',R1,R2,0) call CreateUnit(Player(0),'hpea',R2,R1,0) call CreateUnit(Player(0),UNIT,-100,-100,0) call RegionAddRect(REG,r) call TriggerRegisterEnterRegion( T, REG,null ) call TriggerAddAction( T, function Trig_Enter_Actions ) endfunction endlibrary As you can test, it seems depends the origin of the model, not of an any part. You mean the region must contains 32 units ?! If you talk about a size of a cell, i fix it i think, and it's still the same |
| 01-14-2008, 09:23 PM | #5 |
yes, this is a bug and is related very well here |
| 01-15-2008, 09:57 AM | #6 | |
Quote:
well, only four years later. But btw he didn't say why. I mean, it's because the X and Y of the unit. So there is an easy (useless) way to detect where the unit comes from (only north and east) |
| 01-15-2008, 03:44 PM | #7 |
I think that the event fires slightly before the unit's position passes into the region, just like a damage event fires just before damage is done. |
| 01-15-2008, 03:56 PM | #8 | |
Quote:
|
| 01-15-2008, 04:59 PM | #9 |
its a bug, hard to know why it happens |
