Arrow Quiver

Speaking of dragging, we can click on the Ammunition to send it to the dedicated slot, right? I haven’t tested it yet, still doing the connections thingy

Tomorrow I might ask for a major system though, something to ‘aid/replace’ the Traits System. As much as I love the traits system, I don’t think a game that has all of it’s skills based on just combat is a good idea, at least I’d like to have flavor in mine. Long-story-short, similar to how the combat system works based on XP, I want to duplicate that for resource gathering, crafting, and possibly other skills down the line, so that players can grind multiple skills for multiple rewards, and hopefully the grind might keep them around for a while (me and my wild imagination again… xD)

Again, that’s a discussion for another day. For tonight, let me just wrap up the Quiver system so I can get some rest, I only got 5 hours to sleep :slight_smile:

For that we must add to the Equipment Enum a ‘Quiver’, right? (Edit: Nevermind, that was a dumb question… I quickly realized we talking about assigning the ammunition to the prefab :sweat_smile: )

OK Umm, Brian… something probably went missing. When I try equip the arrow into my Quiver Equipment slot, it just… won’t fit in for some reason (Clicking on it does nothing (which is surprising, because I want the click to work as well), but dragging it results in the NRE). It gives me a Null Reference Exception error, as follows (shouldn’t we also consider adding the ‘TryHandleRightClick()’ method as well…?):

NullReferenceException: Object reference not set to an instance of an object
GameDevTV.UI.Inventories.QuiverSlotUI.GetItem () (at Assets/GameDev.tv Assets/Scripts/UI/Inventories/QuiverSlotUI.cs:36)
GameDevTV.UI.Inventories.ItemTooltipSpawner.CanCreateTooltip () (at Assets/GameDev.tv Assets/Scripts/UI/Inventories/ItemTooltipSpawner.cs:16)
GameDevTV.Core.UI.Tooltips.TooltipSpawner.UnityEngine.EventSystems.IPointerEnterHandler.OnPointerEnter (UnityEngine.EventSystems.PointerEventData eventData) (at Assets/GameDev.tv Assets/Scripts/Utils/UI/Tooltips/TooltipSpawner.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerEnterHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:29)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:514)

And one last thing before we clear this off, the arrows being wielded is independent of the bow, right? As in, we can wield any arrows we want, but we can’t fire them if the bow and arrow don’t match (which I believe it is, because we assign the arrow to the bow anyway)

You should consider it… but having done this already for equipment and action items, you should have the tools you need to make this work for Ammunition items…
(check if is an AmmunitionItem, move or swap as needed)

You love giving me null references with perfectly good line numbers, but no code with the line number marked…

In this case, though, there literally is only one thing that can be null in QuiverSlotUI.GetItem(), and that’s quiver…
Is there a Quiver on the player?

OK so umm, adding the Quiver got it to work properly with the player, but now I’m trying with the Right Hand Click method in ‘InventorySlotUI.cs’ (trying it as we speak). Speaking of which, just like how these bows have special needs to wield them, I’ll probably want special levels equal to those of the bows for the arrows, just to make sure the grind is on (if it’s a major system change, then I can live without it… xD)

We can add this by adding a line similar to the weapon, right? This line:

if (!equipableItem.CanEquip(equipableItem.GetAllowedEquipLocation(), equipment)) return;    // The line solely responsible for checking for Predicate conditions, prior to being able to wield a weapon (if you're not high enough of a level, you can't wield that)
                

This is the HandleDoubleClick() (I guess HandleRightClick() in your case) in InventorySlotUI…

        private void HandleDoubleClick()
        {
            TimesUp();//Prevents triple click from starting another HandleDoubleClick
            InventoryItem item = inventory.GetItemInSlot(index);
            int number = inventory.GetNumberInSlot(index);
            if (item == null || number<1 ) return; //Nothing to do
            if (inventory.gameObject.CompareTag("Player"))
            {
                var otherInventoryUI =
                    FindObjectsOfType<InventoryUI>().FirstOrDefault(ui => ui.IsOtherInventory); //will return the other Inventory or null
                //Check to see if it's not null (should never happen), if it's Active, and if the otherInventory's inventory is valid.
                if (otherInventoryUI != null && otherInventoryUI.gameObject.activeSelf && otherInventoryUI.SelectedInventory!=null)
                {
                    Inventory otherInventory = otherInventoryUI.SelectedInventory;
                    TransferToOtherInventory(otherInventory, item, 1);
                }
                else if(item is EquipableItem equipableItem && inventory.TryGetComponent(out Equipment equipment))
                {
                    EquipItem(equipableItem, equipment, number);
                }
            }
            else //if(!inventory.gameObject.CompareTag("Player") means we're the other inventory.
            {
                TransferToOtherInventory(Inventory.GetPlayerInventory(), item, 1);
            }
        }

See this section here:

                else if(item is EquipableItem equipableItem && inventory.TryGetComponent(out Equipment equipment))
                {
                    EquipItem(equipableItem, equipment, number);
                }

Youre’ going to want to do something similar with the Quiver… as in…
Check to see if the item is an AmmunitionItem, and check to see if there is a Quiver… Then transfer the item to the Quiver…

The EquipItem method should provide a template for the actual transfer…

  • See if the Quiver already has an item loaded. If it does, store that item and quanity temporarily, then transfer the current item to the quiver, then add the item you got from the quiver to the inventory, otherwise, just transfer the item to the quiver.

OK so here’s what I tried doing:

                    else if (item is AmmunitionItem ammunitionItem && inventory.TryGetComponent(out Quiver quiver)) {

                        quiver.AddAmmunition(ammunitionItem, number);

                    }

But… it still didn’t work :confused: - We’ll also have to add a ‘TryHandleRightClick()’ in QuiverSlotUI to reverse the process as well (I sincerely apologize if I’m asking for too much tonight)

What happened when you did that… did the Quiver get the items, but the items remained in inventory? (Infinite Well of Ammy)?

Nope, no transfer at all…

Trying not to accidentally have that in my game… already met this annoying pitfall multiple times, it was horrifying

Out of time for now… Here’s the completed InventorySlotUI.HandleDoubleClick()

        private void HandleDoubleClick()
        {
            TimesUp();//Prevents triple click from starting another HandleDoubleClick
            InventoryItem item = inventory.GetItemInSlot(index);
            int number = inventory.GetNumberInSlot(index);
            if (item == null || number<1 ) return; //Nothing to do
            if (inventory.gameObject.CompareTag("Player"))
            {
                var otherInventoryUI =
                    FindObjectsOfType<InventoryUI>().FirstOrDefault(ui => ui.IsOtherInventory); //will return the other Inventory or null
                //Check to see if it's not null (should never happen), if it's Active, and if the otherInventory's inventory is valid.
                if (otherInventoryUI != null && otherInventoryUI.gameObject.activeSelf && otherInventoryUI.SelectedInventory!=null)
                {
                    Inventory otherInventory = otherInventoryUI.SelectedInventory;
                    TransferToOtherInventory(otherInventory, item, 1);
                }
                else if(item is EquipableItem equipableItem && inventory.TryGetComponent(out Equipment equipment))
                {
                    EquipItem(equipableItem, equipment, number);
                } else if (item is AmmunitionItem ammunitionItem && inventory.TryGetComponent(out Quiver quiver))
                {
                    TransferToQuiver(ammunitionItem, quiver, number);
                }
            }
            else //if(!inventory.gameObject.CompareTag("Player") means we're the other inventory.
            {
                TransferToOtherInventory(Inventory.GetPlayerInventory(), item, 1);
            }
        }

along with the InventorySlotUI.TransferToQuiver()

        private void TransferToQuiver(AmmunitionItem ammunitionItem, Quiver quiver, int number)
        {
            AmmunitionItem item = quiver.GetItem();
            int amount = quiver.GetAmount();
            inventory.RemoveFromSlot(index, number);
            quiver.AddAmmunition(ammunitionItem, number);
            if (item != null)
            {
                inventory.AddItemToSlot(index, item, amount);
            }
        }

OK not to make your day any harder, but that didn’t work either. Whenever you have the time, can we please try again? This, and the ‘TryHandleRightClick’ for the ‘QuiverSlotUI.cs’ please :slight_smile:

And a brand new problem: my AI Ranger enemies are out of ammo… (This honestly gave me a good laugh, but we need to renew the ammo for the rangers)

I’m off to sleep as well (i’ll be awake in less than 4 hours…), thanks again Brian

“That didn’t work” tells me absolutely nothing… I need more details whenever you say that didn’t work…

  • What was expected
  • What did happen?
  • Are there any error messages?

If you’ve got the code in place, then the issue is likely in the setup…
Here is my Upgrades repo, for which I’ve pushed a working Quiver setup (buy the bow and the ammo from the shop keeper just a few feet away from the player).

I expected the arrow to automatically go to the Quiver slot in the Equipments tab

Nothing happened

Nope, null, nada… No error messages. It just vowed not to work, nothing more

But you can drag to the Quiver slot?

Yes I can drag back and forth, but I can’t click to automatically transfer (neither from the inventory to the Quiver slot, nor vice versa)

Add the above noted Debug

The debug isn’t being called

Remove the else…

Nope, still won’t budge… i.e: still not working (don’t you think this function goes in ‘TryHandleRightClick()’ instead of ‘HandleDoubleClick()’? I have both here…)

YES, but I’m working off of my copy, which is HandleDoubleClick()… I thought I mentioned that above… You’ll want it to be in TryHandleRightClick()

Yup, placing it in ‘TryHandleRightClick()’ absolutely got it to work in my copy. Next step will be to code the “QuiverSlotUI.cs” 's function to also be able to unwield it through a click

And finally… give some ammo to the Ranger NPC AI, otherwise he can’t fight us

Privacy & Terms