• 🏆 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!

[Spell] Moving multiple units towards a central location

Status
Not open for further replies.
Level 2
Joined
Jun 20, 2021
Messages
5
Hi there!

Im having trouble creating a spell, that is pulling nearby enemies towards a central location.

I'm using two triggers to achieve this effect:

  • Gravitational Rift
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Gravitational Rift (Void Mage)
    • Actions
      • Set VariableSet endPoint = (Target point of ability being cast)
      • Set VariableSet tempReal = (1.60 + (0.40 x (Real((Level of Gravitational Rift (Void Mage) for (Triggering unit))))))
      • Set VariableSet tempDmg = ((15.00 + (5.00 x (Real((Level of Gravitational Rift (Void Mage) for (Triggering unit)))))) + (0.50 x (Real((Intelligence of (Triggering unit) (Include bonuses))))))
      • Special Effect - Create a special effect at endPoint using war3mapImported\Void Disc.mdx
      • Hashtable - Save Handle OfendPoint as 50 of (Key (Triggering unit).) in missileTable.
      • Hashtable - Save tempReal as 51 of (Key (Triggering unit).) in missileTable.
      • Hashtable - Save tempDmg as 52 of (Key (Triggering unit).) in missileTable.
      • Hashtable - Save Handle Of(Last created special effect) as 53 of (Key (Triggering unit).) in missileTable.
      • Unit Group - Add (Triggering unit) to riftCasters
      • Trigger - Turn on Gravitational Rift Loop <gen>
The first trigger is simply for initialization on spell cast and sets up some values I need for later processing.

  • Gravitational Rift Loop
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in riftCasters and do (Actions)
        • Loop - Actions
          • Set VariableSet tempUnit = (Picked unit)
          • Set VariableSet tempPoint = (Load 50 of (Key (Picked unit).) in missileTable.)
          • Set VariableSet tempReal = (Load 51 of (Key (Picked unit).) from missileTable.)
          • Set VariableSet tempDmg = (Load 52 of (Key (Picked unit).) from missileTable.)
          • Set VariableSet tempEffect = (Load 53 of (Key (Picked unit).) in missileTable.)
          • Set VariableSet tempReal = (tempReal - 0.10)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempReal Greater than 0.00
            • Then - Actions
              • Hashtable - Save tempReal as 51 of (Key (Picked unit).) in missileTable.
              • Set VariableSet tempGroup = (Units within 400.00 of tempPoint matching ((((Matching unit) is alive) Equal to Wahr) and ((((Matching unit) belongs to an enemy of (Owner of (Picked unit)).) Equal to Wahr) and (((Matching unit) is in projectiles.) Equal to Falsch))).)
              • Unit Group - Pick every unit in tempGroup and do (Actions)
                • Loop - Actions
                  • Set VariableSet startPoint = (Position of (Picked unit))
                  • Set VariableSet endPoint = (startPoint offset by 10.00 towards (Angle from startPoint to tempPoint) degrees.)
                  • Unit - Move (Picked unit) instantly to endPoint
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Distance between tempPoint and endPoint) Less than or equal to 250.00
                    • Then - Actions
                      • Unit - Cause tempUnit to damage (Picked unit), dealing (tempDmg / 10.00) damage of attack type Spells and damage type Magic
                    • Else - Actions
                  • Custom script: call RemoveLocation(udg_startPoint)
                  • Custom script: call RemoveLocation(udg_endPoint)
              • Custom script: call DestroyGroup(udg_tempGroup)
            • Else - Actions
              • Unit Group - Remove (Picked unit) from riftCasters.
              • Special Effect - Destroy tempEffect
              • Custom script: call RemoveLocation(udg_tempPoint)
              • Custom script: call ClearSubTable(udg_missileTable, GetHandleIdBJ(GetEnumUnit()), 50, 53)
              • If ((Number of units in riftCasters) Equal to 0) then do (Trigger - Turn off (This trigger)) else do (Do nothing)
This second trigger should pick all enemy units within 400 of the central point of the ability and move them towards the center. In reality though, only one unit that is affected gets pulled towards the center while each other unit affected gets moved in seemingly random directions.

Does anyone have an idea why that may happen? Let me know, if I can provide additional information, that might be helpful in solving this.
 
Level 24
Joined
Feb 9, 2009
Messages
1,787
1625839675196.png
Filtering unit groups via this to tutorial will improve readability and fix some bugs.

If you need to save a point consider saving an effect and referring to its X & Y as i'm assuming trying to refer the original cast point and then clearing it for leaks results in it not working right?

I'd highly recommend dropping hashtables and trying out dynamic indexing.
I made a spell similar to yours that you can refer to if you want to see how it can be done.
 
Status
Not open for further replies.
Top