| 08-09-2008, 04:15 AM | #1 |
What is the best way to check (and how do I check) that a coordinate is outside the map boundaries, and then change the coordinate so it does not go outside the map bounds? (PS: For a charge spell) |
| 08-09-2008, 05:27 AM | #2 |
load max and min X\Y values into globals and check. there is no faster or better way then globals and checks. |
| 08-09-2008, 11:15 AM | #3 |
That... doesn't help much. I'm asking how I go about checking, and then the best way to change the x/y's so it doesn't crash the map. |
| 08-09-2008, 11:20 AM | #4 |
Before you move a unit, check the x and y co-ordinates: JASS://calculate the target x/y if targetX > MapMaxX then set targetX = MapMaxX elseif targetX < MapMinX then set targetX = MapMinX endif if targetY > MapMaxY then set targetY = MapMaxY elseif targetY < MapMinY then set targetY = MapMinY endif //move the unit Depending on the situation you'll probably just want to kill the spell when the co-ordinates lie outside the map. |
| 08-09-2008, 11:26 AM | #5 |
JASS:library GetWorldBoundsMinMax initializer init //! textmacro SetSafeX takes X if $X$ < GetXmin() then set $X$= GetXmin() elseif $X$ > GetXmax() then set $X$= GetXmax() endif //! endtextmacro //! textmacro SetSafeY takes Y if $Y$ < GetYmin() then set $Y$= GetYmin() elseif $Y$ > GetYmax() then set $Y$= GetYmax() endif //! endtextmacro globals private real Xmin private real Ymin private real Xmax private real Ymax endglobals function GetXmin takes nothing returns real return Xmin endfunction function GetXmax takes nothing returns real return Xmax endfunction function GetYmin takes nothing returns real return Ymin endfunction function GetYmax takes nothing returns real return Ymax endfunction public function init takes nothing returns nothing local rect r= GetWorldBounds() set Xmin= GetRectMinX(r) set Ymin= GetRectMinY(r) set Xmax= GetRectMaxX(r) set Ymax= GetRectMaxY(r) call RemoveRect(r) set r=null endfunction endlibrary and finally an example : JASS:function test takes real x , real y returns nothing //! runtextmacro SetSafeX("x") //! runtextmacro SetSafeY("y") call CreateUnit(Player(0),'hpea',x,y,0.0) endfunction |
| 08-09-2008, 11:33 AM | #6 |
Didn't Blizzard make that no longer crash anyway? |
| 08-09-2008, 11:42 AM | #7 | ||
Quote:
Quote:
Yeah, they did. It freezes Wc3 instead, until your computer manages to pull out of it (using Ctrl + Alt + Del and Alt + Tab). I find it retarded they don't just do what SetUnitPosition does (rams them right up to the edge but doesn't place them there) Thanks for the help :D |
| 08-09-2008, 11:46 AM | #8 |
I had edited my post. I made invalid macros. |
| 08-09-2008, 11:56 AM | #9 |
You also made a minor typo ( $R$ instead of $X$ ) but I can fix that on my own. I like your method; I shall use it! +rep for the macros. |
