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

[vJass] Out of Map

Status
Not open for further replies.
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

Yes it's another thread from me. I try to learn vJass since 3 days and I finish my first own spell this day. Was a long day to make it but it's done so far =)

Now I have a problem, the spell creates a ball (dummy unit) that flies over the map. The problem is the dummy can fly out of the map.

I know that Vexorian created a good system called Bound Sentinel, but my plan was to make it so, that the spell will END when the ball is out of the map.


The dummy walks to the points "d.x1 und d.y1" also a rect named "ENUM_RECT" is always at the position of the ball, so I thought maybe something like "if the coordinates or the rect is out of map then end spell". Maybe it isn't that simple but can someone help me with that please?

Again: I'm learning vJass, so please a clear help that I can understand it ^^


Greetings - Thanks - Peace
Dr. Boom
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
x1 = Min x of playable map area ( x of left side)
y1 = Min y of playable map area ( y of bottom side )
x2 = Max x of playable map area ( x of right side)
y2 = Max y of playable map area ( y of top side )

(x,y) = coordinates of the unit

So if y > y2 or x > x2 or y < y1 or x < x1 then out of bounds
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Hm, did you try this already?

JASS:
function test takes nothing returns nothing
    local real X = GetRectCenterX(ENUM_RECT)
    local real Y = GetRectCenterY(ENUM_RECT)
    local real x1 = GetRectMaxX(bj_mapInitialPlayableArea)
    local real y1 = GetRectMaxY(bj_mapInitialPlayableArea)
    local real x2 = GetRectMinX(bj_mapInitialPlayableArea)
    local real y2 = GetRectMinY(bj_mapInitialPlayableArea)

    if X >= x1 or Y >= y1 or X <= x2 or Y <= y2 then
        call RemoveUnit(bj_lastCreatedUnit)
    endif
endfunction
The 'or's are important (once one of these limits is exceeded, the unit is considered out of bounds) and try to double-check the x1, x2, y1 and y2 for the correct values :p (you might mix up a few and it'll bug the 'system' :/).
At least, in MY theory it works xD

And in case it doesn't work, a worse method:
JASS:
    local region check = CreateRegion()
    local location l = Location(GetRectCenterX(ENUM_RECT), GetRectCenterY(ENUM_RECT)) // Yes a location! D:

    call RegionAddRect(check, bj_mapInitialPlayableArea)
    if IsLocationInRegion(check, l) then
        call RemoveUnit(dummy)
    endif
    
    call RemoveRegion(check)
    call RemoveLocation(l)
    set l = null
    set check = null

Edit: too late ^^
 
Status
Not open for further replies.
Top