• 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.

[Trigger] hashtable issues

Level 9
Joined
Dec 1, 2010
Messages
346
The following is a part of my trigger.
I'm trying to add in a check in my trade ports system where A [Homeport] and a [destination port] can not be in the same tradenode (region based system).

I have two hashtables with the following structure:
Hashtable [3`]

Slot 0 = Unit ID
Slot 1 = handle of homeport
Slot 2 = Handle of target tradepoint
Slot 3 = Current order integer (0 = No order, 1 = Deliver cargo to target, 2 = Return to homeport)
slot 4 = Player number [owner]

Hashtable [1`]

Slot1 = ID
Slott2: Unit type
Slot 3 = Tradenode number
slot 4 = Gold cost
slot 5 = wood cost
slot 6 =

  • Then - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • And - All (Conditions) are true
          • Conditions
            • (Unit-type of (Target unit of ability being cast)) Equal to Trade Port
            • (Key (Load 3 of (Key (Target unit of ability being cast).) in hashtable[1].).) Not equal to (Load 3 of (Key (Load 1 of (Key (Casting unit).) in hashtable[3].).) from hashtable[1].)
      • Then - Actions
        • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Key (Casting unit).) from hashtable[1].)))
        • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Load 1 of (Key (Casting unit).) from hashtable[3].) from hashtable[1].)))
        • Hashtable - Save Handle Of(Target unit of ability being cast) as 2 of (Key (Casting unit).) in hashtable[3].
        • Game - Display to (Player group((Owner of (Casting unit)))) the text: Set |cff00ffffdesti...
      • Else - Actions
        • Game - Display to (Player group((Owner of (Casting unit)))) the text: Target a trade post...
When testing to this check i've added two tradeports in the same node. however the check isn't firing so i added
  • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Key (Casting unit).) from hashtable[1].)))
  • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Load 1 of (Key (Casting unit).) from hashtable[3].) from hashtable[1].)))
Both ports are in tradenode 1. i have a seperate check that shows that they are in the correct node ingame
  • Untitled Trigger 003 Copy
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set VariableSet tempPos = (Position of (Picked unit))
          • Floating Text - Create floating text that reads (String((Load 3 of (Key (Picked unit).) from hashtable[1].))) at tempPos with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
          • Floating Text - Change (Last created floating text): Disable permanence
          • Floating Text - Change the lifespan of (Last created floating text) to 0.10 seconds
          • Custom script: call RemoveLocation(udg_tempPos)
This check displays a 1 above both ports. meaning they're correctly set to the right node.
  • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Load 1 of (Key (Casting unit).) from hashtable[3].) from hashtable[1].)))
However the following code gives me a 0. While it should give a 1 if it was properly reading the trade node. This is also probably the reason that
  • (Key (Load 3 of (Key (Target unit of ability being cast).) in hashtable[1].).) Not equal to (Load 3 of (Key (Load 1 of (Key (Casting unit).) in hashtable[3].).) from hashtable[1].)
fails to filter out the same port


Am i misunderstanding something about how hashtables are supposed to work?


 
Level 9
Joined
Dec 1, 2010
Messages
346
Is this handle stored and loaded correctly? 1 of (Key(Casting unit)) from Hashtable[3].
  • Set home port
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
    • Actions
      • -------- Add to transport ship unit group --------
      • -------- Add conditions to or IF adding levels to transportship --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of (Casting unit)) Equal to Transport Ship
        • Then - Actions
          • Unit Group - Add (Casting unit) to transportShips[(Player number of (Owner of (Casting unit)))]
        • Else - Actions
      • -------- Set homeport --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Select home port
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Target unit of ability being cast)) Equal to Trade Port
            • Then - Actions
              • Hashtable - Save 0 as 2 of (Key (Casting unit).) in hashtable[3].
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: Reset |cff00ffffdes...
              • Hashtable - Save Handle Of(Target unit of ability being cast) as 1 of (Key (Casting unit).) in hashtable[3].
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: Set |cff00ff00homep...
            • Else - Actions
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: Target a trade post...
        • Else - Actions
      • -------- Set destination port --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • And - All (Conditions) are true
            • Conditions
              • (Ability being cast) Equal to Select destination port
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Unit-type of (Target unit of ability being cast)) Equal to Trade Port
                  • (Key (Load 3 of (Key (Target unit of ability being cast).) in hashtable[1].).) Not equal to (Load 3 of (Key (Load 1 of (Key (Casting unit).) in hashtable[3].).) from hashtable[1].)
            • Then - Actions
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Key (Casting unit).) from hashtable[1].)))
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Load 1 of (Key (Casting unit).) from hashtable[3].) from hashtable[1].)))
              • Hashtable - Save Handle Of(Target unit of ability being cast) as 2 of (Key (Casting unit).) in hashtable[3].
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: Set |cff00ffffdesti...
            • Else - Actions
              • Game - Display to (Player group((Owner of (Casting unit)))) the text: Target a trade post...
        • Else - Actions
      • -------- Press trade button --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Toggle route active
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Load 3 of (Key (Casting unit).) from hashtable[3].) Equal to 0
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of items carried by (Casting unit)) Equal to (Size of inventory for (Casting unit))
                • Then - Actions
                  • -------- If full inv, go to target --------
                  • Hashtable - Save 1 as 3 of (Key (Casting unit).) in hashtable[3].
                • Else - Actions
                  • -------- If not full inv go to homeport --------
                  • Hashtable - Save 2 as 3 of (Key (Casting unit).) in hashtable[3].
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Load 3 of (Key (Casting unit).) from hashtable[3].) Not equal to 0
                • Then - Actions
                  • Hashtable - Save 0 as 3 of (Key (Casting unit).) in hashtable[3].
                • Else - Actions
        • Else - Actions
well here's the full trigger,

specifically in this part=
  • -------- Set homeport --------
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Ability being cast) Equal to Select home port
    • Then - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Target unit of ability being cast)) Equal to Trade Port
        • Then - Actions
          • Hashtable - Save 0 as 2 of (Key (Casting unit).) in hashtable[3].
          • Game - Display to (Player group((Owner of (Casting unit)))) the text: Reset |cff00ffffdes...
          • Hashtable - Save Handle Of(Target unit of ability being cast) as 1 of (Key (Casting unit).) in hashtable[3].
          • Game - Display to (Player group((Owner of (Casting unit)))) the text: Set |cff00ff00homep...
        • Else - Actions
          • Game - Display to (Player group((Owner of (Casting unit)))) the text: Target a trade post...
    • Else - Actions
i set it at:
  • Hashtable - Save Handle Of(Target unit of ability being cast) as 1 of (Key (Casting unit).) in hashtable[3].
I don't know if the loading is correct though. i have no clue if i'm doing that wrong


during all my tests i first set the homeport and then i set the destination port
 
Level 9
Joined
Dec 1, 2010
Messages
346
okay you did make me check, maybe i'm confusing myself (my brain is cluttered)

1726916825277.png


i think key 1 is supposed to store a handle and i'm loading an integer?
Am i completely confused or is there a way to load the handle from this slot?

hashtable 3 saves the unit handle at slot 1 and i'm saying laod integer at slot 1 but what i really want is the unit handle of the homeport frm hashtable 3 so that in hashtable 1 i can use it to retrieve the tradeport number.


EDIT:
After running this it seems to display 1-1 in the check which is promising lmao
  • Game - Display to (Player group((Owner of (Casting unit)))) the text: (String((Load 3 of (Key (Load 1 of (Key (Casting unit).) in hashtable[3].).) from hashtable[1].)))
for clarification, instead of getting the integer i'm getting the key/handle id

Edit 2: Yes after antoher 30 minutes of struggling i realized i also mixed up my comparison. i took the unit handle where i needed the an int and i took an int where i needed to take the unit handle lol.
The trigger seems to be functioning now=


 
Last edited:

Uncle

Warcraft Moderator
Level 70
Joined
Aug 10, 2018
Messages
7,373
Some random fixes:

This is the Event that you use to detect when a unit successfully casts an ability:
  • Unit - A unit Starts the effect of an ability
Don't use anything other than this if you want to be 100% sure that you actually cast the ability. If you don't like the delay that comes with it then reduce the Casting unit's Art - Cast Point to 0.00 inside of the Object Editor.


You should almost never need to use AND:
  • If - Conditions
    • And - All (Conditions) are true
      • Conditions
        • (Unit-type of (Target unit of ability being cast)) Equal to Trade Port
        • (Key (Load 3 of (Key (Target unit of ability being cast).) in hashtable[1].).) Not equal to (Load 3 of (Key (Load 1 of (Key (Casting unit).) in hashtable[3].).) from hashtable[1].)
That's the default behavior of Conditions, in other words this has the same exact outcome:
  • If - Conditions
    • (Unit-type of (Target unit of ability being cast)) Equal to Trade Port
    • (Key (Load 3 of (Key (Target unit of ability being cast).) in hashtable[1].).) Not equal to (Load 3 of (Key (Load 1 of (Key (Casting unit).) in hashtable[3].).) from hashtable[1].)

Careful with the heavy usage of (Integer A) and (Integer B) in your For Loops:
  • For each (Integer A) from 1 to 24, do (Actions)
    • Loop - Actions
      • Unit Group - Pick every unit in transportShips[(Integer A)] and do (Actions)
        • Loop - Actions
These are global variables that are shared between all triggers. To avoid overwriting these values you'll want to use your own unique Integer that's dedicated to the trigger or set of triggers. For example:
  • For each integer Transport_Loop from 1 to 24, do (Actions)
    • Loop - Actions
      • Unit Group - Pick every unit in transportShips[Transport_Loop] and do (Actions)
        • Loop - Actions
 
Last edited:
Top