• 🏆 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] Backpack hashtable not switching items.

Status
Not open for further replies.
Level 6
Joined
Jan 8, 2009
Messages
140
This is basically my first attempt at using hashtables as it seems like the best way to handle it. I've probably done something fundamentally wrong here but it seems like it should work to me. it saves the players inventory when they cast open as 1-6 of that players index and removes the items. it then loads 6+ 1-6 where backpack items are stored and gives them to the hero. on closing it saves them and switches back.

the abilities switch and the items are removed but they don't seem to be saved correctly because they don't come back when close runs.

  • Testing Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Backpack = (Last created hashtable)
  • Backpack
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Open Backpack
    • Actions
      • Set playerNum = (Player number of (Owner of (Triggering unit)))
      • Unit - Remove Open Backpack from (Triggering unit)
      • Unit - Add Close Backpack to (Triggering unit)
      • For each (Integer loopA) from 1 to 6, do (Actions)
        • Loop - Actions
          • Hashtable - Save Handle Of(Item carried by (Triggering unit) in slot loopA) as loopA of playerNum in Backpack
          • Item - Remove (Item carried by (Triggering unit) in slot loopA)
          • Hero - Give (Load (loopA + 6) of playerNum in Backpack) to (Triggering unit)
  • Backpack Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Close Backpack
    • Actions
      • Set playerNum = (Player number of (Owner of (Triggering unit)))
      • Unit - Remove Close Backpack from (Triggering unit)
      • Unit - Add Open Backpack to (Triggering unit)
      • For each (Integer loopA) from 1 to 6, do (Actions)
        • Loop - Actions
          • Hashtable - Save Handle Of(Item carried by (Triggering unit) in slot loopA) as (loopA + 6) of playerNum in Backpack
          • Item - Remove (Item carried by (Triggering unit) in slot loopA)
          • Hero - Give (Load loopA of playerNum in Backpack) to (Triggering unit)
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You can make a separate unit and hide that unit and give the items to that unit instead of removing the items.

"Item - Remove <item>" removes it from the game and not only from the unit.
You should use "Hero - Give <item> to <unit>" where the unit is your dummy unit.
Or just drop the item and hide the item itself... depending on your preference.

@Bribe
There are actually many ways that I can name that he wont use but still make your approach glitch your map.
Better to keep the item than making a new one... basically for the same reasons why "Unit - Replace" is bad.
 

Ardenian

A

Ardenian

Another approach would be to save the item type of each slot and create them after the old ones are removed. However, this is more performance-intense.
 
Status
Not open for further replies.
Top