Sign In Register

How can we help you today?

Start a new topic

Inventory: BuyVirtualGoods vs Custom Solution

I am looking into the best way to design an inventory system where items are both granted to the player at the end of a multiplayer match and can also be bought from a in-game store with in-game currency.


As far as I can tell the only way to grant items to the player is with a BuyVirtualGoods request correct?


From what I understand BuyVirtualGoods requires virtual currency to be spent but when granting an item to the player after a multiplayer match the item should be free, so should/can I "buy" a virtual good for 0 virtual currency?


OR


Should I have a custom runtime collection that virtual goods are added to after matches, if so how can items bought from the store for virtual currency be added to the runtime collection instead of player data (since it would be redundant to store the same data in two places)?


What steps should I take toward implementing this with cloud code?


1 person has this question

Hi Tolin,


You can also grant virtual items via Cloud Code:

 

Spark.getPlayer().addVGood(shortCode, quantity, reason);

 

 This will not use currency and the items will end up being in your player's inventory.


This means you can still use our virtual goods for your application.


Hope this helps,

Omar


That's great, I'll take another look at the player API.


One more question though:


Is there a way to get a list of all virtual goods; to say make drop tables or randomly pick a virtual good by tag/type?


Thanks.

 Hi Tolin,


Yes, use:

 

Spark.getConfig().getVirtualGoods()

 

This will return an array of virtual goods with their configs. You can loop it on a random index and return it or do something fancier using weights as seen in MMO loot tables.


Cheers,

Omar

Sweet, thanks.


Just so I'm sure that I'm working with JSON:


Does Spark.getConfig().getVirtualGoods() return as JSON in cloud script? You said I could loop though it, does that mean it is a list/array?

Can I modify the  tags of virtual goods in the player's inventory (assuming they are JSON)?


I think that's the last thing I need clarified.

 

 The function returns a list/array. Here's the result of the function invoked from Cloud Code in one of my games:


 

 

[
      {
        "currencyCosts": {
          "gold": 1
        },
        "description": "pack_100",
        "disabled": false,
        "name": "pack_100",
        "propertySet": null,
        "shortCode": "pack_100",
        "type": "VGOOD"
      },
      {
        "currencyCosts": {
          "test": 1000
        },
        "description": "test",
        "disabled": false,
        "name": "test",
        "propertySet": null,
        "shortCode": "test",
        "type": "VGOOD"
      },
      {
        "bundledGoods": [
          {
            "qty": 1,
            "shortCode": "pack_100"
          }
        ],
        "currencyCosts": {
          "gold": 5
        },
        "description": "buyPack100",
        "disabled": false,
        "name": "buyPack100",
        "propertySet": null,
        "shortCode": "buyPack100",
        "type": "VGOOD"
      }
]

 

 

 

Unfortunately, you can't change tags. Tags are linked to the configuration of the virtual good, not an instance of it.


Hope this helps,

Omar

Login to post a comment