Arrow Quiver

Then I guess I’m not understanding what’s going on…
You’re saying that an Unarmed SO is getting added to the inventory when the bow runs out of ammo?

If the player is in combat, he has a bow and arrow on him, and his ammo runs out and he’s forced to take the bow off during combat, then yes the Unarmed SO somehow gets instantiated in the Players’ inventory (I fixed the other bug with my player turning around, so now we have this one, and my abilities system has recently taken a messy hit as well. For now though, I want to develop a minimap first xD, so once we finish this bug we can try making a circular minimap that exists on the top right corner of my game screen)

I’m not entirely sure how this is possible… the UnequipRangedWeapon() method does add the current weapon to inventory, but it should only ever be called if the currently equipped weapon is a ranged weapon.

Go through your Fighter script and find any method that calls UnequipRangedWeapon(). Make sure that it’s only being called in the event that the weapon has a projectile assigned, has an ammo assigned, and that the quiver is out of the correct ammo.

Forgot to update this. I found this statement in the boolean ‘CheckForProjectileAndSufficientAmmo()’ function we created for this topic:

if (currentWeaponConfig.GetAmmunitionItem() && !GetComponent<Quiver>().HasSufficientAmmunition(currentWeaponConfig.GetAmmunitionItem())) {
            // If you want to keep pointing at your player without attacking them because of insufficient/wrong ammo, delete 'UnequipRangedWeapon()' below:
            UnequipRangedWeapon();
            return false;

I commented it out, and the problem was gone (since we have a ‘return false’ case for the rest of this function anyway, if none of the true conditions are met)

BUT… Now the player won’t unequip his weapon if his bow and arrow don’t match (apparently calling ‘UnequipRangedWeapon()’ in that function is the source of the problem)

This still shouldn’t fire the UnequipRangedWeapon if the player is using the Unarmored WeaponConfig

if(currentWeaponConfig.GetAmmunitionItem()

should only be true if the currentWeaponConfig has an AmmunitionItem, which means that the next part of the if won’t even be fired if it doesn’t… does the Unarmored have an AmmunitionItem assigned?

Nope, my ‘Unarmed’ does not have an ammunition or projectile assigned to it

I THINK I SEE WHERE THE PROBLEM IS, but I’m not sure how to solve it.

In ‘UnequipRangedWeapon()’, we have this line:

GetComponent<Fighter>().GetComponent<Equipment>().RemoveItem(EquipLocation.Weapon);

This line deletes EVERYTHING on the players’ “Weapon” location, including the ‘Unarmed’ that is supposed to replace the bow when it’s gone from the hand, hence why it instantiates the ‘Unarmed’ as well, into the inventory. Considering that we just wrote a command that deletes everything in the players’ “Weapon” location, it deleted the ‘Unarmed’ too, and it also instantiated the both of them into the inventory, because… well… that’s what this line is doing:

GetComponent<Fighter>().GetComponent<Inventory>().AddToFirstEmptySlot(currentWeaponConfig, 1, true);

(if the ‘Unarmed’ was unassigned, this wouldn’t be a problem I believe).

My question here is, how do we solve that? (Deleting it from the hierarchy returns an NRE, so that won’t work)

I was thinking of a ‘foreach’ loop that scans the inventory and deletes any ‘Unarmed’ objects it finds right after the weapon is unequipped, hence it’ll be in ‘UnequipRangedWeapon()’, but… the loop statement is already a headache, with this error:

foreach statement cannot operate on variables of type 'Inventory' because 'Inventory' does not contain a public instance or extension definition for 'GetEnumerator'

Edit, I found the source of the issue: This ‘if’ statement in ‘Fighter.Hit()’, at the bottom of it, is what’s responsible for the instantiation:

// If you don't have enough ammo and it's a projectile, take the ranged weapon off:
            /* if (!CheckForProjectileAndSufficientAmmo()) {
                UnequipRangedWeapon();
            } */

It’s at the absolute bottom of the checking for projectiles, in ‘Fighter.Hit()’. If we eliminate it, all problems go, except one. The only problem is, the fight won’t continue unless the player is hit once again (I want to fix this too, but if it’s at the cost of the issue then it doesn’t matter. That’s as close as I can currently get to ideal conditions).

Edit: A little more testing, and I realized it acts perfectly fine. We can cut this bug off our list now :slight_smile: (because the death bug that we thought we fixed by tuning ‘AwardExperience()’ unfortunately still exists. Saving and quitting the game and coming back fixes it with no issues, but I don’t want to go this far… If we can eliminate that death bug altogether that would be great)

In which order are you calling these two lines?
If you call them like this:

        private void UnequipRangedWeapon() {
           GetComponent<Fighter>().GetComponent<Equipment>().RemoveItem(EquipLocation.Weapon);
            GetComponent<Fighter>().GetComponent<Inventory>().AddToFirstEmptySlot(currentWeaponConfig, 1, true);
        }

Then the item would be removed, and Fighter would detect the item being removed and equip the Unamored, and at that point the Unarmored would be added to the inventory (and the bow would be… lost)
But if you run it this way

        private void UnequipRangedWeapon() {
            GetComponent<Fighter>().GetComponent<Inventory>().AddToFirstEmptySlot(currentWeaponConfig, 1, true);
            GetComponent<Fighter>().GetComponent<Equipment>().RemoveItem(EquipLocation.Weapon);
        }

Then the bow (being the currently equipped weapon) should be added to the inventory, then the weapon in the Equipment is removed, causing the Unarmored to be equipped from being the default weapon. From there, there should be nothing causing that unarmored to be placed in inventory.

I’ll give this a try in a bit and keep you updated. By tomorrow morning your time I’ll have this comment edited :slight_smile:

@Brian_Trotter Edit: it was always in the second order you mentioned above, the one that doesn’t destroy the bow on unequipment. Again, the issue is solved when you eliminate the ‘if’ statement we mentioned above. For now, let’s move on to something else… I’ll start another question for the death race condition that still somehow exists (Edit: This one is fixed by calling ‘Respawner.RespawnCoroutine()’ in ‘PlayerController.Update()’… not really tbh, it still shows up unfortunately)

Privacy & Terms