| 01-17-2003, 05:17 PM | #1 |
Guest | I need a trigger to set a region variable to the region that a specific unit is in. And let me make these things clear: 1)* I don't want to loop through an array of region variables. This is the way I am doing it currently. Is there a better way? 2) I don't want any kind of enter region events. I need to get it WHILE the unit is in the region. 3)I don't want to make a trigger for each region...thats the reason I was using method 1* Hope this makes sense... thanks for any help. |
| 01-17-2003, 07:21 PM | #2 |
Looks like you just need a region comparison, Ive seen one advertised before on a much earlier post, yet ive had trouble finding it. So heres how we can possibly compare regions. (im pretty sure that other function does this the same way) Since a region is defined by 4 real values, (Xmin, Ymin, Xmax, Ymax) its just a matter of comparing those 4 numbers. If you compare the 4 numbers then you have a function to compare regions with. Im writing one and testing it now, ill bring my results back to this thread. FM_TertiaryEye |
| 01-17-2003, 07:40 PM | #3 |
Guest | Nope, sorry thats not what I need. I can do a region comparison...but that's unrelated. I'm am making this crazy trigger for an RPG. I think the looping through an array is the best way. It looks something like: //Psuedo trigger///////////////////////////////////////////// For 0 to NumOfRegions do: If Unit is in RegionArray(Integer A) = true then Set UnitsRegion = RegionArray(Integer A) else Do nothing //Psuedo trigger///////////////////////////////////////////// You get the idea. |
| 01-17-2003, 08:44 PM | #4 |
Well in that case you simply have to use: RectContainsUnit(Region, Unit) Which you are probably doing already/ Looping is basically the only way to do this without using a unit enters region event. The reason you cant get a region from a single point, is because that point could be in several regions at once. Heres the region API just for reference. There are some pretty neat functions in there, like moving regions that might help if you really dont want to use the loop, however using the loop will work fine IMHO, and unless you have hundreds of regions i doubt it will cause you much problem even on a .1 interval. Code:
native Rect takes real minx, real miny, real maxx, real maxy returns rect native RectFromLoc takes location min, location max returns rect native RemoveRect takes rect whichRect returns nothing native SetRect takes rect whichRect, real minx, real miny, real maxx, real maxy returns nothing native SetRectFromLoc takes rect whichRect, location min, location max returns nothing native MoveRectTo takes rect whichRect, real newCenterX, real newCenterY returns nothing native MoveRectToLoc takes rect whichRect, location newCenterLoc returns nothing native GetRectCenterX takes rect whichRect returns real native GetRectCenterY takes rect whichRect returns real native GetRectMinX takes rect whichRect returns real native GetRectMinY takes rect whichRect returns real native GetRectMaxX takes rect whichRect returns real native GetRectMaxY takes rect whichRect returns real native CreateRegion takes nothing returns region native RemoveRegion takes region whichRegion returns nothing native RegionAddRect takes region whichRegion, rect r returns nothing native RegionClearRect takes region whichRegion, rect r returns nothing native RegionAddCell takes region whichRegion, real x, real y returns nothing native RegionAddCellAtLoc takes region whichRegion, location whichLocation returns nothing native RegionClearCell takes region whichRegion, real x, real y returns nothing native RegionClearCellAtLoc takes region whichRegion, location whichLocation returns nothing native Location takes real x, real y returns location native RemoveLocation takes location whichLocation returns nothing native MoveLocation takes location whichLocation, real newX, real newY returns nothing native GetLocationX takes location whichLocation returns real native GetLocationY takes location whichLocation returns real native IsUnitInRegion takes region whichRegion, unit whichUnit returns boolean native IsPointInRegion takes region whichRegion, real x, real y returns boolean native IsLocationInRegion takes region whichRegion, location whichLocation returns boolean // Returns full map bounds, including unplayable borders, in world coordinates native GetWorldBounds takes nothing returns rect Heres the region comparison function i just wrote and its test cases. (for anyone else whose interested) Code:
// Region Comparison Trigger // 17 Jan 03 - FM_TertiaryEye // [email][email protected][/email] function IsSameBounds takes rect region1, rect region2 returns boolean if GetBooleanOr(GetRectMinX(region1) != GetRectMinX(region2), GetRectMinY(region1) != GetRectMinY(region2)) then return false endif if GetBooleanOr(GetRectMaxX(region1) != GetRectMaxX(region2), GetRectMaxY(region1) != GetRectMaxY(region2)) then return false endif return true endfunction function Trig_RegionTest_Actions takes nothing returns nothing local rect RegionVariable // Testing Two Matching Regions (same bounds) if IsSameBounds(gg_rct_A, gg_rct_C) then call DisplayTextToForce(GetPlayersAll(), "Region A shares bounds with Region C:" + " Passed") else call DisplayTextToForce(GetPlayersAll(), "Region A shares bounds with Region C:" + " Failed") endif // Testing two regions with same size but not same bounds if IsSameBounds(gg_rct_A, gg_rct_B) then call DisplayTextToForce(GetPlayersAll(), "Region A does not share bounds with Region B:" + " Failed") else call DisplayTextToForce(GetPlayersAll(), "Region A does not share bounds with Region B:" + " Passed") endif set RegionVariable = gg_rct_A set udg_CurrentRegion = gg_rct_B // Testing a region with an assigned local and global variable if IsSameBounds(gg_rct_A, gg_rct_C) then call DisplayTextToForce(GetPlayersAll(), "Region A shares bounds with Region C" + " Passed") else call DisplayTextToForce(GetPlayersAll(), "Region A shares bounds with Region C" + " Failed") endif endfunction //=========================================================================== function InitTrig_RegionTest takes nothing returns nothing set gg_trg_RegionTest = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_RegionTest, Player(0), "-test", true ) call TriggerAddAction( gg_trg_RegionTest, function Trig_RegionTest_Actions ) endfunction |
| 01-17-2003, 09:37 PM | #5 |
Guest | Good point...about point being in more than one region. I am going to have to get creative with this thing. Btw: I was just using triggers, but that custom text looks easy...like C++. I'll have to check that out. Thanks. |
