1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. The long-awaited results for Concept Art Contest #11 have finally been released!
    Dismiss Notice
  3. Join Texturing Contest #30 now in a legendary battle of mythological creatures!
    Dismiss Notice
  4. The Aftermath has been revealed for the 19th Terraining Contest! Be sure to check out the Results and see what came out of it.
    Dismiss Notice
  5. Hivers united and created a bunch of 2v2 melee maps. Vote for the best in our Melee Mapping Contest #4 - Poll!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice

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. 20:09, 31st Jul 2011
    Maker: Approved. Does what it is supposed to, and does it well.
     
  2. Bannar

    Bannar

    Joined:
    Mar 19, 2008
    Messages:
    3,086
    Resources:
    20
    Spells:
    5
    Tutorials:
    1
    JASS:
    14
    Resources:
    20
    Ha :D I see you finaly uploaded this. Great job, GUI gets more and more of good stuff.
    5/5 Bride, hope you end your LuckyPerser soon, good luck.
    It is much simpler while using your indexing system, than creating it by own without it (I guess you know what I mean). =)
     
  3. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Nice :)
    You've inspired me to rewrite some of my libraries in GUI so that GUIers can use them too :D
    5/5
     
  4. Jazztastic

    Jazztastic

    Joined:
    Apr 4, 2011
    Messages:
    895
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    Holy fucking shit. Does this basically add a new boolean to the game? And an incredibly useful one at that?

    I can already see the wave of rupture spells coming now.
     
  5. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,772
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Thanks for the positive feedback. This is based on Xiliger's
    idea here: http://www.hiveworkshop.com/forums/graveyard-418/isunitmoving-159724/

    I made a number of improvements that I published here:
    http://www.hiveworkshop.com/forums/jass-functions-413/system-unit-moving-178341/

    That vJass version has extra features like "on move" or "on
    stop" events and is a bit more efficient. This version I've
    created so that it's easy to pop into a map and start using
    right away, as a lot of PC's and (every) Macintosh have
    problems running JNGP.
     
  6. Jazztastic

    Jazztastic

    Joined:
    Apr 4, 2011
    Messages:
    895
    Resources:
    7
    Spells:
    6
    Tutorials:
    1
    Resources:
    7
    Well I'm pretty sure I can speak for the entire GUI community when I say that having powerful resources like these available for GUI usage is amazing. I'm just getting ready for the tidal wave of spells when people realize how easy spellmaking is with your two new GUI resources :)

    Amazing job sir. Well done
     
  7. Tiche3

    Tiche3

    Joined:
    Jun 25, 2009
    Messages:
    432
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Yeah, rupture like spells rock! :D http://www.hiveworkshop.com/forums/spells-569/hives-spellpack-v2-1b-183097/ if you like rupture spell, then search for it in this pack ;) sorry for promoting tho.

    On the topic: This system is awesome since some spells require this. I wouldn't like to dissapoint you but for me (only me, it's only a personal opinion, don't get mad :p) it's not hard to create for a spell. BUT it's a waste of memory for each single spell to create a new system such as this. I mean 5 triggers running each 0.04 seconds for different spells while with this it can be only one, running at 0.03 ;)

    Off the topic: Bribe, I have sent you a personal message but i don't know whether you got it or not. So please, please re-review my spellpack :(

    Tiche3
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,772
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    This is not meant to replace periodic triggers. It is
    meant to provide detection to determine if a unit is
    moving or stopped.

    Something like this would actually be quite annoying
    and innefficient to try to code without the GUI Unit
    Indexer system. This is also really easy to use since
    the user can do everything he/she needs without any
    custom script.
     
    Last edited: Jul 11, 2011
  9. Bannar

    Bannar

    Joined:
    Mar 19, 2008
    Messages:
    3,086
    Resources:
    20
    Spells:
    5
    Tutorials:
    1
    JASS:
    14
    Resources:
    20
    You are right, since detecting movement isn't mystery but in GUI it fails if we talk about efficiency and for sure having Indexer saves much time.
     
  10. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,772
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Updated to 1.0.0.1 to make installation a bit easier,
    and optimized the code slightly.

    Basically, if GUI Unit Indexer is in the map, copy and
    paste this trigger into your map and the thing is
    installed. I don't think it can get any easier than this.
     
  11. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    Does this auto-add units into the system, meaning all units in the map are checked every 0.05 seconds. If so, what if you want to use it for heroes only for example?
     
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,772
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Old Post
    Right now it checks all units that are indexed by GUI Unit Indexer.

    If you wanted to index only certain types of units, I can make this
    use its own list that has its own filtering. In fact, that's probably a
    good idea to do so. I'll keep that in mind next time I have a chance
    to update this thing.


    Updated to version 2.0.0.0. This update requires the latest GUI Unit Indexer
    to work with its new features.

    New features:

    Now has "OnMove" and "OnStop" events.
    Now runs on its own list, so you can filter out units you don't need to check.

    • Unit Moving Events
      • Events
        • -------- When a unit starts moving: --------
        • Game - UnitMovingEvent becomes Equal to 1.00
        • -------- When a unit stops moving: --------
        • Game - UnitMovingEvent becomes Equal to 2.00
      • Conditions
      • Actions
        • -------- UDexUnits[UDex] refers to the moving/stopped unit --------
     
    Last edited: Jul 24, 2011
  13. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Nice :D
    You should warn GUIers that they can't use Vexorian's optimizer though :/
     
  14. cr4ck4r

    cr4ck4r

    Joined:
    Jul 22, 2010
    Messages:
    70
    Resources:
    2
    Maps:
    1
    Spells:
    1
    Resources:
    2
    and why? reason?
     
  15. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Because he's using
    TriggerRegisterVariableEvent
    ?
    It requires the name of the variable as a string, so if you optimize the map, it would change the name of the variable and ruin your
    TriggerRegisterVariableEvent
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,772
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I'm not going to require mention of Vex's fail optimizer when these are working, native properties of World Editor that are only "broken" because of his fail design. I will not "apologize" for his mistakes.
     
  17. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Stick it to the man! :p

    Well, you know, you should at least tell them their map will be unplayable if they optimize it and THEN, you could blame Vex :p
    That way, you wouldn't get lots of people complaining in the WEHZ about their unplayable maps :/

    Come on :p
     
  18. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,772
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Most of the GUI populace won't be using the "shorten names" feature of the optimizer as it requires knowledge of common.j and blizzard.j, let alone be using the optimizer itself.

    Rather than requiring innocent scripts like this to mention such a thing, the guy who built a buggy program should be the only one who has to give warnings for malfunctions.

    Weep's GUI Damage Detection System has always used this event and no one has complained. Using the event for these libraries is just another page in the story.
     
  19. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    You're right :)