Adding Gold Directly to the Player

nitrox32

Member
How do I add gold directly to the player? For instance, I want to add gold when they pick up an object. I understand how to create an item pickup, I just don't understand how use an inventory item definition to add gold directly to the player.
 
Thanks for getting back to me, I understand how to create an item pickup as you mentioned above. It's the part about Category and Definitions part I don't get. I created an item definition that includes currency amounts but when I collect the item it adds it to the players inventory and not the player's gold count. In other words, if I collect 50 gold, I will have fifty separate gold items in the inventory. How do I make it add to the players gold count not the inventory?Capture.PNG
 
Currency and Items are seperate things.

1 Gold item =/= 1 Gold Currency.

So picking up 1 gold item will not give you 1 gold currency. The way you've set things up the best you can do is sell the gold item in the shop to get 1 gold currency.

The system has both an ItemPickup and a CurrencyPickup (Checkout the demo scene, or the pickup feature scene). These are seperate components.

Currency is stored in the CurrencyOwner
Items are stored in the Inventory (ItemCollections)

So to add currency directly to the player in code you would do
Code:
ownerCurrencyCollection.AddCurrency(goldCurrency, 10);
There are code examples here:

And to add items you would do:
Code:
inventory.AddItem(goldItem, 10);


You mentioned having multiple Gold items instead of a stack of gold items. Items stack when their category is Common and Immutable. Make sure you understand the difference between common, unique, immutable and mutable items. It is very important to get the expected results. You can read their definitions here:
and here
 
Okay, I was able to create a currency pickup. My next question is when the player opens a chest. The chest window and displays the items that are in the chest based on what had been added. Since items are not the same as inventory, how can a player discover gold in a chest and add it to their currency?
 
That's actually not something anyone else requested as a feature so it was never implemented. I can add it to my TODO list. But I'm afraid it will take a while before I can implement it since I have a lot of high priority task to go trhough first.

If you are able to write code you could add it this feature yourself in the mean time.
There are two ways you could go about it
1) Override the Chest and Chest Menu code to allow currency to be shown and added to the Inventory.
2) Keep the Gold as an Item and add a event listener that listens to items being added to the Inventory, and if it matches the Currency Item Category, convert it in currency and remove the item.
3) Similar to option two, but instead of using a event listener, create a custom ItemTransactionCollection that converts Currency Items to currency, before they are added to the other ItemCollections. This has the advantage of working even if your bag ItemCollection is full, if you are using ItemRestrictions.

Those are two very different approaches, it really depends on the type of game and visual you want to achieve.
 
Top