question

Tolin Simpson avatar image
Tolin Simpson asked

Player Inventory Questions

Hello, Here is out situation:

(Using Unity SDK and C#)

Recently we have developed a new inventory system that would get items based on an ID from an array and add them to slots in UI and categorized based on categories such as "Weapon", "Armor" and "Misc" linked to the item ID and this works great when testing and pressing a button that "grants" the player an item based on what ID is given.

PlayFab has only just started to be integrated with our project so these might be newbie questions but I could not find anything specific in the forums.

Q. 1) In the GetInventoryCallback(GetUserInventoryResult result) Function (taken from the "Prize Wheel" recipe) how can I get a property from an item in the inventories index similar to the categories I described above. Also what if I want GetInventory() to just return VC and not items so when I update the UI it just gets VC if I am updating the user's VC UI display it works the other way around or does getting the players inventory have to return everything each call.

Q. 2) Now for testing adding items from a button click by passing a number to the inventory UI works but we want to get an item from a drop table or catalog and add it to the players PlayFab inventory, from looking at the Client API I can only see Purchasing items as the only way to add an item to the players inventory through PlayFab, not always will the player be paying VC for items and we could just Purchase an item with the price of 0 to grant the item to the player but why is there not just an addItemRequest(string itemID,string userID, int amount) function that adds a new item from a catalog onto the end of the  item array's index? Unless I am missing something what is the best way to just add an item, does it have to be done through drop tables, if so how?

I hope I was able to communicate my questions clearly, I'll clarify more if needed.

Thanks in advance

- Tolin Simpson

Owner, LeatherBound Games

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

> 1) In the GetInventoryCallback(GetUserInventoryResult result) Function (taken from the "Prize Wheel" recipe) how can I get a property from an item in the inventories index similar to the categories I described above.

You can use the ItemClass or CustomData to track on the items type.

> Also what if I want GetInventory() to just return VC and not items so when I update the UI it just gets VC if I am updating the user's VC UI display it works the other way around or does getting the players inventory have to return everything each call.

Yes, currently it returns both. However, it would be a reasonable addition to provide optional "ReturnInventory" and "ReturnVC" parameters to it (which default to true, so that it's not a breaking change). I'll add that to the backlog, though I can't say for certain when it'll bubble up in our work stack. I would recommend putting this recommendation in our Feature Requests forum, so that others can help vote it up.

> 2) Now for testing adding items from a button click by passing a number to the inventory UI works but we want to get an item from a drop table or catalog and add it to the players PlayFab inventory, from looking at the Client API I can only see Purchasing items as the only way to add an item to the players inventory through PlayFab, not always will the player be paying VC for items and we could just Purchase an item with the price of 0 to grant the item to the player but why is there not just an addItemRequest(string itemID,string userID, int amount) function that adds a new item from a catalog onto the end of the  item array's index? Unless I am missing something what is the best way to just add an item, does it have to be done through drop tables, if so how?

It's not in the Client SDK because if you trust the client for that, a hacked client will cheat like crazy, guaranteed. You can instead use the GrantItemsToUser API call in the Server set from Cloud Script, which gives you a free way to have server-authoritative code. Here's a link to a write-up of Cloud Script: https://api.playfab.com/docs/using-cloud-script

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Amuse avatar image
Amuse answered

It is possible to get just virtual currency using GetUserCombinedInfo API call

Just set the following :

PlayFabId
GetVirtualCurrency as true (defaults to true)

GetReadOnlyData as false (defaults to true)
GetAccountInfo as false (defaults to true)
GetInventory as false (defaults to true)
GetUserData as false (defaults to true)

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

A very good point - thanks, Jason!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tolin Simpson avatar image
Tolin Simpson answered

Ok great, but using Cloud script changes my first question. If I use cloud script to grant the player an item can the client change the custom data of the item in the users inventory say I have the key value pair {"Damage":"0"} set in the catalog for that item and when it is granted to the player I want to randomize the damage value (specific to the item in the users inventory, I don't want to change the value in the catalog so users have completely unique items) or would this be better to do in the Cloud Script so cheaters can't set the damage of their weapons, if something like this should be done in Cloud Script what is the best way to do this. Should I modify the key value pairs in a Cloud Script and return them to be assigned by the client after granting the item, I am not usre how to do this because all items are different and some may not have custom data that needs to be modified. Also based on the item class and something like rarity the range to set the value of custom data mey vary. Can I access custom data in cloud script in a way I can do this?

pseudo code:

handlers.grantItemsToUser = function (itemID) {
    foreach(KeyValuePair in itemID)     {          if(KeyValuePair == "Damage")          {            //set value to a random range for damage          }          //ect..     }   //grant item           return { }   }
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Yes, all the Server API calls are available in Cloud Script. In fact, what you describe is the only way to do this, as UpdateUserInventoryItemCustomData is a Server API call.

Also, it's worth highlighting that the CustomData in the Catalog is not copied onto the item instances. At the catalog level, it's global data for all items of the same type, so that you can change it once there, and have all players using the same values.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

chrissimon avatar image
chrissimon answered

Hi @Brendan,

Is there any reason which would lead to VC from GetUserInventory and GetUserCombinedInfo being different?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.