1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  5. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  8. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Is Unit Moving 2.1.0.0

Submitted by Bribe
This bundle is marked as approved. It works and satisfies the submission rules.
Credits
Xiliger for the idea.
Purpose
Detect if a unit is moving or stopped. This works for any
type of movement (natural, through triggers, etc.)

Just use the boolean:

  • UnitMoving[UDexUnits[UDex]] Equal to true

How to install
  1. Copy and paste the Unit Indexer trigger from the map (if you didn't do so yet)
  2. Copy and paste the Is Unit Moving trigger from the map.
  3. It's installed!

  • Is Unit Moving Config
    • Events
    • Conditions
      • (Default movement speed of UDexUnits[UDex]) Not equal to 0.00
    • Actions
      • -------- Units who do not pass the above conditions will not be allowed to be registered by the system. --------
      • -------- One can add exceptions such as with buildings who have the ability to uproot. --------
      • -------- --------
      • -------- Here you can configure how frequently the check occurs. --------
      • -------- NOTES: This should not be lower than any movement systems in your map. --------
      • -------- Slower checks improve performance, but I wouldn't slow it much more than this. --------
      • -------- --------
      • Set UnitMovementInterval = 0.10


Code (vJASS):

function IsUnitMovementTracked takes integer i returns boolean
    return udg_UMovPrev[i] != 0 or udg_UMovNext[0] == i
endfunction
function UnitMovementRegister takes nothing returns boolean
    local integer i = udg_UDex
    if not IsUnitMovementTracked(i) and TriggerEvaluate(gg_trg_Is_Unit_Moving_Config) then
        set udg_UMovPrev[udg_UMovNext[0]] = i
        set udg_UMovNext[i] = udg_UMovNext[0]
        set udg_UMovNext[0] = i
        set udg_UnitMovingX[i] = GetUnitX(udg_UDexUnits[i])
        set udg_UnitMovingY[i] = GetUnitY(udg_UDexUnits[i])
    endif
    return false
endfunction
function UnitMovementUnregister takes nothing returns boolean
    local integer i = udg_UDex
    if IsUnitMovementTracked(i) then
        set udg_UnitMoving[i] = false
        set udg_UMovNext[udg_UMovPrev[i]] = udg_UMovNext[i]
        set udg_UMovPrev[udg_UMovNext[i]] = udg_UMovPrev[i]
        set udg_UMovPrev[i] = 0
    endif
    return false
endfunction
function RunUnitMovementEvent takes integer i, real e returns nothing
    local integer pdex = udg_UDex
    if e == 1.00 then
        set udg_UnitMoving[i] = true
    else
        set udg_UnitMoving[i] = false
    endif
    set udg_UDex = i
    set udg_UnitMovingEvent = e
    set udg_UnitMovingEvent = 0.00
    set udg_UDex = pdex
endfunction
//===========================================================================
// This function runs periodically to check if units are actually moving.
//
function UnitMovementTracker takes nothing returns nothing
    local integer i = 0
    local integer n
    local real x
    local real y
    loop
        set i = udg_UMovNext[i]
        exitwhen i == 0
        set x = GetUnitX(udg_UDexUnits[i])
        set y = GetUnitY(udg_UDexUnits[i])
        if x != udg_UnitMovingX[i] or y != udg_UnitMovingY[i] then
            set udg_UnitMovingX[i] = x
            set udg_UnitMovingY[i] = y
            if not udg_UnitMoving[i] then
                if GetUnitTypeId(udg_UDexUnits[i]) != 0 then
                    call RunUnitMovementEvent(i, 1.00)
                else
                    set n = udg_UDex
                    set udg_UDex = i
                    set i = udg_UMovPrev[i] //avoid skipping checks
                    call UnitMovementUnregister()
                    set udg_UDex = n
                endif
            endif
        elseif udg_UnitMoving[i] then
            call RunUnitMovementEvent(i, 2.00)
        endif
    endloop
endfunction
//===========================================================================
function InitTrig_Is_Unit_Moving takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, 1.00)
    call TriggerAddCondition(t, Filter(function UnitMovementRegister))
   
    set t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, 2.00)
    call TriggerAddCondition(t, Filter(function UnitMovementUnregister))
   
    if gg_trg_Is_Unit_Moving_Config != null then
        call TriggerExecute(gg_trg_Is_Unit_Moving_Config)
    else
        call ExecuteFunc("Trig_Is_Unit_Moving_Config_Actions")
    endif
    call TimerStart(CreateTimer(), udg_UnitMovementInterval, true, function UnitMovementTracker)
endfunction

 


Version history

  • 1.0.0.0 - Release
  • 1.0.0.1 - Updated the default settings with a 0.5 timer to
    minimize the installation work.
  • 2.0.0.0 - Added OnMove and OnStop events, added a filter for undesirables.
  • 2.1.0.0 - Split into a GUI Config trigger and a JASS engine. This subsequently fixes a couple of bugs while improving performance.


Keywords:
movement, moving, xiliger, isunitmoving, move, detect, unitmoving
Contents

Is Unit Moving Testmap (Map)

Reviews
Moderator
20:09, 31st Jul 2011 Maker: Approved. Does what it is supposed to, and does it well.
  1. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,268
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    Simple system, could be useful though. Aww this uses the custom value of a unit? Lame =s
     
  2. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    That's only because GUIers shouldn't be using the custom value anywhere else, so using it for a GUI UnitIndexer would be ok :)
    The Jass ones use Custom values too you know :p
     
  3. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,268
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    That's why hashtables are better =p
    Perhaps someone should create a hashtable version...
     
  4. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Nah, we're good :)
     
  5. Jazztastic

    Jazztastic

    Joined:
    Apr 4, 2011
    Messages:
    895
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    I don't even know how this would work in a hashtable. Maybe I'm just an idiot, but it seems like Bribe did a fine enough job of it already. This resource and his other one that this relies on are in my map I'm working on, this resource alone is used in 2 spells (one of which I posted)
     
  6. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,032
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Why is it lame? If you are using custom value in another area of your map, you can just change the way you do things:

    Instead of:

    • Unit - Set Custom Value of (Triggering unit) to 100


    It becomes:

    • Set MyValue[(Custom value of (Triggering unit))] = 100


    This way, the custom value can be used for all systems as a simple array point, instead of wasting the custom value on just one little system. That's the beauty of a unit indexing system.
     
  7. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,268
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    That sounds too easy... lol
    But I still prefer to use hashtables.
    Maybe you should make an indexing system for items, could be quite useful. =p
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,032
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    It really is criminally too easy. Unit Indexers are really popular because of it. AutoIndex is probably the most famous, then AIDS would come next. Nestharus' Unit Indexer is probably the best of them all, but all three of those resources are made in vJass which is why I made GUI Unit Indexer.

    This won't use hashtables, it's a lot easier for a user to just get the custom value of a unit. It's also very important to be efficient with this (no hashtable attachment) because there might be hundreds of units being checked, and that can cause lag if I used hashtables.
     
  9. RehSinP

    RehSinP

    Joined:
    Dec 2, 2010
    Messages:
    16
    Resources:
    0
    Resources:
    0
    Make it say (Unit name) has moved and (Unit name) has stopped moving.
     
  10. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,032
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Make what say it? The demo map already says those things.
     
  11. Jazztastic

    Jazztastic

    Joined:
    Apr 4, 2011
    Messages:
    895
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    You should add something that detects when the unit is moving at a high speed or low speed (which could be changed easily by user, around 400 and 100 respecetively). It would be incredibly useful in spells. For example, a spell could give a unit a temporary boost of speed that decreases over time, but as long as it is above X movement speed, the unit is invisible. Something like that would make this system more desireable to have, to me at least.
     
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,032
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I could make an add-on to detect that, since speed of movement and the overall concept of movement are two seperate things.
     
  13. manasou

    manasou

    Joined:
    Apr 13, 2012
    Messages:
    101
    Resources:
    4
    Models:
    4
    Resources:
    4
    needed+5
     
  14. Aschy

    Aschy

    Joined:
    Jan 23, 2008
    Messages:
    269
    Resources:
    0
    Resources:
    0
    Thanks ya very much for this, it will be a great help!

    On a side note the trigger's guis is very clean, easy to understand, and works amazingly smooth.

    5/5
     
  15. Quilnez

    Quilnez

    Joined:
    Oct 12, 2011
    Messages:
    3,253
    Resources:
    37
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    2
    JASS:
    4
    Resources:
    37
    • Custom script: if udg_TempX != udg_UnitMovingX[udg_UDex] or udg_TempY != udg_UnitMovingY[udg_UDex] then

    Sir, may I suggest to also check for unit's current order?
    • Custom script: if udg_TempX != udg_UnitMovingX[udg_UDex] or udg_TempY != udg_UnitMovingY[udg_UDex] and GetUnitCurrentOrder(udg_UDexUnits[udg_UDex]) == OrderId("move") then
    And I think it's also possible to convert "smart" order to the actual order like "move", "attack", etc.


    That's all. Have a good day!
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,032
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    That will be much worse. A unit could still have an order and not be moving, or a unit could be moving and not have an order.
     
  17. Wrda

    Wrda

    Joined:
    Nov 18, 2012
    Messages:
    1,095
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Yes, but quilnez is right.
    First time I used your system and tested it, I checked if a unit tries moves to a point and then order it back would fire the event, and it did. Same thing as for patrol, attack, flags (shift-click). I really got disappointed for this "bug". A unit who is moving but stops moving because of an obstacle or because it received a new order doesn't mean he actually stopped moving. I think that should be fixed. Maybe make 3 events: 1 - stopped moving; 2 - stopped, but will still move; 3 - is moving
     
  18. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,032
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I am quite sure Nestharus' movement thing handles that, so you may want to look into his.
     
  19. matin45

    matin45

    Joined:
    Aug 13, 2018
    Messages:
    211
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Thanks for your help. It's so helpful.