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

Hidden inventories with little code

Level 21
Joined
Mar 27, 2012
Messages
3,232
And here's for something completely different!

Story

I have a map, where each hero has a spellbook. At some point I got tired of adding the Inventory(hero) ability to each hero, so I put it in their spellbook.
On one of the heroes I forgot to remove the ability from hero itself.
The result? First 6 items I picked up simply disappeared, but they did add stats.
Back then I simply removed the ability from the hero and was done with it.
However, recently I started to test what this little glitch can do. The results blew me away.

What?

In the game there are 5 inventory abilities. They do stack, but in a strange way. If you combine 2 inventory abilities that both have 4 slots, then you can still only see 4 items.
That's because inventories overlap. The one added first is the one with the lowest slot indexes - it is the one to receive items first.
The one added last, however, is the one you can actually see.
You do not need to use multiple different inventory abilities to apply a secret inventory, but it can be useful if you want to dynamically add/remove the inventories.

How to use?

Make sure your hero has the Inventory(hero) ability.
Then create an ability based on spellbook. Add the Inventory(hero) ability into the spellbook and add the spellbook to the hero.
You're now done with the object editor part.

The harder part is triggers. I won't give instructions on how to make a full item management system. I will, however, give you the tools to make it.
Q/A explains.

Q: How do I know if an item was put into the hidden inventory?
A: When the item is picked up you check if it is in the hero's inventory. Sounds dumb, but the native that checks if a hero has some item only checks the visible inventory.
Thus, if an item was picked up and it isn't on the hero, then it was put into hidden inventory.
Q: How do I drop items if I can't even see them?
A: There is no direct way that I know. However, it can be simulated.
First you create an item of the exact same type
  • Item - Create (Item-type of (Item being manipulated)) at (Position of (Triggering unit))
Then you remove the old item.
You could also try to just move the item to ground, and it would work, but the item would become impossible to pick up and hero would still have it in the secret inventory, thus still gaining stats.
Make a boss that can be weakened by destroying his items when they are on the ground, thus reducing his stats.

Q: How do I drop an when it has already been picked up earlier?
A: When the item is picked up you store it into a variable, thus you can access it later too.
Q: How to put an item into the visible inventory when the secret one isn't filled?
A: The best way I know is filling all secret slots with a dummy item and then giving the actual item. After that you can remove the dummy items. For this you'll need to keep track of how many items the hero has at all times though.


*When adding/removing secret inventories they sometimes break, thus not dropping the items they contain. This can only be fixed by NOT removing them at all.
*The second inventory can be applied in any way, this includes items(an interesting idea, since items can then add slots for more items).

Test map:
Every item that gets put into a secret inventory is dropped 20 seconds later. The hero has 18 secret and 6 normal slots.
If you pick up all items, then wait for something to drop and then try to pick up more, then it will say that you have full slots.
This can be fixed by dropping one item(or not filling the visible inventory completely).
 

Attachments

  • Double Inventory.w3x
    18.9 KB · Views: 344
Last edited by a moderator:
Level 21
Joined
Mar 27, 2012
Messages
3,232
Wow. This is awesome. I just tested and it seems to function nicely with my CSS system too.

I will try to investigate more to outline a better way to do a backpack system that preserves stats.

This actually already does preserve stats.
In order to make a backpack you can move all items to a specific part of the map. If you want to remove something from the backpack, then you need to create another item of that type(to pick it up) and remove the old(to make stats not apply to whoever held it before).
To keep track of hidden items you can use an array.

Test map can tell a lot here.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
This actually already does preserve stats.
In order to make a backpack you can move all items to a specific part of the map. If you want to remove something from the backpack, then you need to create another item of that type(to pick it up) and remove the old(to make stats not apply to whoever held it before).
To keep track of hidden items you can use an array.

Test map can tell a lot here.

Yes I am already aware of that. What I am trying to say here is that it is bulky to do a nice backpack system with stat preservation but this discovery is a god-send to take care of all those.

Your method doesn't account for systems that attaches data to the items themselves. Such as my system that attaches the socket count data to a specific item. Thus I am thinking of a way to manipulate items in the hidden inventory somehow so that the items are never removed and truly "stored".
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Yes I am already aware of that. What I am trying to say here is that it is bulky to do a nice backpack system with stat preservation but this discovery is a god-send to take care of all those.

Your method doesn't account for systems that attaches data to the items themselves. Such as my system that attaches the socket count data to a specific item. Thus I am thinking of a way to manipulate items in the hidden inventory somehow so that the items are never removed and truly "stored".

Oh, now I get where the problem is.
Well, there are some ways that might work.
You can try giving the item to some other unit/hero, in order to unequip it. Moving item to location only works properly if the item is in a visible inventory.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Okay so I did some testing and found some interesting things.

  • When the spell book with inventory ability is added. All items in the main inventory is transferred to it.
  • It is possible to add multiple inventories, each will be a spell book with 'AInv' ability.

Hmm maybe if we are to use a struct to handle each inventory, it will be possible to create the backpack system right?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Okay so I did some testing and found some interesting things.

  • When the spell book with inventory ability is added. All items in the main inventory is transferred to it.
  • It is possible to add multiple inventories, each will be a spell book with 'AInv' ability.

Hmm maybe if we are to use a struct to handle each inventory, it will be possible to create the backpack system right?

When you add an inventory, then it overlaps the previous one. No items are actually moved.
About using the same ability, yep, I know.
But the problem is not adding. The problem is removing spellbook, cos sometimes that doesn't drop the items. If you just remove the spellbook AND delete items, then it would work, but as I get it, this is not good enough for what you want to pull off.

You could do something like having an array(or struct) for each hero, which has as many slots as the hero has secret inventory slots. Then, when an item is picked up you assign it to the variable/struct. Thus you'll have a list of equipped items.
How does that help? Well, you can assign custom stats to the virtual slot, instead of the item. Then you'll need a custom function for when an item is unequipped(removed), that removes the stats added by that item slot.
From that point on you can have your own methods of checking if hero has item equipped(whether it's in struct) and other necessary stuff.

That way you can (hopefully) get past the problems of removing items.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
When you add an inventory, then it overlaps the previous one. No items are actually moved.
About using the same ability, yep, I know.
But the problem is not adding. The problem is removing spellbook, cos sometimes that doesn't drop the items. If you just remove the spellbook AND delete items, then it would work, but as I get it, this is not good enough for what you want to pull off.

You could do something like having an array(or struct) for each hero, which has as many slots as the hero has secret inventory slots. Then, when an item is picked up you assign it to the variable/struct. Thus you'll have a list of equipped items.
How does that help? Well, you can assign custom stats to the virtual slot, instead of the item. Then you'll need a custom function for when an item is unequipped(removed), that removes the stats added by that item slot.
From that point on you can have your own methods of checking if hero has item equipped(whether it's in struct) and other necessary stuff.

That way you can (hopefully) get past the problems of removing items.

Yes that is what I thought before for a backpack system that is compatible with my CSS system. However I figure that it would take too much work since you have to handle a lot of data like whether the item is transferred to the backpack when it is dropped, when will an item be dropped from the backpack to the ground, how much stat to add (items with sockets), etc.

I will do some additional testing first before coming up with a conclusion.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Yes that is what I thought before for a backpack system that is compatible with my CSS system. However I figure that it would take too much work since you have to handle a lot of data like whether the item is transferred to the backpack when it is dropped, when will an item be dropped from the backpack to the ground, how much stat to add (items with sockets), etc.

I will do some additional testing first before coming up with a conclusion.

In the end all that a secret inventory saves you, is having to apply the basic stats yourself.

Unsure if this has been mentioned already, but apparently this also works if you the 'inventory' ability to items.

That's a good idea, I didn't think of that before.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
This seems buggy.
If Im ingame and got items in my hidden inventory, and then I want to remove it.

I see no good solution for this. How can I remove one of the hidden items?

It's only buggy if you try removing the inventories(which you shouldn't do anyway).

In order to remove one of the hidden items you need to keep track of all of the items that get hidden(aka, unit picks an item up, but doesn't have it and the item isn't a powerup).
Then in order to unequip you simply remove the item and create a new one at position of unit. It might also work if you just give the item to some other unit first, who doesn't have a secret inventory(Not tested this one).
 
Then in order to unequip you simply remove the item and create a new one at position of unit. It might also work if you just give the item to some other unit first, who doesn't have a secret inventory(Not tested this one).

but how will the user actually do it?

I mean for example, I pick up an item, it goes to the hidden inventory, since it is hidden I cannot remove it... Don't give me the trigger part because that is on the developer side, I'm talking about on the player side... the player cannot see it -> he cannot right click it -> he cannot drop it

and IMO, I think it looks bad to the user if he picks up an item and he don't see it in his inventory...

also, I think it's a bad idea to use this for a backpack for equipment items, because it still gives the item stats to the holder of the items... and items in a backpack doesn't do that right?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
but how will the user actually do it?

I mean for example, I pick up an item, it goes to the hidden inventory, since it is hidden I cannot remove it... Don't give me the trigger part because that is on the developer side, I'm talking about on the player side... the player cannot see it -> he cannot right click it -> he cannot drop it

and IMO, I think it looks bad to the user if he picks up an item and he don't see it in his inventory...

also, I think it's a bad idea to use this for a backpack for equipment items, because it still gives the item stats to the holder of the items... and items in a backpack doesn't do that right?

Well, in the end the main advantage that this system has over an item manager, is the fact that stats can be applied without triggers.
Also, it's relatively easy to make a MPI item management system with this exploit, and it's way easier than anything we could do before(due to not having to manipulate stats and not having to remove items when they are equipped).
 
Well, in the end the main advantage that this system has over an item manager, is the fact that stats can be applied without triggers.

Assuming that stat upgrades are picked items and in the expense that you cannot remove the stat without triggers since the user cannot right click the item in the hidden inventory...

Also, it's relatively easy to make a MPI item management system with this exploit, and it's way easier than anything we could do before(due to not having to manipulate stats and not having to remove items when they are equipped).

MUI maybe? since it's per unit... though you still need to do lots of checks if you want to use it for equipments... like if you need to lock equipments to 1 per type, you'd still need to check...

then if you have usable items, you need to ensure that they won't go into the hidden inventory else the user cannot use them... so in the end it's still a lot of work...

Yes, it makes thing simpler if you only consider hidden stat bonuses and other hidden bonuses... but if you think about the other implications of this system, I don't think it's worth it...
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Assuming that stat upgrades are picked items and in the expense that you cannot remove the stat without triggers since the user cannot right click the item in the hidden inventory...



MUI maybe? since it's per unit... though you still need to do lots of checks if you want to use it for equipments... like if you need to lock equipments to 1 per type, you'd still need to check...

then if you have usable items, you need to ensure that they won't go into the hidden inventory else the user cannot use them... so in the end it's still a lot of work...

Yes, it makes thing simpler if you only consider hidden stat bonuses and other hidden bonuses... but if you think about the other implications of this system, I don't think it's worth it...

Yes, most uses for this involve triggers, but it can be a quite useful mechanic. Although you did point out some good points.
In any case, one more tool in the hands of modders. I bet someone finds a use for it.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
In my spellbook tutorial I only mentioned the trick and didn't provide a good way to use it.
Also, I wrote this one before adding this information to the spellbook tutorial.
Overall, the spellbook tutorial is meant to talk about absolutely everything related to spellbooks and their uses, while this one is for a specific technique and how it can be abused.
 

Zwiebelchen

Hosted Project GR
Level 35
Joined
Sep 17, 2009
Messages
7,236
Nice discovery.

Let me present you of one awesome application you guys might not have thought about yet, that imho is much more valuable than just having a "secret" inventory that probably is more trouble than it's worth:

You can use this method to implement a lightweight stacking system that doesn't require the usage of powerups.

Currently, you can only do a stacking system by using powerups for items on the ground, as only powerups can be picked once the inventory is full. With this secret inventory bug, we now have a tool to allow picking up non-powerup items when the inventory is full, to allow incrementing the charges of existing items.

So the secret inventory serves as a cache to collect items over the current inventory limit.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
That is actually quite a good idea. In this case it's definitely necessary to keep the secret part of the inventory full while the main is not, so that the main one can work properly. When the main is filled, an item should be deleted from the secret one and voila, you have a hidden free slot for stacking.

Btw, back when I made the tutorial I didn't know about the moveitem orders. I'll test them to see if they can be used to shuffle items between inventories.
 
That is actually quite a good idea. In this case it's definitely necessary to keep the secret part of the inventory full while the main is not, so that the main one can work properly. When the main is filled, an item should be deleted from the secret one and voila, you have a hidden free slot for stacking.

Btw, back when I made the tutorial I didn't know about the moveitem orders. I'll test them to see if they can be used to shuffle items between inventories.

I wonder is it possible to make the "hidden" inventory visible? In GUI?
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
The game only shows the last added inventory, so even though you can interact with the hidden one you can't make it visible.

However, there are several workarounds.
1. You can delete items from the hidden one and recreate them in the main one, in order to make it seem like they were moved.
2. If moveitem orders work, then you can move items from hidden inventory to main one, but not the other way around(unless you drop the item and give it again).
 

Zwiebelchen

Hosted Project GR
Level 35
Joined
Sep 17, 2009
Messages
7,236
That is actually quite a good idea. In this case it's definitely necessary to keep the secret part of the inventory full while the main is not, so that the main one can work properly. When the main is filled, an item should be deleted from the secret one and voila, you have a hidden free slot for stacking.
That was exactly what I was thinking. To the JASS section we go!
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
I mean, his system also supports "max-inventory" case. He catches orders and prevents order if no slot is left.

I don't deny anything from the idea. Meaby I'm just dumb, or could you explain the issue for me more closely?

Edit: One problem tho, if hero (visible) inventory is full, even that the "hidden" ones are not, the "Full inventory" -warning is still applied. This can be caused by adding items by default in WE to unit (even in your map, add 6x crown of kings and see the difference).
That idea in regard to leaving one empty slot from hidden inventory might not work. When you fill all the hidden inventories and the visible one, when items start to drop (because of your 15sec periodic trigger) you can not pick any items, unless you free slot from visible inventory.

If I'm wrong, please help me get what/why/where.
 
Last edited:
Level 21
Joined
Mar 27, 2012
Messages
3,232
I've actually noted this bug that you described. The solution to this is removing one item from the main inventory(even if for a moment). This forces the game to refresh the inventory slots and thus will prevent the warning.
Probably the best moment to do this is when you remove an item from the hidden inventory (which is the only time that this can bug really)
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
This is more than just "removing item for a moment". How to prevent message/sound from occuring in such case? Removing/adding item might as consequence alter hero' stats, even for that little while, what might be dangerous.

Btw, I've just noticed that Witcher's system alters "full inventory" sound in interface constants.

Power ups.. power ups.. will we ever get rid of em?

Although the Witcher's idea might not be that bad, after all, we can play Inventory Full sound ourselves when there is no item to stack with in given inventory.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
If someone is willing to test the moveitem orders on items in hidden inventories, then that would be nice. I may get to it eventually, but atm I don't have much time.

The idea is that you keep track of all items in hidden inventories. Then when you order one of the items to be moved, probably to the same slot as it is. This might refresh the thing that checks item slots without actually picking up new items.
 
Top