• 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] Attempting to save/load handles from hashtable

TFS

TFS

Level 2
Joined
Aug 28, 2015
Messages
3
First off, forgive me if this something fundamental and my brain just refused to learn.

Now to the point, I have a building ability im working on. Its called Coronate. Upon activation it will replace the targeted hero with a hero of type King then summon a group of "elite" units to the nearest Town Hall structure with fancy teleport special effects etc. Since I have a desire to use the actual "Mass Teleport" SFX, I have two triggers, 1. Coronate Hero and 2. Create Elite Units. The first trigger initiates a countdown timer which, upon its expiriation, obviously causes the second trigger to fire.

So I am using a hashtable to keep things MUI but the issue Im facing is that after saving the teleport SFX and nearest town hall location to the hashtable, loading them in the second trigger doesn't seem to work as they seem to reset to default values i.e. when I test the map, the "elite" units are created and the center of the map (which I believe means the default value is being loaded in which means I am incorrectly saving and/or loading the value into the hashtable).

I have reread the code several times and I cannot figure out where its going wrong.

Thanks in advance.

Ps. I realise there are still leaks. I will be attempting to fix them once I solve the hashtable issue. Cheers.

  • Coronate Hero
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Coronate
    • Actions
      • Set VariableSet coronateTarget = (Target unit of ability being cast)
      • Set VariableSet coronateUnitTypes[0] = Elite Footman
      • Set VariableSet coronateUnitTypes[1] = Elite Rifleman
      • Set VariableSet coronateUnitTypes[2] = Elite Knight
      • Unit - Replace coronateTarget with a King using The new unit's max life and mana
      • Set VariableSet coronateTarget = (Last replaced unit)
      • Special Effect - Create a special effect attached to the origin of coronateTarget using Abilities\Spells\Human\ReviveHuman\ReviveHuman.mdl
      • Special Effect - Destroy (Last created special effect)
      • Special Effect - Create a special effect attached to the origin of coronateTarget using Abilities\Spells\Human\Resurrect\ResurrectCaster.mdl
      • Special Effect - Destroy (Last created special effect)
      • Unit - Remove Coronate from (Casting unit)
      • Unit Group - Add (Triggering unit) to coronateCasters
      • Set VariableSet coronateNearestTHDist = 9999999.00
      • Set VariableSet coronateCasterLoc = (Position of (Triggering unit))
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((((Matching unit) is A town-hall-type unit) Equal to True) and ((Owner of (Matching unit)) Equal to (Owner of (Triggering unit))))) and do (Actions)
        • Loop - Actions
          • Set VariableSet coronatePickedLoc = (Position of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between coronateCasterLoc and coronatePickedLoc) Less than coronateNearestTHDist
            • Then - Actions
              • Set VariableSet coronateNearestTH = (Picked unit)
              • Set VariableSet coronateNearestTHDist = (Distance between coronatePickedLoc and (Position of (Picked unit)))
            • Else - Actions
      • Set VariableSet coronateNearestTHLoc = (Position of coronateNearestTH)
      • Hashtable - Save Handle OfcoronateNearestTHLoc as 0 of (Key (Triggering unit).) in customHashtable.
      • Special Effect - Create a special effect attached to the origin of coronateNearestTH using Abilities\Spells\Human\MassTeleport\MassTeleportTo.mdl
      • Set VariableSet coronateSFX = (Last created special effect)
      • Hashtable - Save Handle OfcoronateSFX as 1 of (Key (Triggering unit).) in customHashtable.
      • Custom script: call RemoveLocation(udg_coronateCasterLoc)
      • Custom script: call RemoveLocation(udg_coronatePickedLoc)
      • Countdown Timer - Start coronateTimer as a One-shot timer that will expire in 2.00 seconds

  • Create Elite Units
    • Events
      • Time - coronateTimer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in coronateCasters and do (Actions)
        • Loop - Actions
          • Set VariableSet coronateUnitCount = 0
          • Set VariableSet coronateUnitIndex = 0
          • Set VariableSet coronateNearestTHLoc = (Load 0 of (Key (Picked unit).) in customHashtable.)
          • Set VariableSet coronateSFX = (Load 1 of (Key (Picked unit).) in customHashtable.)
          • Special Effect - Destroy coronateSFX
          • For each (Integer A) from 1 to coronateNumUnits, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • coronateUnitCount Equal to 4
                • Then - Actions
                  • Set VariableSet coronateUnitCount = 0
                  • Set VariableSet coronateUnitIndex = (coronateUnitIndex + 1)
                • Else - Actions
                  • Set VariableSet coronateUnitCount = (coronateUnitCount + 1)
              • Unit - Create 1 coronateUnitTypes[coronateUnitIndex] for (Owner of (Picked unit)) at coronateNearestTHLoc facing Default building facing degrees
              • Special Effect - Create a special effect at (Position of (Last created unit)) using Abilities\Spells\Human\MassTeleport\MassTeleportCaster.mdl
              • Special Effect - Destroy (Last created special effect)
 
Level 24
Joined
Feb 27, 2019
Messages
833
I looked through. The save and load part looked good so I assumed something else must be wrong which as you mentioned must be the loc since null locs equal the co-ordinates 0.00, 0.00 (center of map). I looked at the where the nearest target is set which decides the location and found an error but I dont really understand why this error causes the units to be created in the center of the map. It should mean that the first ever picked unit that succeds the condition is always the unit that is set to the variable and pick every unit is deterministic. The error is this:
  • Set VariableSet coronateNearestTHDist = (Distance between coronatePickedLoc and (Position of (Picked unit)))
 

TFS

TFS

Level 2
Joined
Aug 28, 2015
Messages
3
@Duckfarter Thanks, I corrected the error you found. I still can't work out why its defaulting to the center of the map, and also the teleport SFX that is created on the nearest Town Hall doesn't get removed either. :peasant-thinking:
 

TFS

TFS

Level 2
Joined
Aug 28, 2015
Messages
3
@Duckfarter Omg I knew it would be something fundamental! Thank you! :thumbs_up:
I must have totally glossed over that point when I was reading the hashtable tutorials.
 
Top