• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Lock units into locations

Status
Not open for further replies.
Level 9
Joined
Apr 23, 2011
Messages
460
Hello, I'm certain that I posted this before, but I'm not going to necro that post and this post will address the problem more potently and specifically, please tell me if this is possible, or should just be done by modifying the terrain (last resort).

I am working on a map that is split into various islands and there are areas of the map that I don't want units to be able to go to I.E the waterfall area, the ocean, cliffs etc. However, using some spells that have .03 timers and move the unit in a parabolic motion (arching), they can go into the areas I wish them to not enter. I used Bribe's UnitIsMoving library to create a system that keeps them out, HOWEVER, their z (vertical) height is bugged and they walk above the ground, any idea on how I can fix this problem?
 
Level 25
Joined
May 11, 2007
Messages
4,650
Can't you just use pathing blockers ? (It's in the doodads palette).

And in the trigger when you move the units, before moving them, check with an if (pathing is off at temppoint2) then Remove unit from the movingGroup.
 
Level 9
Joined
Apr 23, 2011
Messages
460
Pathing blockers don't work on them because as the trigger loops through time, it eventually bypasses the pathing blocker coordinates. I'll post my system here.

JASS:
library UnitBadArea initializer init
    struct UnitBadArea
        private static method checkUnit takes unit u returns nothing
            local real x = GetUnitX(u)
            local real y = GetUnitY(u)
            local real retX = UnitMoving(GetUnitUserData(u)).x
            local real retY = UnitMoving(GetUnitUserData(u)).y
            if GetTerrainType(x, y) == 'Avin' or GetTerrainType(x,y) == 'Arck' then
                call SetUnitX(u, retX)
                call SetUnitY(u, retY)
            endif
            set u = null
        endmethod
        private static method getUnits takes nothing returns nothing
            local unit u
            local group g = CreateGroup()
            call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
            loop
                set u = FirstOfGroup(g)
                exitwhen u == null
                call GroupRemoveUnit(g, u)
                call .checkUnit(u)
            endloop
            call DestroyGroup(g)
            set g = null
        endmethod
        static method main takes nothing returns nothing
            call .getUnits()
        endmethod
    endstruct
    
    private function init takes nothing returns nothing
        call TimerStart(CreateTimer(), .03, true, function UnitBadArea.main)
    endfunction
endlibrary
 
Status
Not open for further replies.
Top