Forum rules - please read before posting.

How to check which inventory slot is available and send an item to it?

I'd like to send an item to an empty inventory slot like on this video, watch at 0:45


How can I send my items over inventory bar and to an empty slot?
Thanks

Comments

  • ummm.. by what I see, this isn't something you can do natively with AC. You may need some scripting. But I have a couple of ideas: 

    1. fake it with animations: you could have several reusable animations which each go to a different slot of the menu. Then, when a player gets an item, turn on the sprite and go ahead and activate the correct animation depending on the empty slot available, (the animation should contain the appearing, moving and disappearing). Finally give the player the item through AC for it to appear in the inventory. Problem with this is: I don't know how you would go ahead and get the next "empty" slot to know which animation to activate, and I'm unsure how AC would work it out, I assume it's through an array, but we'd have to take a look at the scripting guide to see if we can find anything. 

    (Or, you could content yourself by just going ahead and making and empty slot, whose sole reason of existence would be for the effect, put it next to the inventory, and have it "receive" new items. then you could have a single animation to trigger when the player gets an item)

    or 

    2. You could use scripting to spawn the object and move it pretty much in the same manner you move a 2d character, except you have him move to a target, in this case the transform of the specific slot. The problem, again, is how to to know the next empty slot and also how to get the transform of the specific UI element. The first problem could be easily solved by using a UGUI, that way you will easily have access to the transform position...

    Anyway, maybe someone with a lot more programming knowledge or more grasp on ACs API could help us out here. I also want to try an effect that needs to know the identity of the inventory slot in regards to the inventory grid (in my case the first and last slot).
  • edited May 2016
    Yeah, I noticed some games sort of fake it. They send a found item and just before it reaches the empty inventory slot they quickly fade it out and fade in that item in the slot.
     So they use a dummy item that moves to the inventory and the inventory item that fades in.

    The problem is how to check which inventory slot is available and send it over, also how to move found item over the inventory bar since it is GUI.

    Also I wonder how to shift full inventory ( say full 7 slots) to left, show an empty available slot on the right and send the item there.

    At the moment I send my found items to markers.
    Thanks
  • edited May 2016
    Some custom scripting would definitely be required, but the API should have the functions you need.  First, add an invisible dummy item to the inventory, then use the following code to work out it's position:

    // Cast the MenuInventoryBox element
    AC.MenuElement myElement = AC.PlayerMenus.GetElementWithName ("MyMenu", "MyInventoryBox");
    AC.MenuInventoryBox myInventoryBox = (AC.MenuInventoryBox) myElement;

    // Shift all items to the end, so that the dummy slot is visible
    myInventoryBox.Shift (AC_ShiftInventory.ShiftRight, 100);

    int dummyID = 20; // The ID number of the invisible dummy item
    int dummySlotIndex = myInventoryBox.GetItemSlot (dummyID); // The slot index number of the dummy item

    // If Unity UI
    RectTransform slotRectTransform = myInventoryBox.GetRectTransform (dummySlotIndex);

    // Or, if AC Menu
    AC.Menu myMenu = AC.PlayerMenus.GetMenuWithName ("MyMenu");
    Vector2 slotCentre = myMenu.GetSlotCentre (myInventoryBox, dummySlotIndex);

    After the animation, you can then use the Inventory: Add or remove Action to replace the dummy item with your new item.
  • edited May 2016
    So basically you suggest is to add just one transparent item to the inventory and then replace it with the real ones I find/send, am I right? Very smart way.
    But once I remove the dummy one, how would I add the 2nd, 3rd and so on items since the dummy one would be gone? And I wouldn't be able to get the new position. Unless I'm missing smth.

    Thanks
  • Well, you'd be doing it in turn, right?  Add a dummy item, replace it, then add another one if there's a second item to animate.  The video only showed one at a time.
  • Ok, I will try it, thank you :D
    The items that I send/fly are not in GUI but the inventory is, how would I go about items flying over the inventory bar to the item's slots?
  • You could try a sprite or Unity UI.  Since you'll be using a different system to the GUI, you'll have to make sure the scale looks correct, but first you should focus on just getting it to animate to the right place.
  • edited September 2019

    Trying to do the same thing (v. 1.69.2), but with no luck.

    For example in Game Tab (Unity Editor) screen set to 800x480:
    Vector2 slotCentre = myMenu.GetSlotCentre (myInventoryBox, 3);
    return 728.0, 30.4. But this is almost opposite to the real position of DummyItemSlot #3.

    the following line not working, thus I just comment it:
    myInventoryBox.Shift (AC_ShiftInventory.ShiftRight, 100);

    Is there any solution to this?

  • The y-position increases as you go down from the top of the screen, so 728x30 suggests it's towards the top-right. Where is it really, and is it rendered with AC or Unity UI? A screenshot to illustrate the actual situation would help a lot to understand the situation.

    the following line not working, thus I just comment it:

    What's wrong, exactly? The API for this function hasn't changed. Are you getting any message in the Console?

    Perhaps it's best if you share the actual code you're using.

  • edited October 2019

    Chris, thanks for prompt reply: you gave me an idea - which help...

    (1) Found the mistake in my code. To proper scale into Camera's viewport my solution now looks this:
    Vector2 slotCentre = myMenu.GetSlotCentre(myInventoryBox, dummySlotIndex);
    slotCentre = new Vector3(slotCentre.x, (float)Screen.height - slotCentre.y, -1);
    Vector3 slotCentreWorld = Camera.main.ScreenToWorldPoint(slotCentre);

    (2) in Enum.cs there is no definition for ShiftRight
    line 36: public enum AC_ShiftInventory { ShiftPrevious, ShiftNext };
    In EventManager.cs in line 635 ShiftLeft and ShiftRight just mentioned, probably it's a bug.

  • in Enum.cs there is no definition for ShiftRight

    Quite right. Yes, the Shift function call should be changed to the following:

    myInventoryBox.Shift (AC_ShiftInventory.ShiftNext, 100);
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.