question

seowebcart avatar image
seowebcart asked

Economy v2 Inventory

Hello everyone!! I have serious problems with the use of playfab and unity. I basically can't... add the object I collect in the game to the inventory.. can anyone send me an example script on how I could do it??? and I've been watching tutorials and looking for guides for about 1 year but with poor results... please give me a hand... I'm losing patience...

unity3d
10 |1200

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

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

May I know how you add the collected Items to the player’s inventory and what error message you receive? You may call the AddInventoryItems API with EntityId, ItemId and Amount to add the collected item to the player’s inventory. Refer to PlayFab Inventory APIs - PlayFab | Microsoft Learn. Please remember that we recommend calling this API in Azure function for security reason (this API may be abused by hackers), then you may call ExecuteFunction API to execute the function.

3 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.

seowebcart avatar image seowebcart commented ·

Thank you for your answer there are no tutorials about it and I really don't know how to do it... I would like an example please... the user registration session is ok... I'm missing this one which is used to assign objects to the inventory when they are collected, remove them from the inventory when they are used, and read them when I enter the game so that from playfab I know how many items I have..

0 Likes 0 ·
seowebcart avatar image seowebcart commented ·

or maybe if you know a tutorial where I can follow the steps that are carried out... An example would be enough for me... 1) when I pick up the object it is destroyed... what should I write in the object's script to add it to the inventory??? 2) in the playfab dashboard I added the credit card and inserted the object but when I collect it using this code

public void AddItem(string itemId, int quantity) { var request = new AddInventoryItemsRequest {

       Amount = quantity
   };

   
   PlayFabEconomyAPI.AddInventoryItems(request, OnAddItemSuccess, OnError);

} I get an error that says Playfaberror: items are invalid or missing

I'm a beginner please give me a tip if needed I'll even pay you... I've been trying to learn for over 1 year how to implement playfab but the online tutorials seem to be made on purpose so as not to reveal the most important part that I'm missing

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha commented ·

Currentlty, PlayFab doesn’t have Economy V2 example for you. When collecting Items, you could call AddInventoryItems API. When using Items, you could call SubtractInventoryItems API to reduce the inventory items. When you enter the game, you could call GetInventoryItems to get all the items owned by the player.

According to your code and the error message, it seems that you call the AddInventoryItems API without ItemId. The ItemId is necessary for calling the API. If “inserted the object” means you have already created catalog Items in PlayFab dashboard, you could attach the ItemIds with the objects in Unity. When player collect the objects, you could use the ItemId with the Amount and Entity parameter to call the AddInventoryItems API. Please remember that we recommend calling this API in Azure function for security reason (this API may be abused by hackers), then you may call ExecuteFunction API to execute the function.

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.