• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Unit Enable/Disable Movement

Level 13
Joined
Nov 22, 2006
Messages
1,260
Enable/Disable Movement

By: Silvenon


JASS:
function MovementDisable_Conditions takes nothing returns boolean
    local integer i = GetIssuedOrderId()
    return (i == 851971 or i == 851986 or i == 851983 or i == 851990) and not GetHandleBoolean(GetTriggerUnit(), "b")
endfunction

function MovementDisable_Execute takes nothing returns nothing
    call DestroyTimer(GetExpiredTimer())
    call IssueImmediateOrder(udg_MoveUnit, "stop")
endfunction

function MovementDisable_Actions takes nothing returns nothing
    set udg_MoveUnit = GetTriggerUnit()
    call TimerStart(CreateTimer(), 0.00, false, function MovementDisable_Execute)
endfunction

function UnitEnableMovement takes unit u returns nothing
    call SetHandleBoolean(u, "b", true)
endfunction

function UnitDisableMovement takes unit u returns nothing
    call SetHandleBoolean(u, "b", false)
endfunction

function Init_MovementToggle takes nothing returns nothing
    call TriggerAddCondition(udg_Trig, Condition(function MovementDisable_Conditions))
    call TriggerAddAction(udg_Trig, function MovementDisable_Actions)
endfunction

function Init_UnitMovement takes unit u returns nothing
    call SetHandleBoolean(u, "b", true)
    call TriggerRegisterUnitEvent(udg_Trig, u, EVENT_UNIT_ISSUED_POINT_ORDER)
endfunction


A simple system which allows you to disable/enable user movement orders (right-click) given to a certain unit.

If someone is curious about the MovementDisable_Conditions function, these are the ID translations (thanks to PurplePoot):
  • 851971 - smart
  • 851986 - move
  • 851983 - attack
  • 851990 - patrol

Instructions:
  • put this code in your map header
  • create a global trigger variable named Trig and a global unit variable named MoveUnit
  • initialize the system like this: call Init_MovementToggle()
  • initialize the system for a unit like this: call Init_UnitMovement(udg_MyUnitVar)
  • after calling Init_UnitMovement, enable/disable the movement with UnitEnableMovement(udg_MyUnitVar) and UnitDisableMovement(udg_MyUnitVar), example:

  • Events
    • Map initialization
  • Conditions
  • Actions
    • Custom script: call Init_MovementToggle()

  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Tornado
  • Actions
    • set Caster = (Triggering unit)
    • Custom script: call Init_Movement(udg_Caster)
    • Custom script: call UnitEnableMovement(udg_Caster)
    • Wait 5.00 seconds
    • Custom script: call UnitDisableMovement(udg_Caster)

Requires: KaTTaNa's Local Handle Vars

The reason why I made this lame simple system is because I discovered that it doesn't work if ordering a unit to stop directly, but a timer is needed (some lame bug).



If this doesn't work right, please report it!
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
*Edited*

I just realized the previous version wouldn't work at all.

There is a Jump function and a whole spellpack waiting for you also :)

Welcome to the living, btw.

EDIT:

This doesn't stop movement commands ("move"), attack move commands ("attack"), or move to unit commands.

I thought that "smart" means any kind of right-click. Edited.

What is the orderstring of move to unit? "moveto"?
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Fixed it, thanks.

I also used a global instead of attaching the unit to the timer (since timeout 0.00 means that it happens instantly, I hope). ISN'T THAT COOL???

EDIT: Maybe I should've put this in the small code snippets section?
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
He wishes to allow AI movement, as well as attacks/etc.

Actually, I don't know what I wish. I disabled it like this because I needed it that way for my map, and I figured out the bug, and posted here if anyone finds it useful.

Btw, pausing can lead to unwanted effects. Spell disabling, for example. And I wanted the unit to not move when it's ordered to, when with pause you can't even order it. Also, pausing the unit pauses the buffs, I think..............and so on.

If I wanted to make it with pausing, I wouldn't post anything since it's so damn simple that it's not worth posting.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Arghhh I don't know what is that what I want to accomplish! I thought this was a good way to make the unit not move when it's ordered to, all other ways are kinda bad for that. This is good for a spell, for example a spell that makes the other player lose control of his unit, I don't know I'm just guessing.

I was just saying that with a timer it won't work, I thought somebody would find that useful. If not, graveyard it.
 
Top