| 03-25-2009, 05:01 AM | #1 |
This script should return a unit to the nearest building of a certain type. It displays the debugmsg but doesn't work? Anyone see an issue? JASS:globals constant integer uHARVEST_CORPSE = 'A009' constant integer uBLOOD_PIT = 'n00A' group BWRG = CreateGroup() endglobals function BloodExpr takes nothing returns boolean local unit u = GetFilterUnit() return GetUnitTypeId(u) == uBLOOD_PIT and GetWidgetLife(u) > .405 and GetOwningPlayer(u) == CALLBACK_PLAYER endfunction function BloodWormReturn takes nothing returns nothing local unit u = GetTriggerUnit() local unit b local unit f local real best = 100000 local real r local real dx local real dy local real x = GetUnitX(u) local real y = GetUnitY(u) call BJDebugMsg("rawr") call GroupClear(BWRG) set CALLBACK_PLAYER = GetOwningPlayer(u) call GroupEnumUnitsInRange(BWRG, 0, 0, 12800, Condition(function BloodExpr)) loop set f = FirstOfGroup(BWRG) exitwhen(f == null) set dx = GetUnitX(f) - x set dy = GetUnitY(f) - y set r = dx*dx+dy+dy/10000 if(best > r)then set best = r set b = f endif endloop call IssuePointOrder(u, "move", GetUnitX(b), GetUnitY(b)) endfunction |
| 03-25-2009, 05:46 AM | #2 | |
Quote:
1) have to put parentheses around the distance. division is before addition 2) You added ry by itself instead of multiply set r = (rx*rx + ry*ry) / 10000 |
