• 🏆 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] [Snippet] SuspendUnit

Info

Sometimes it's not recommended to use the PauseUnit() function,
because it has some (usually) unwanted side effets like:

  • Buffs/effects suspend.
  • Orders are stored when paused, and fired on UnPause.
  • Can screw up animations. (link)
  • Unit does not accept PowerUpss, UnitAddItem returns true, but item is not picked up. (link)

But in some cases we might want need a good alternative which completly makes a unit unuseable.

Code

JASS:
library SuspendUnit /* v1.1    By IcemanBo (credits to Maker for this method)

    Alternative for the PauseUnit() function without known side effects.
    A paused unit will be completly unuseable until unpaused.
    Unit's current order will be forgetten.
    
            API
          ¯¯¯¯¯¯
    function SuspendUnit(unit, boolean) returns nothing
    
    function IsUnitSuspended(unit) returns boolean
    
        
    Instructions:
   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    After copying the library save the map and restart the editor.
    When done, then comment out the next line:*/
    
    //! external ObjectMerger w3a ANcl paus Ncl6 1 "defend" anam "Channel Pause" acat "" atat "" aher 0 alev 1 Ncl1 1 10000 aani "stand" aeat "" |

    globals
        private constant integer PAUSE = 'paus'
        private constant integer DEFEND = 852055
    endglobals
    function SuspendUnit takes unit u, boolean b returns nothing
        if (b) then
           call UnitAddAbility(u, PAUSE)
           call IssueImmediateOrderById(u, DEFEND)
        else
            call UnitRemoveAbility(u, PAUSE)
        endif
    endfunction
    function IsUnitSuspended takes unit u returns boolean
        return (GetUnitAbilityLevel(u, PAUSE) > 0)
    endfunction
endlibrary

Small test map is attached. (demo code is not up to date)
 

Attachments

  • Pause.w3x
    13.4 KB · Views: 209
Last edited:
Sometimes, moderators can't accept PauseUnit because of it's side effects. Actually there are some reasons why people still submit spells that use it :
1) to "control time". For example, the Chronosphere spell actually "stops the time", so this includes anything (Except for periodic spels) like animations and buffs. It is intended to be that way and I don't see a reason why Moderators always dump the Chronosphere spell if it has to be made that way in the first place.
2) Animations. If there is another way to pause an animation, that would be great.

About the SetUnitPropWindow, Units can still turn while having a PropWindow of 0. Also PropWindow returns radians afaik.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
So it's an alternative way to "pause" a unit. That's nice.

I think every method has it's ups and downs and you have to evaluate every case
different. PauseUnit for example has also some pros as it decreases computation time
for that unit. That's why we use it in dummy unit recycling snippets.
 
2) Animations. If there is another way to pause an animation, that would be great.
call SetUnitTimeScale(u, 0) freezes any animation in place.

About the SetUnitPropWindow, Units can still turn while having a PropWindow of 0. Also PropWindow returns radians afaik.
If you don't want units to turn, you can always just stun them. There's so many stun snippets out there it's not even funny.

Also you can combine prop window with set unit turn speed.
 
@pred: it would be better to call that ensnare.

If you don't want units to turn, you can always just stun them. There's so many stun snippets out there it's not even funny.

Also you can combine prop window with set unit turn speed.

yeh, but then you can't set a unit animation, right? (idk, honest question)
 
yeh, but then you can't set a unit animation, right? (idk, honest question)
You can; I've been using a stun snippet for years to effectively halt units while moving them around in knockback effects; animations play just fine; it's only that the stun effect itself plays the "stand" animation once. You just need to overwrite that.
 
Stunning will probably end up in having the pretty same effect in "disabling" units. (have not really tested for differences)
But approach is mostly different. And here I don't care about durations, but just the state itself. Paused/Unpaused.
It's pretty straight forward. Some other suggestions in thread only disable movement behaviour of unit,
and en up in effects something like "ensnare" like has been said correctly by PnF.
 
^No, it should not. Though I can't test it atm by myself, as I dont have wc3 installed. :/
I am pretty sure it does interfere with defend, as you can not change the order string of the defend ability and you just call call IssueImmediateOrderById(u, DEFEND) in your snippet.

Basicly, if you try your snippet on a footman, he will go into defend mode.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Edit, never mind. I realize now what you're saying upon viewing the code again. IceMan, please update with that adjustment.

JASS:
(UnitRemoveAbility(u, PAUSE) and UnitAddAbility(u, PAUSE) and IssueImmediateOrderById(u, DEFEND)
Isn't it better to check ability's level than having three function calls.

No, because if the unit doesn't have the ability UnitRemoveAbility returns false and the other 2 never get evaluated.

JASS:
function F takes nothing returns boolean
    call BJDebugMsg("Test")
    return true
endfunction
function J takes...
    if false and F() then
...

You'll never see the BJDebugMsg.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
There are 3 issues which have been brought to my attention:

1) Silenced units cannot deploy this ability.
2) Stunned units will not issue this order until after the stun, so additional orders during the stun can override the infinite-channel ability.
3) Unlike with stuns, the order queue is emptied.

Looks like stuns are the best way to go.
 
Top