[Snippet] DisableUnitMovement

Scripts

14 years
edited 8 years
Disables the movement of a particular unit. This method was discovered by WaterKnight (or at least, it was first exposed to the public by WaterKnight) in this thread:
http://www.hiveworkshop.com/forums/world-editor-help-zone-98/setunitpropwindow-disableunitmovement-206527/

I made this library to be a simple wrapper for it. Of course, this is all inlineable, but it is a useful technique for people to know.

Setting a unit movespeed to 1 will still allow it to move (ever so slowly) and will interrupt orders. Ensnares ground units and whatnot. This has no debuff, and works 100%.

Code (jass) Select
1
library DisableUnitMovement /* v1.0.0.1
2
*******************************************************************
3
*
4
*   Disables unit movement. They can still turn, but will stay in
5
*   place. It simulates an ensnare-like effect, except that it will
6
*   not ground units, it does not have buffs, does not interrupt
7
*   channeled casts and appears to have no downsides.
8
*
9
*   Full credits to WaterKnight for discovering this technique.
10
*
11
*******************************************************************
12
*
13
*   function DisableUnitMovement takes unit u returns nothing
14
*
15
*       - Prevents a unit from moving.
16
*
17
*   function EnableUnitMovement takes unit u returns nothing
18
*
19
*       - Allows a unit to move once again.
20
*
21
*******************************************************************/
22
23
    function DisableUnitMovement takes unit u returns nothing
24
        call SetUnitPropWindow(u, 0)
25
    endfunction
26
27
    function EnableUnitMovement takes unit u returns nothing
28
        call SetUnitPropWindow(u, GetUnitDefaultPropWindow(u) * bj_DEGTORAD)
29
    endfunction
30
31
endlibrary


Spoiler
Code (jass) Select
1
/*    Demo    */
2
scope Demo initializer Test
3
    globals
4
        private unit footman
5
    endglobals
6
7
    private function OnExpire takes nothing returns nothing
8
        call EnableUnitMovement(footman)
9
        call BJDebugMsg("Movement enabled!")
10
    endfunction
11
 
12
    private function Test takes nothing returns nothing
13
        set footman = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
14
        call DisableUnitMovement(footman)
15
        call BJDebugMsg("Movement disabled!")
16
        call TimerStart(CreateTimer(), 5, false, function OnExpire)
17
    endfunction
18
endscope
19

EDIT: Updated thanks to kStiyl. Apparently SetUnitPropWindow expects radians. Seems to be true judging by SetUnitPropWindowBJ(). Also fixed a syntax error, oops.
14 years
I do love how nice are this simple scripts. Adn this technique is lovely, Good job :)

And of Course, uber approved :)