1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Hidden inventories with little code

Discussion in 'Miscellaneous Tutorials' started by Xonok, Jul 30, 2013.

  1. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    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/A
    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.
    Possible use
    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).
     

    Attached Files:

    Last edited by a moderator: Aug 23, 2013
  2. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    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.
     
  3. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    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.
     
  4. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    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".
     
  5. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    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.
     
  6. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    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?
     
  7. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    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.
     
  8. Doomlord

    Doomlord

    Joined:
    Dec 15, 2011
    Messages:
    1,150
    Resources:
    14
    Spells:
    12
    JASS:
    2
    Resources:
    14
    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.
     
  9. Whitewolf8

    Whitewolf8

    Joined:
    Aug 31, 2011
    Messages:
    208
    Resources:
    3
    Models:
    1
    Maps:
    2
    Resources:
    3
    Unsure if this has been mentioned already, but apparently this also works if you the 'inventory' ability to items.
     
  10. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    In the end all that a secret inventory saves you, is having to apply the basic stats yourself.

    That's a good idea, I didn't think of that before.
     
  11. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,621
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    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?
     
  12. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    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).
     
  13. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,621
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    oh, my bad xD

    nice trick
     
  14. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    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?
     
  15. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    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).
     
  16. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    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...
     
  17. Krogoth

    Krogoth

    Joined:
    Apr 5, 2011
    Messages:
    247
    Resources:
    0
    Resources:
    0
    Nice trick, you actually solved my problem. +rep ^_^
     
  18. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,040
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    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.
     
  19. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Approved and moved. It is a neat trick.
     
  20. A Void

    A Void

    Joined:
    Mar 29, 2011
    Messages:
    2,498
    Resources:
    10
    Models:
    2
    Spells:
    1
    Tutorials:
    7
    Resources:
    10
    How was this approved? This is not a tutorial and I don't understand anything useful from this. This is only useful for those who want to create Item Inventory Systems, this trick was also covered in the Spellbook Tutorial.