• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Detecting Amount Traveled

Status
Not open for further replies.
Level 7
Joined
Apr 21, 2011
Messages
93
So I'm wondering, is it possible to detect the amount traveled by a unit, and if so, to what extent is it possible to interact with the detected value?

For example, I think I remember in DotA, there was an ability that dealt increased damage if the projectile struck further away from its initial point. I'm not looking for exactly that, I need something less linear.

I'm looking for something that works if a unit moves to a location around an object, anything that would work - not with distance from point A to point B, but the actual distance traveled.

I thought of a possible alternative as well, if it would be possible to just time the units as they move. The situation where I need the mechanic would feature units with the same movement speed and each unit individually, so timing is also a possibility.

Also, a second alternative could use dummy units and proximity for detecting the distance traveled but when creating an event trigger, strings such as "position of unit" only work for the initial positions of units the instant the map initializes.
I'm quite familiar with the trigger editor, but I haven't got the slightest amount of skill with the custom scripts, so if there's a way around it using some sort of script It'd make me a very happy possum ^^

Thanks in advance!
 
Well it's quite simple really, after all the standard spell stuff, setting up arrays and blah (or hashtable if that's what you're using) you can save its starting location then in a looping trigger you load the value and then set another one to its current position, then you calculate the distance between them which will return a real value and add this to the value already stored in a real variable (Formula being RealVal = RealVal + Distance between points (TempPoint, TempPoint2)

This could similarly be done with co-ordinates but you get the general idea I'll post an example trigger in a second


  • Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Example
    • Actions
      • Set MaxIndex = (MaxIndex + 1)
      • Set TempUnit[MaxIndex] = (Triggering unit)
      • Set CurrentPoint[MaxIndex] = (Position of TempUnit[MaxIndex])
      • Set DistTravelled[MaxIndex] = 0.00
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MaxIndex Equal to 1
        • Then - Actions
          • Trigger - Turn on Loop <gen>
        • Else - Actions
  • Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer CurrentIndex) from 1 to MaxIndex, do (Actions)
        • Loop - Actions
          • Set TempPoint = (Position of TempUnit[CurrentIndex])
          • Set DistTravelled[CurrentIndex] = DistTravelled[CurrentIndex] + Distance Between (TempPoint) and (CurrentPoint[CurrentIndex])
          • Custom script: call RemoveLocation (udg_CurrentPoint[udg_CurrentIndex])
          • Set CurrentPoint[CurrentIndex] = TempPoint
          • Custom script: call RemoveLocation(udg_TempPoint)


That'd be the sort of thing you'd be going for (ofc I left out the recycling bit since I don't know when you'd want the tracking/instance to end if ever)
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I think you should use the http://www.hiveworkshop.com/forums/...-199189/?prev=search=IsUnitMoving&d=list&r=20 system to cope with this situation.
When unit moves (detected by the system), add whatever value you want to add, let's say we call is as DistanceTravelled (Real/Integer variable).

After that, you would do something about that variable DistanceTravelled as in, damage the unit based on the calculation, etc etc.
 
Status
Not open for further replies.
Top