question

bl4stmind@gmail.com avatar image
bl4stmind@gmail.com asked

CloudScript - Get item RemainingUses from inventory (Legacy)

Hi all,

I'm obviously spending a lot of time trying to learn C# and Playfab and i struggle to get the remaining uses of an item with a cloud script.

The cloud script is :

handlers.OnStatUpgrade = function(args){

     var getPlayerInv = server.GetUserInventory
     ({
         PlayFabId: currentPlayerId
     });
 
 var getPlayerInvItem = getPlayerInv.Inventory;  
 var getItemStats = JSON.parse(JSON.stringify(getPlayerInvItem));
 if (getItemStats.ItemId = "LingotFer" ) {
     return getItemStats.RemainingUses;
 }

}

That doesn't works obviously. Yet getItemStats is equal to : {"ItemId":"LingotFer","ItemInstanceId":"46B41216B525616F","ItemClass":"CBSDefaultData","PurchaseDate":"2024-01-29T16:50:02.881Z","RemainingUses":4,"CatalogVersion":"CBSItems","DisplayName":"Plaque d'acier","UnitPrice":0},{"ItemId":"MetalBar","ItemInstanceId":"AC7ADEA8AFDB97CB","ItemClass":"CBSDefaultData","PurchaseDate":"2024-01-28T18:18:50.018Z","RemainingUses":10,"Annotation":"Granted via Game Manager","CatalogVersion":"CBSItems","DisplayName":"Barre de métal","UnitPrice":0},{"ItemId":"GemShard","ItemInstanceId":"CDD457783C0F1009","ItemClass":"CBSDefaultData","PurchaseDate":"2024-01-28T18:18:37.053Z","RemainingUses":5,"Annotation":"Granted via Game Manager","CatalogVersion":"CBSItems","DisplayName":"Eclats de gemme","UnitPrice":0},{"ItemId":"Chaine","ItemInstanceId":"497A0FD4CC3664DD","ItemClass":"CBSDefaultData","PurchaseDate":"2024-01-28T14:36:54.53Z","RemainingUses":2,"Annotation":"Granted via Game Manager","CatalogVersion":"CBSItems","DisplayName":"Chaîne d'acier","UnitPrice":0},{"ItemId":"Rouage","ItemInstanceId":"A3320B768796F7EA","ItemClass":"CBSDefaultData","PurchaseDate":"2024-01-28T12:54:48.156Z","RemainingUses":8,"Annotation":"Granted via Game Manager","CatalogVersion":"CBSItems","DisplayName":"Rouage","UnitPrice":0}]

I would like to be able to retrieve the item remaining uses for a specific itemId, here "LingotFer". Do you know how to proceed ?

Best regards,

Mikael

CloudScript
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

Since calling the GetUserInventory API on the client side to get the remaining usage of an item is fine, may I know the reason you want to get the remaining usage of an item in Could Script?

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.

bl4stmind@gmail.com avatar image bl4stmind@gmail.com commented ·

Hi, yes of course ! I have a scene where the player can update the statistics of his characters. In the game client, i check if the player has the correspondings ressources for each upgrade. These ressources are items in the inventory. I check in the game client if the button can be interactable. But when the player click on it to make an upgrade, i was thinking that it would be better to double check if he has the relevants items and currencies in his inventory before trying to remove items and update the player data.

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha bl4stmind@gmail.com commented ·

Since you want to double-check that the number of items is sufficient and remove items from the player's inventory when they are sufficient, you can use the ConsumItms API to do both. When the quantity of the item is insufficient, APi will return an error. When the quantity is sufficient, the corresponding number of items will be consumed.

1 Like 1 ·
bl4stmind@gmail.com avatar image bl4stmind@gmail.com Xiao Zha commented ·

Alright, thanks for the advice !

1 Like 1 ·

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.