Setup custom shop

Niroan

Member
Hello

Been trying to figure out how to make custom shop.
but it keeps showing my users inventory as the shop
 
Most likely you have set your own inventory as the shop inventory.

First you'll need to make a shop with its own inventory where you define the items which the shop will sell:
1601882080752.png

Then you may open your Shop Menu using the following code (In the next patch there will be a component for that so people won't need to write the code):

C#:
        [Tooltip("The shop menu.")]
        [SerializeField] protected ShopMenu m_ShopMenu;
        [Tooltip("The shop.")]
        [SerializeField] protected ShopBase m_Shop;

        /// <summary>
        /// Open the menu on interaction.
        /// </summary>
        /// <param name="interactor">The interactor.</param>
        public void Open(Inventory inventory)
        {
            m_ShopMenu.SetClientInventory(inventory);
            m_ShopMenu.SetShop(m_Shop);
            m_PanelManager.OpenMenu(m_ShopMenu);
        }

The client inventory is the player inventory.
The shop references it's own shop inventory.
 
What event type is the Currency?
Is this correct?

EventHandler.RegisterEvent<CurrencyAmounts>(_CurrencyOwner, EventNames.c_CurrencyOwner_OnUpdate, EventCurrencyUpdate);

then the function

public void EventCurrencyUpdate(CurrencyAmounts currency)
{
Debug.Log("Currency: " + currency.Count);


}
 
No, unfortunatly the event does not return the quantity that was added/removed. I'm not sure how I missed that...
I'll fix it in the next patch. I'll most likely do something similar to the inventory add and remove events.
 
Can you tell me where you Take and give currency inside shop? There must me a code that makes sure that player has enough “Gold”.
Right after that i Can just insert the cloud script
 
For those stumbling on this thread I sent this to Niroan on Discord:
1602149042505.png

The real fix will be a bit more advanced than just adding the execute event in those two places but this should work for Niroans purpose.
 
Hi @Niroan
Sorry about this morning. I'm not sure why things were not working. Since it was troubling me I spent my lunch break adding the new feature.
It's tested and it works. it's quite different from what we discussed.

You can find the relevant scripts attached. Make sure to replace the respective scripts where they belong.
If it doesn't compile then that means I made other changes in other files, if that's the case I'm afraid you'll have to wait for the next 1.0.X version to release. But from what I remember it shouldn't be the case.

Here is an example of how you can register to this new event:
C#:
using Opsive.Shared.Events;
using Opsive.Shared.Utility;
using Opsive.UltimateInventorySystem.Core;
using Opsive.UltimateInventorySystem.Exchange;
using System.Collections.Generic;
using UnityEngine;

public class CurrencyOwnerEventTest : MonoBehaviour
{
    [SerializeField] protected CurrencyOwner _CurrencyOwner;
   

    // Start is called before the first frame update
    void Start()
    {

        Debug.Log(_CurrencyOwner.gameObject);

        EventHandler.RegisterEvent<ListSlice<CurrencyAmount>>(_CurrencyOwner.gameObject,EventNames.c_CurrencyOwnerGameObject_OnAdd_CurrencyAmountListSlice, HandleAddAmount);

        _CurrencyOwner.AddCurrency(InventorySystemManager.GetCurrency("Gold"), 1);

    }



    private void HandleAddAmount(ListSlice<CurrencyAmount> amount)
    {

        Debug.Log("Add");

        for (int i = 0; i < amount.Count; i++) {

            Debug.Log(amount[i]);

        }
    }

}

The reason the parameter is a ListSlice<CurrencyAmount> is because you can remove multiple currencies at the same time.

If this solution does not work for you either then let me know and I'll see what I can do, you most likely will need to wait for the next version if that's the case.
 

Attachments

  • CurrencyOwner.cs
    7 KB · Views: 0
  • CurrencyCollection.cs
    68.7 KB · Views: 0
  • EventNames.cs
    5.3 KB · Views: 0
Top