• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Detect and Count Unit Movement

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
So as the title says. How can I detect and count a unit's movement? I think the best data to
collect is the distance the unit has moved. The number of move orders isn't going to work.

Also, I need to know how to create an event from this. For example, once the unit has moved a
random distance between X and Y, actions will occur. Then I can reset the movement counter.
Is this possible at all and in GUI?
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Through further research, I have found this thread:

http://www.hiveworkshop.com/forums/triggers-scripts-269/how-make-distance-storing-not-leak-233477/

I can count the distance now.

  • Game - WalkAmount becomes Greater than or equal to (Random real number between 1000.00 and 2000.00)
I use this event to detect how far I have travelled. "WalksAmount" being the variable used to store my distance.

I have two problems though:

1.) My "Walk Amount" distance always starts at 1240.
2.) The event always seems to trigger at about 1930. I DO NOT have "Fixed Random Seed" checked within preferences.

Any help please?
 
Last edited:
Level 16
Joined
Mar 27, 2011
Messages
1,349
Ok. Fixed the first problem by setting WalkPoint2 at map initialization. Now, the Walkamount correctly starts at 0. But, the trigger still seems to fire at 1930. Its not random for some reason. Here are my Triggers:

  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set WalkPoint2 = (Position of Footman 0002 <gen>)
  • Count Distance
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set WalkPoint1 = WalkPoint2
      • Set WalkPoint2 = (Position of Footman 0002 <gen>)
      • Set WalkAmount = (WalkAmount + (Distance between WalkPoint1 and WalkPoint2))
      • Custom script: call RemoveLocation (udg_WalkPoint1)
      • Custom script: set udg_WalkPoint1=null
      • Game - Display to (All players) for 2.00 seconds the text: (String(WalkAmount))
  • Encounter
    • Events
      • Game - WalkAmount becomes Greater than or equal to (Random real number between 1000.00 and 2000.00)
    • Conditions
    • Actions
      • Game - Display to (All players) for 5.00 seconds the text: Enemy!
      • Game - Display to (All players) for 5.00 seconds the text: (String(WalkAmount))
      • Set WalkAmount = 0.00
The Text messages are for testing purposes only.

Edit: It seems each time I test the map, the trigger fires at different WalkAmount numbers. Its as if its randomly picked for that game, and your stuck with that random number for the whole game. It does not generate a new number each time it triggers, but rather each time you play the game.
 
Last edited:
Level 5
Joined
May 6, 2013
Messages
125
native TriggerRegisterVariableEvent takes trigger whichTrigger, string varName, limitop opcode, real limitval returns event

You bind a variable by the name of varName to the real by the name of limitval. You expected it to bind the variable to the function (random value between x and y), when in fact you bind your variable to the real resulting from this function, causing the threshold to be set once at map initialization. While the real resulting from the function varies between the games, the threshold will not change once the trigger was created, resulting in your observations.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
It does not get a random number every time it is fired.

How can I get a new number every time it is fired?

if u want it to be random use an ITE in the actions. in the event use greater than 1000 or something like that.

  • Encounter
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WalkAmount Greater than or equal to (Random real number between 1000.00 and 2000.00)
        • Then - Actions
          • Game - Display to (All players) for 5.00 seconds the text: Enemy!
          • Game - Display to (All players) for 5.00 seconds the text: (String(WalkAmount))
          • Set WalkAmount = 0.00
        • Else - Actions
You going to need to elaborate. This didn't work for me either. I don't understand Imp's explanation, so I'm not really sure what the problem is here.
 
Use this as the event.
  • Game - WalkAmount becomes Greater than or equal to 1000.00
You should also set the random value to a value then change the value in the then block of the ITE to a new random value.

@poke
Read the thread before posting....


Edit:
  • Encounter
    • Events
      • Game - WalkAmount becomes Greater than or equal to 1000.00
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WalkAmount Greater than or equal to WalkRandomReal
        • Then - Actions
          • Game - Display to (All players) for 5.00 seconds the text: Enemy!
          • Game - Display to (All players) for 5.00 seconds the text: (String(WalkAmount))
          • Set WalkAmount = 0.00
          • Set WalkRandomReal = (Random real number between 1000.00 and 2000.00)
        • Else - Actions
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
After every time it fires you could destroy and recreate the trigger. This lets you attach a new event to it and gets rid of the old one.

I am pretty sure it would be easier to check the value yourself every time you update it. This way you can use a variable to represent the amount needed and that can be updated every time the limit is reached.
 
I am pretty sure it would be easier to check the value yourself every time you update it. This way you can use a variable to represent the amount needed and that can be updated every time the limit is reached.

That is also true he can move this whole ITE in my above post into the trigger that sets the movement distance.
 
Status
Not open for further replies.
Top