question

drakunnio avatar image
drakunnio asked

how to get the routed value of an item

i precise obtain for example, this value of my amount health potions in script C# for unity, how obtain this value?, it's apparence one question very easy, more i wanted in to forum and not got answer, sorry me me english, i am Brazilian, Trank you

10 |1200

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

Hernando avatar image
Hernando answered

Do you mean to get the remaining amount of consumables(health potions)?

If it is like this,first make sure you have added an item to your catalog that is set to consumable(Step-by-step tutorial can refer to Player Inventory).

Then you can get the player's inventory by calling GetUserInventory. The item which is consumable in response will has property RemainingUses, that value is what you need.

Besides, If you have any questions about consumable, please seethis thread of forums: https://community.playfab.com/questions/25985/what-is-the-difference-between-consumable-and-dura.html


10 |1200

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

drakunnio avatar image
drakunnio answered

my problem is a little more complicated than that I will explain better, in the class of items I created one that would be "KILL", and in the script of my character, I created a function that every last shot (the game is a 2d shot). Continuing the bullet projectile of each character has an identifier, put in the script of the monster that upon receiving the shot that reduces its life to 0, it enters the getcomponent of the other object and makes the call of the function that adds in that client another item " KILL ", and so far, everything is working perfectly well, I just wanted to be able to take that number of the amount of items that is marked as stackable, and expose in the player panel, something like getting an integer value .. currently tried something like:

public void check () { PurchaseItemRequest pr = new PurchaseItemRequest (); GetUserInventoryRequest ir = new GetUserInventoryRequest (); PlayFabClientAPI.GetUserInventory (ir, result => { List <ItemInstance> ii = result.Inventory; foreach (ItemInstance i in ii) { if (i.ItemId == "KILL") { kill = i.ItemId = "KILL"; Debug.Log ("HAS ITEM FOUND"); } } }, error => {}); }


the item is found but obviously there is something wrong on the line (kill = i.ItemId = "KILL";), and I would like to know how I could get the amount of the stackable item I have, I hope you have understood appreciate!

5 comments
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 commented ·

Can you please clarify your use case? This sounds a bit like you're trying to track a realtime action (damage being done to a character) via inventory. If so, that will not work, as it would require an excessive rate of API calls that would ultimate cause throttling on your title.

If you have data you need to be able to update and query at high frequency, you would need to either a) track that on the client and only periodically update the backend, or b) have a custom game server you use to host the simulation (if security is a requirement).

0 Likes 0 ·
drakunnio avatar image drakunnio commented ·

DetalhesThis is not the case, on the contrary, this data is only called in 1 case (as soon as the user logs in), and it is updated when it finishes a match, that is where I add the previous value + the current value. this is all working perfectly, I just wanted to know how I would get this amount of item quantity and turn it into a text that is only 1 time, and then I transform it into a custom property with photon ... example int KILLS = 3; Text NTEXT; NTEXT.text = "" + int; in this case access the value of the whole number with the script, but how to access the number of the quantity of an item?

0 Likes 0 ·
brendan avatar image brendan drakunnio commented ·

If the item in question is only being acted upon in the inventory of the player who just logged in (that is, you're not trying to update a single inventory by all players), then Hernando's information above is the answer to your question - the RemainingUses returned for that item in the inventory is the value you're looking for. What issues are you encountering reading that data?

0 Likes 0 ·
drakunnio avatar image drakunnio commented ·

I do not know the method of using the "remaining uses", but I already managed for example to get the value of the virtual coins and turns them into integers like this:


string MONEY = result.InfoResultPayload.UserVirtualCurrency ["MO"];
int NumberMO = (MONEY);


I want this line of code for the remaining use of a stackable consumable item, could you please give me an example code?

0 Likes 0 ·
brendan avatar image brendan drakunnio commented ·

Have a look at this tutorial:

https://api.playfab.com/docs/tutorials/landing-players/inventory

Where the code iterates across the items returned by GetUserInventory, you have access to everything in the inventory instances the player has (https://api.playfab.com/documentation/Server/datatype/PlayFab.Server.Models/PlayFab.Server.Models.ItemInstance). So when you find the item you want - likely with something like this:

if (inventory.Inventory[i].ItemId === ItemIdLookingFor)

(where ItemIdLookingFor would be your "KILL" item), you would get the remaining uses from:

inventory.Inventory[i].RemainingUses
0 Likes 0 ·

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.