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

Status
Not open for further replies.
Level 2
Joined
Mar 7, 2008
Messages
14
Hey Hive, I've stumbled across a problem when I tried to make a backpack unit.

The idea was to give the hero the ability to summon a backpack-dummy unit (I used Summon Misha), however I wanted to keep the inventory so that when the unit died or was resummoned, it would keep its inventory, and I made that work. The only problem is that when the backpack unit died, after a few seconds it would drop all the items, since it was not a hero. No matter how I tried to work around this problem, it would either end with losing all the items, or making copies (dropping items after death, but and also have the items when summoned).
When I try to remove the unit when it dies to prevent it from dropping the items, the items are removed as well. Here are the 3 triggers I use:

  • SaveInventory
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set ItemTest[(Integer A)] = (Item carried by (Triggering unit) in slot (Integer A))

  • LoadInventory
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • (Unit-type of (Summoned unit)) Equal to Backpack
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Hero - Create (Item-type of ItemTest[(Integer A)]) and give it to (Summoned unit)
  • PlsDontDropOnDeath
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Triggering unit) is dead) Equal to True
          • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
Maybe I'm going about this all wrong, but I think I need to either fix the trigger system, or somehow avoid having this particular normal unit type drop items on death. Any ideas?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
On the top trigger, try either hiding the items and showing on summon or moving them to the corner of the map / into the ocean

E/ for both of these, you need to change ur action robUnit -Give ItemTyoe[] to unit and remove third trig. To make it MPI, use (IntegerA + 20 * player id) when adding items
 
Level 2
Joined
Mar 7, 2008
Messages
14
I can't make the hide item work, and when I try to move the item, it just generates a new copy every time the backpack unit dies.
I don't really understand your second line, could you elaborate? Also, I'm guessing MPI has something to do with multiplayer compatible or something? I'm very much interested in that, could you explain why + 20? Thanks in advance!

Edit: Would it make sense to use hashtables maybe?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
If its generating a new item you're not doing it right, moving items doesn't dupe.

The number is irrelevant, it must be between (number of slots) and (8192 / number of players)

Hashtables are counterintuitive

MPI means that if you have a unit that kills their bag and another player kills their bag, the first can still load the original items. (Multi Player Instanceable)
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Never use and all condition block unless it is inside an or all condition block.
Never use integer A / B. Make a custom integer variable in variable editor and use that instead. ( this is for speed and efficiency.)

The problem is as stated above it needs to be MPI.
To do that store items in the slot based on ((player integer * 6) + loop integer)
As said above.
Then move the items to a spot on map. Then hide the items.

Then when you go to move items back. Unhide them. Then give them to the unit you want.

You should take a look at my tutorial Things You Should Know When Using Triggers / GUI
link is in my sig below.
 
Level 2
Joined
Mar 7, 2008
Messages
14
Alright, so I looked at your tutorial stuff, and after working on it I think I finally made it work. Could you tell me if you see something wrong with it?
It looks like this:
  • SaveInventory
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • For each (Integer index) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set ItemTest[index] = (Item carried by (Triggering unit) in slot index)
          • Item - Move (Item carried by (Triggering unit) in slot index) to (Center of (Playable map area))
          • Item - Hide ItemTest[index]
  • LoadInventory
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • For each (Integer index) from 1 to 6, do (Actions)
        • Loop - Actions
          • Item - Show ItemTest[index]
          • Hero - Give ItemTest[index] to (Triggering unit)
And then, if I understand correctly, to make it multiplayer compatible, I would have to do something like this?

  • SaveInventory
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • For each (Integer index) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set ItemTest[(((Player number of (Owner of (Triggering unit))) x 24) + index)] = (Item carried by (Triggering unit) in slot index)
          • Item - Move (Item carried by (Triggering unit) in slot index) to (Center of (Playable map area))
          • Item - Hide ItemTest[(((Player number of (Owner of (Triggering unit))) x 24) + index)]
Thank you for your help so far, and also thanks in advance :)
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
In your SaveInventory trigger you should store triggering unit before the loop and use the variable. Also you leak a location in that trigger. You need to store center of playable map area. You should also use an ITE and check if their is an item in that slot before trying to move the item.

In your LoadInventory trigger store triggering unit before the loop. In the loop you should check to see if the variable for the item is not null before trying to give it to a unit.


In your MPI trigger. Store triggering unit before the loop. You need to store center of playable map and clean the leak by removing location after. Store player number of Triggering player also. (you do not need owner of triggering unit since the event used is a player unit event. So triggering player will be better and more efficient.)
This will work currently.
[(((Player number of (Owner of (Triggering unit))) x 24) + index)]
but you should make it this.
[(((Player number of (Owner of (Triggering unit))) x 6) + index)]

Also use an ITE to check if their is an item in the slot before setting the variable to it.
 
Level 2
Joined
Mar 7, 2008
Messages
14
I'm quickly losing track of what I'm doing, but I've changed the trigger to this:

  • SaveInventory
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • For each (Integer index) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Triggering unit) has (Item carried by (Triggering unit) in slot index)) Equal to True
            • Then - Actions
              • Set ItemTest[(((Player number of (Owner of (Triggering unit))) x 6) + index)] = (Item carried by (Triggering unit) in slot index)
              • Item - Move (Item carried by (Triggering unit) in slot index) to (Center of (Playable map area))
              • Item - Hide ItemTest[(((Player number of (Owner of (Triggering unit))) x 6) + index)]
              • Custom script: call RemoveLocation (udg_Temp_Point)
            • Else - Actions
For the location, should I just make a region variable and replace the Center of Playable Map Area? Will it work in multiplayer in this state?

EDIT: Hmm, no that's not right, now the unit loads items that it has dropped.
 
Last edited:
Level 29
Joined
Oct 24, 2012
Messages
6,543
This trigger stores the items in each slot into the variable array.
You can then load those items and move them back into another unit.

  • SaveInventory
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • Set Temp_Point = (Center of (Playable map area)
      • Set tempUnit = ((Triggering unit)
      • Custom script: set udg_tempItemType = 0
      • Set tempInt = (Player number of (Triggering player) x 6)
      • For each (Integer index) 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 (Item carried by tempUnit in slot index)) Not equal to tempItemType
            • Then - Actions
              • Set tempInt = tempInt + 1
              • Set ItemTest[tempInt] = (Item carried by tempUnit in slot index)
              • Item - Move ItemTest[tempInt] to Temp_Point)
              • Item - Hide ItemTest[tempInt]
            • Else - Actions
      • Custom script: call RemoveLocation (udg_Temp_Point)
 
Level 2
Joined
Mar 7, 2008
Messages
14
Alright, it seems to work now, but I haven't tested it in multiplayer. Does it look okay?
  • SaveInventoryWandererBP
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • Set Temp_Backpack_Point = (Center of (Playable map area))
      • Set Temp_Backpack_Unit = (Triggering unit)
      • Custom script: set udg_tempItemType = 0
      • Set Temp_Int = ((Player number of (Triggering player)) x 6)
      • For each (Integer index) 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 (Item carried by Temp_Backpack_Unit in slot index)) Not equal to tempItemType
            • Then - Actions
              • Set Temp_Int = (Temp_Int + 1)
              • Set ItemTest[Temp_Int] = (Item carried by (Triggering unit) in slot index)
              • Item - Move ItemTest[Temp_Int] to Temp_Backpack_Point
              • Item - Hide ItemTest[Temp_Int]
            • Else - Actions
      • Custom script: call RemoveLocation (udg_Temp_Backpack_Point)
  • LoadInventoryWandererBP
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Backpack
    • Actions
      • Set Temp_Int = ((Player number of (Triggering player)) x 6)
      • For each (Integer index) from 1 to 6, do (Actions)
        • Loop - Actions
          • Item - Show ItemTest[Temp_Int]
          • Hero - Give ItemTest[Temp_Int] to (Triggering unit)
          • Set Temp_Int = (Temp_Int + 1)
 
Status
Not open for further replies.
Top