IsUnitMoving Simple [GUI] v. 1.0

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
Pros :
-Pretty much simplified and easy to understand
-Can Use any UnitIndexer or just use Different UserData for each Unit
-GUI
Cons:
- I Guess its Inacurate
Function
- Detects if a unit is moving or not. This works for any
type of movement (natural, through triggers, etc.)
Boolean Applied =
  • UnitMoving[(Custom value of (Triggering unit))] Equal to true
Installation
Copy and paste the IsUnitMoving Trigger from the map.
Copy and paste the UIM Vars Needed Trigger from the map.
Done!
v1
  • IsUnitMoving
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • -------- You May Configure the Time Interval above --------
      • -------- ------------------------------------ --------
      • -------- Simplified IsUnitMoving --------
      • -------- w/out All Test Func and Comment lines --------
      • -------- -Have 33 lines --------
      • -------- GUI Friendly --------
      • -------- ------------------------------------ --------
      • -------- Requires --------
      • -------- Any Unit Indexer --------
      • -------- or Different UserData of Each Unit --------
      • Set UnitMoveGroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • -------- You May Add Conditions To Fit to your system.. --------
          • -------- else remove --------
          • Custom script: local integer i = GetUnitUserData(GetEnumUnit())
          • Custom script: if not udg_IUMAdded[i] then
          • Custom script: set udg_UnitMovingX[i] = GetUnitX(GetEnumUnit())
          • Custom script: set udg_UnitMovingY[i] = GetUnitY(GetEnumUnit())
          • Custom script: set udg_IUMAdded[i] = true
          • Custom script: else
          • Custom script: if GetUnitMoveSpeed(GetEnumUnit()) > 0 then
          • Custom script: if GetUnitX(GetEnumUnit()) != udg_UnitMovingX[i] and GetUnitY(GetEnumUnit()) != udg_UnitMovingY[i] then
          • Custom script: set udg_UnitMoving[i] = true
          • Custom script: set udg_UnitMovingX[i] = GetUnitX(GetEnumUnit())
          • Custom script: set udg_UnitMovingY[i] = GetUnitY(GetEnumUnit())
          • Custom script: else
          • Custom script: set udg_UnitMoving[i] = false
          • Custom script: endif
          • Custom script: endif
          • Custom script: endif
          • -------- TEST --------
          • -------- You may remove once done testing --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is selected by Player 1 (Red)) Equal to True
            • Then - Actions
              • Cinematic - Clear the screen of text messages for (All players)
              • Game - Display to (All players) the text: (Index = + (String((Custom value of (Picked unit)))))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • UnitMoving[(Custom value of (Picked unit))] Equal to True
                • Then - Actions
                  • Game - Display to (All players) the text: Unit is Moving
                • Else - Actions
                  • Game - Display to (All players) the text: Unit is Not Moving
              • Game - Display to (All players) the text: ((Name of (Picked unit)) + ( MoveSpeed = + (String((Current movement speed of (Picked unit))))))
              • Game - Display to (All players) the text: -Speed ### to Chang...
            • Else - Actions
      • Custom script: call DestroyGroup(udg_UnitMoveGroup)
v2
  • IsUnitMoving2
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- This Version Doesnt Need Two Other Vars --------
      • -------- udg_IUMAdded --------
      • -------- udg_UnitMoveGroup --------
      • -------- ------------------------------------ --------
      • -------- Simplified IsUnitMoving --------
      • -------- GUI Friendly --------
      • -------- ------------------------------------ --------
      • -------- Requires --------
      • -------- Any Unit Indexer --------
      • -------- or Different UserData of Each Unit --------
      • Custom script: call ExecuteFunc("Core")
      • Custom script: endfunction
      • -------- ------------------------------------ --------
      • Custom script: function TimeInterval takes nothing returns real
      • Custom script: return 0.02
      • Custom script: endfunction
      • -------- You May Configure the Time Interval above --------
      • -------- ------------------------------------ --------
      • Custom script: function Start takes nothing returns nothing
      • Custom script: local integer i = GetUnitUserData(GetEnumUnit())
      • Custom script: set udg_UnitMovingX[i] = GetUnitX(GetEnumUnit())
      • Custom script: set udg_UnitMovingY[i] = GetUnitY(GetEnumUnit())
      • Custom script: endfunction
      • -------- ------------------------------------ --------
      • Custom script: function MainG takes nothing returns nothing
      • Custom script: local integer i = GetUnitUserData(GetEnumUnit())
      • -------- You May Add Conditions To Fit to your system.. --------
      • -------- else remove --------
      • Custom script: if GetUnitMoveSpeed(GetEnumUnit()) > 0 then
      • Custom script: if GetUnitX(GetEnumUnit()) != udg_UnitMovingX[i] and GetUnitY(GetEnumUnit()) != udg_UnitMovingY[i] then
      • Custom script: set udg_UnitMoving[i] = true
      • Custom script: set udg_UnitMovingX[i] = GetUnitX(GetEnumUnit())
      • Custom script: set udg_UnitMovingY[i] = GetUnitY(GetEnumUnit())
      • Custom script: else
      • Custom script: set udg_UnitMoving[i] = false
      • Custom script: endif
      • Custom script: endif
      • -------- TEST --------
      • -------- You may remove once done testing --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Picked unit) is selected by Player 1 (Red)) Equal to True
        • Then - Actions
          • Cinematic - Clear the screen of text messages for (All players)
          • Game - Display to (All players) the text: (Index = + (String((Custom value of (Picked unit)))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • UnitMoving[(Custom value of (Picked unit))] Equal to True
            • Then - Actions
              • Game - Display to (All players) the text: Unit is Moving
            • Else - Actions
              • Game - Display to (All players) the text: Unit is Not Moving
          • Game - Display to (All players) the text: ((Name of (Picked unit)) + ( MoveSpeed = + (String((Current movement speed of (Picked unit))))))
          • Game - Display to (All players) the text: -Speed ### to Chang...
        • Else - Actions
      • Custom script: endfunction
      • -------- ------------------------------------ --------
      • Custom script: function Main takes nothing returns nothing
      • Custom script: local group g = GetUnitsInRectAll(GetPlayableMapRect())
      • Custom script: call ForGroup(g, function MainG)
      • Custom script: call DestroyGroup(g)
      • Custom script: set g = null
      • Custom script: endfunction
      • -------- ------------------------------------ --------
      • Custom script: function Core takes nothing returns nothing
      • Custom script: local group g = GetUnitsInRectAll(GetPlayableMapRect())
      • Custom script: local trigger t = CreateTrigger()
      • Custom script: call ForGroup(g, function Start)
      • Custom script: call TriggerRegisterTimerEventPeriodic( t, TimeInterval() )
      • Custom script: call TriggerAddAction( t, function Main )
      • Custom script: call DestroyGroup(g)
      • Custom script: set t = null
      • Custom script: set g = null
= ChangeLog =
v1.0
- first
v1.1
- Fixed group leak
- Fixed first false iteration
- Added another version

Keywords:
Move,Moving,IsUnit,System,GUI,Simple
Contents

test (Map)

Reviews
18th Apr 2016 Your resource has been reviewed by BPower. In case of any questions or for reconfirming the moderator's rating, please make use of the Quick Reply function of this thread. Review: An inefficient re-make of an already existing...

Moderator

M

Moderator

18th Apr 2016

General Info

Your resource has been reviewed by BPower.
In case of any questions or for reconfirming the moderator's rating,
please make use of the Quick Reply function of this thread.
Review:

An inefficient re-make of an already existing resource ( Is Unit Moving ).
The term in such a case is Reinventing the wheel.
You can check out comment #5 and #6 for more detailed information.

I tend to reject this submission. For now Need Fix.

Troubleshooting:

  • There is a group handle leak in your code.
    ---
  • There is a periodically occuring rect handle ID leak, because GetUnitsInRectAll is badly implemented into GUI.
    That was the fault of the Blizzard coding team in charge. :/
    ---
  • A false positive result on the first iteration.

Review changelog:
  1. -
 
Level 38
Joined
Sep 26, 2009
Messages
8,477
0.03 seconds is slower than movement systems based on 0.03125 periodic movement or higher. In fact, the 0.05 I use in IsUnitMoving is already lower than necessary and could have been set to 0.10 for better performance.

The reason the events of the indexer are used is to capture valid units into an iterable list. This is the fastest way to iterate all units. Systems which rely on fast timers which never stop should eliminate all possible overhead. Opening a new thread for each unit is devestating and will cause far more overhead than adding a couple of variables to store the prev/next unit ID's.

The events to detect when a unit stops or starts moving can be disabled by the importing user if undesired. The performance difference is, however, negligible as a unit doesn't start and stop moving every interval and will therefore never tax the system.

You're leaking a unit group.
 
Level 38
Joined
Sep 26, 2009
Messages
8,477
This still uses dynamic groups and still opens up a new thread for each unit on the map. It also doesn't work with Locust units due to the nature of GroupEnumUnits...

The biggest technical problem right now is the function GetUnitsInRectAll which leaks handle ID's each time it is called.

I don't understand your motivation in making this resource. What about the existing IsUnitMoving resource is so deterring for you to embrace it?
 

Chaosy

Tutorial Reviewer
Level 39
Joined
Jun 9, 2011
Messages
13,110
Is this really such a large downgrade? I mean it could use some tweaking like using a variable for GetEnumUnit() and fixing leaks, but otherwise is there really a performance difference?
Should be approved if changes are made (if I were in charge, but I aint) but I still don't know if it'll benefit others that much since there is another one.
Maybe if he used another indexing method which doesn't force you to use a unit indexer.
 
Top