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

[Solved] Move entire Hero Inventory from one Hero to another

Status
Not open for further replies.
Level 3
Joined
Mar 14, 2022
Messages
17
Hello! I am creating a system for a TD where there are multiple builders, and the player eventually has the option of switching between each builder. I want to make it so when a player switches builder - their inventory also carries over to the new unit. All my builders are hero type as to make it so they can sell Units (which is how the switching works).

Currently the trigger I have set up for the switching is:
Builder Switch.jpg


This works pretty well for the switching. I tried adding an action "Unit - Order (Selling Unit) to give (Item carried in slot 1 by (Selling Unit) to (Sold Unit)", combined with a 0.1 wait trigger which allowed for the item in slot one to carry over... But when I added actions for the items in slots 2 - 6 as well... It still only carried one of the items.

I have considered creating item slot variables for each player builders item slots... But I don't understand how assigning a Variable could work any differently when inserted into the action mentioned above.

Any help would be appreciated! Thank you!
 
Level 12
Joined
Feb 5, 2018
Messages
521
  • For each (Integer ItemLoopInteger) from 1 to 6, do (Actions)
    • Loop - Actions
      • Hero - Create (Item-type of (Item carried by (Selling unit) in slot ItemLoopInteger)) and give it to (Sold unit)
Put this before the remove and select action and it should do it. For better functionality selling unit could be triggering unit.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,517
It'd be better to transfer the items from one unit to another:
  • For each (Integer ItemLoopInteger) from 1 to 6, do (Actions)
    • Loop - Actions
      • Hero - Give (Item carried by (Selling unit) in slot ItemLoopInteger) to (Sold unit)
The action is called "Hero - Give Item To Hero". Don't be fooled, it doesn't need to be a Hero.
 
Level 3
Joined
Mar 14, 2022
Messages
17
It'd be better to transfer the items from one unit to another:
  • For each (Integer ItemLoopInteger) from 1 to 6, do (Actions)
    • Loop - Actions
      • Hero - Give (Item carried by (Selling unit) in slot ItemLoopInteger) to (Sold unit)
The action is called "Hero - Give Item To Hero". Don't be fooled, it doesn't need to be a Hero.
Updated to this one as it does make more sense for the action to 'Give' the Items to the other unit! Thank you both for your help!
 
Level 19
Joined
Feb 27, 2019
Messages
582
I have been working on a gui trigger for my map to move items to the exact same inventory slots and without interrupting orders. When I entered the thread I realized I had done an error in my previous trigger when I didnt consider charged items. I have now reworked the trigger (only took about 6 hours) but cant help to feel like there is a better option with a custom script than my cheesy system, except the fact its gui. I will post here because maybe @Voltron212 cares about items ending up in the exact same slots.

Is there is a function that I can use with custom script to move an existing item located on the map to a units specific inventory slot without interrupting orders, basically: "Hero - Give Item to unit in slot #"?

In a thread, @Maker mentioned "call UnitAddItemToSlotById(unit, itemId, slot)" but I am unsure of how it works. What does "itemId" mean and does it require the creation of a new item?

The reason I made the trigger was because I have art (effects) on units when they carry items but after replacing the skin (which is done a lot with a certain spell) of units these effects disappear and to reset the effects I seem to have to drop the items from the unit and then give them back, lul. Maybe worth to mention is that I change to a skin that has no attachment points then back to the original skin. The spell is used anywhere from 0-400 times during a game.

Short explanation of triggers: I set charges of items to max so charged items cant stack and place cheese in empty slots so that slot order is maintained. This allows for units orders not being interrupted by move item order. Because I cant move an item to a certain slot without interrupting orders I seem to must use cheeses and several loops. Here are the relevant parts of my current triggers.
  • Init Cheese Items
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set VariableSet CheeseLoc = (Point(-9000.00, 8000.00))
      • For each (Integer CheeseL) from 1 to 6, do (Actions)
        • Loop - Actions
          • Item - Create Cheese at CheeseLoc
          • Set VariableSet ParmaCheese[CheeseL] = (Last created item)
          • Item - Hide ParmaCheese[CheeseL]
  • Cheese Items
    • Events
    • Conditions
    • Actions
      • Set VariableSet Int = (Player number of (Triggering player))
      • For each (Integer CheeseL) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set VariableSet CheeseItems[CheeseL] = (Item carried by AllPigsArray[Int] in slot CheeseL)
          • Set VariableSet CheeseStacks[CheeseL] = (Item: CheeseItems[CheeseL]'s Integer Field: Number of Charges ('iuse'))
          • Item - Set charges remaining in CheeseItems[CheeseL] to CheeseStacksMax
          • Hero - Drop CheeseItems[CheeseL] from AllPigsArray[Int].
      • For each (Integer CheeseL) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CheeseItems[CheeseL] Equal to No item
            • Then - Actions
              • Hero - Give ParmaCheese[CheeseL] to AllPigsArray[Int]
              • Set VariableSet CheeseItems[CheeseL] = ParmaCheese[CheeseL]
            • Else - Actions
              • Hero - Give CheeseItems[CheeseL] to AllPigsArray[Int]
      • For each (Integer CheeseL) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of CheeseItems[CheeseL]) Equal to Cheese
            • Then - Actions
              • Item - Move ParmaCheese[CheeseL] to CheeseLoc
              • Item - Hide ParmaCheese[CheeseL]
            • Else - Actions
              • Item - Set charges remaining in CheeseItems[CheeseL] to CheeseStacks[CheeseL]
          • Set VariableSet CheeseItems[CheeseL] = No item
 
Last edited:
Status
Not open for further replies.
Top