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

[Trigger] Hashtables - Dummy Movement

Status
Not open for further replies.
Level 17
Joined
Jun 17, 2010
Messages
2,275
I made the game display checks to see where the trigger was at a given interval and everything leads to the correct spot but the other actions dont seem to be working and i cant quite find the error since this is my first time using hashtables.

  • Decieve Break
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) has buff Decieve ) Equal to True
    • Actions
      • Set Guise_Controller_Point = (Position of (Triggering unit))
      • Set Decieve_Target = (Triggering unit)
      • Set Decieve_Boolean = True
      • Unit - Create 1 Unit Controller for (Owner of (Attacking unit)) at Guise_Controller_Point facing Default building facing degrees
      • Unit - Remove (Attacking unit) from the game
      • Selection - Add (Last created unit) to selection
      • Set Decieve_Dummy = (Last created unit)
      • Custom script: set udg_Decieve_Key = GetHandleId(udg_Decieve_Target)
      • Hashtable - Save Handle OfDecieve_Dummy as 0 of Decieve_Key in Decieve_HashTable
      • Hashtable - Save Decieve_Boolean as 1 of Decieve_Key in Decieve_HashTable
      • Unit Group - Add Decieve_Dummy to Decieve_DummyGroup
      • Trigger - Turn on Dummy Movement <gen>
      • Custom script: call RemoveLocation(udg_Guise_Controller_Point)
  • Dummy Movement
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Game - Display to (All players) the text: Test: Check 5
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Decieve_DummyGroup is empty) Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: Test: Check 4
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Game - Display to (All players) the text: Test: Check 1
          • Unit Group - Pick every unit in Decieve_DummyGroup and do (Actions)
            • Loop - Actions
              • Set Decieve_Dummy = (Picked unit)
              • Hashtable - Save Handle OfGuise_Controller_Point as 2 of Decieve_Key in Decieve_HashTable
              • Set Decieve_Boolean = (Load 1 of Decieve_Key from Decieve_HashTable)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Decieve_Boolean Equal to False
                • Then - Actions
                  • Game - Display to (All players) the text: Test: Check 3
                  • Unit Group - Remove Decieve_Dummy from Decieve_DummyGroup
                  • Hashtable - Clear all child hashtables of child Decieve_Key in Decieve_HashTable
                • Else - Actions
                  • Game - Display to (All players) the text: Test: Check 2
                  • Set Guise_Controller_Point = (Load 2 of Decieve_Key in Decieve_HashTable)
                  • Unit - Move Decieve_Dummy instantly to Guise_Controller_Point
      • Custom script: call RemoveLocation(udg_Guise_Controller_Point)
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
Set Decieve_Dummy = (Picked unit)
Hashtable - Save Handle OfGuise_Controller_Point as 2 of Decieve_Key in Decieve_HashTable

Where's the "Handle OfGuise_Controller_Point" being set?
Where's the "Decieve_Key" being set?
 
Level 17
Joined
Jun 17, 2010
Messages
2,275
In this earlier trigger:

  • Decieve Break
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacking unit) has buff Decieve ) Equal to True
    • Actions
      • Set Guise_Controller_Point = (Position of (Triggering unit))
      • Set Decieve_Target = (Triggering unit)
      • Set Decieve_Boolean = True
      • Unit - Create 1 Unit Controller for (Owner of (Attacking unit)) at Guise_Controller_Point facing Default building facing degrees
      • Unit - Remove (Attacking unit) from the game
      • Selection - Add (Last created unit) to selection
      • Set Decieve_Dummy = (Last created unit)
      • Custom script: set udg_Decieve_Key = GetHandleId(udg_Decieve_Target)
      • Hashtable - Save Handle OfDecieve_Dummy as 0 of Decieve_Key in Decieve_HashTable
      • Hashtable - Save Decieve_Boolean as 1 of Decieve_Key in Decieve_HashTable
      • Unit Group - Add Decieve_Dummy to Decieve_DummyGroup
      • Trigger - Turn on Dummy Movement <gen>
      • Custom script: call RemoveLocation(udg_Guise_Controller_Point)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
But the value of those variables would change every time the unit is attacked. You should save everything within the hashtable and work only with the hash, and forget about pre-set variables, otherwise, they would be set again during the periodic trigger, messing everything up.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Then set Point = Position of (Picked Unit) in the periodic trigger, instead of setting it in the first trigger, then move the dummy towards it using polar offset. That's the best way to follow unit.

What do you exactly want to achieve? It's hard to help without knowing what you want. If you want a dummy follow, then save the handle of the dummy on it's target, add the target to a UnitGroup, periodically load the handle of the dummy from the picked unit and set it's position to (offset *distance* every *0.03* towards *Picked Unit*), checking constantly if the unit group is empty, and then if the Picked Unit is alive, else, remove the unit from the unit group, kill the dummy (or remove it), and turn off the trigger.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
When i said POINT i was refering to the positión of the unit you want the dummy to move towards to. Set "Point" = "Position of Unit" :)

Also, try to explain a bit better your intention :p
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Let me quote myself.

If you want a dummy follow, then save the handle of the dummy on it's target, add the target to a UnitGroup, periodically load the handle of the dummy from the picked unit and set it's position to (offset *distance* every *0.03* towards *Picked Unit*), checking constantly if the unit group is empty, and then if the Picked Unit is alive, else, remove the unit from the unit group, kill the dummy (or remove it), and turn off the trigger....

Hashtable - Save Unit Handle
-> Save handle of (Last created unit) as 0 of (Id of Target Unit) in Hashtable

To move it.
-> Set Dummy = Load 0 of (Id of Picked Unit) in Hashtable
-> Set Point = Position of Dummy Unit with offset ## towards (Picked Unit).
 
Instead of:
  • Hashtable - Save Decieve_Boolean as 1 of Decieve_Key in Decieve_HashTable
you can go with
  • Custom script: call SaveBoolean( udg_Decieve_HashTable, Decieve_Key , 1, Decieve_Boolean )
It maybe make no sense now, but it's 1 function call less and check this:
 

Attachments

  • Capture.JPG
    Capture.JPG
    25.9 KB · Views: 84
Level 20
Joined
Jul 14, 2011
Messages
3,213
We create the Hashtable
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Hash = (Last created hashtable)

We take the Id of the Triggering Unit (Damaged unit, Attacked Unit, etc.) and save it in the Dummy's Id. We add the Dummy to the Unit Group. We also add Locust to the dummy to make it invulnerable/unpickable/unselectable.
  • TriggerSet
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Taunt
    • Actions
      • Set Point1 = (Random point in (Playable map area))
      • Unit - Create 1 Footman for Player 1 (Red) at Point1 facing Default building facing degrees
      • Custom script: set udg_Id = GetHandleId(bj_lastCreatedUnit)
      • Unit Group - Add (Last created unit) to UnitGroup
      • Custom script: call UnitAddAbility(bj_lastCreatedUnit, 'Aloc')
      • Hashtable - Save Handle Of(Triggering unit) as 0 of Id in Hash
      • Trigger - Turn on Periodic <gen>
Now we pick all dummies and we move them towards the position of the target unit. The target unit is loaded from the dummy unit Id.

  • Periodic
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • -------- Is the Group Empty? No? Go on. ¿Yes? Turn off trigger. --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (UnitGroup is empty) Equal to False
        • Then - Actions
          • Unit Group - Pick every unit in UnitGroup and do (Actions)
            • Loop - Actions
              • Custom script: set udg_Id = GetHandleId(GetEnumUnit())
              • Set Unit1 = (Load 0 of Id in Hash)
              • -------- Is the target unit alive? Yes? Go on. ¿No? Kill the Dummy and remove it from the group. --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit1 is alive) Equal to True
                • Then - Actions
                  • Set Point1 = (Position of Unit1)
                  • Set Point2 = (Position of (Picked unit))
                  • Set Point3 = (Point2 offset by 5.00 towards (Angle from Point2 to Point1) degrees)
                  • -------- The Dummy is really near to its target? Yes? Go on. ¿No? Move the dummy towards target. --------
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Distance between Point1 and Point2) Less than or equal to 10.00
                    • Then - Actions
                      • -------- Do damage, special effects, etc. Also Kill/remove the dummy --------
                    • Else - Actions
                      • Unit - Move (Picked unit) instantly to Point3
                  • -------- Leak Cleaning --------
                  • Custom script: call RemoveLocation(udg_Point1)
                  • Custom script: call RemoveLocation(udg_Point2)
                  • Custom script: call RemoveLocation(udg_Point3)
                • Else - Actions
                  • Unit - Kill (Picked unit)
                  • Unit Group - Remove (Picked unit) from UnitGroup
        • Else - Actions
          • Trigger - Turn off (This trigger)
There you go.

It Can (Should) be Improved A LOT with better use of variables and stuff. It can improved even more (really, a lot more) by making it in jass (Convert to custom text and replace bj's doing the functions manually).
 

Attachments

  • Dummy Movement.w3x
    16.7 KB · Views: 46
Level 17
Joined
Jun 17, 2010
Messages
2,275
Sigh, i want to move 1 dummy unit to its corresponding target unit, not every dummy unit to 1 target unit. Thats the problem! if i wanted to move all the dummy units to 1 unit i wouldnt bother with hash tables, im trying to make 1 dummy glued to 1 target, and make it work for multiple unit instances. And i cant use Locust ability because it has to be selectable!

So you can understand heres the map:
 

Attachments

  • Deceive - InfinateAnswers Final WiP.w3x
    32.9 KB · Views: 40
Level 20
Joined
Jul 14, 2011
Messages
3,213
Well, take my triggers, remove the "call UnitAddAbility" custom script (to remove Locust) and forget about the rest. You'll have every dummy following it's target, of course, based on your event/condition. In mine i used taunt as example (Unit starts the effect of an ability). You can change it for "A unit is attacked" and add the conditions, and it will work exactly the same.

I already added the instances to check if the Target is alive, if the dummy reaches the target, and if the unit group is empty.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
That was the idea. You have to take my triggers as a guide, and just add the rest of stuff you need, but the basics are there.
 
Status
Not open for further replies.
Top