question

simong@everguild.com avatar image
simong@everguild.com asked

GrantItemsToUser with a bundle

Hi, I created a catalog with items in it then I created 3 bundles which are basically 3 card decks that contains a list of items (the cards).
Each of these bundles contain 31 items.
When the player first register I run cloud script that grant to the user these 3 default bundles by doing so:
var result = server.GrantItemsToUser({CatalogVersion:"Catalog_v0.1", PlayFabId:currentPlayerId, ItemIds:[deckIds[i]]});
The problem is I don't receive all the items unlocked by the bundle, and it seems to be random. Sometimes I get 30 GrantedItemInstance, sometimes 28 or 29 but never the actual quantity.
I still always have the GrantedItemInstance corresponding to the bundle and when I check the property "BundleContents.length" it gives me the right number of times which is 31.
So basically for each bundle I grant to the user I should receive 32 items (the bundle items + the 31 cards) or it's not the case.
Here is a sample code:
var res = server.GetUserReadOnlyData({PlayFabId:currentPlayerId,Keys:["initInventory"]});
if(res.Data.initInventory == null)
{
var deckIds = ["Starter Orc", "Starter Elf", "Starter Vampire"];
for(var i = 0; i < deckIds.length; i++)
{
var characterId;
var heroId;
var deckData = { "Name":deckIds[i], "Cards":new Array()};
var result = server.GrantItemsToUser({CatalogVersion:"AllCards", PlayFabId:currentPlayerId, ItemIds:[deckIds[i]]});
log.info("Granted Starter pack " + deckIds[i] + " Num Elements :" + result.ItemGrantResults.length);
for(var j = 0; j < result.ItemGrantResults.length; j++)
{
var item = result.ItemGrantResults[j];
if(item.ItemClass == "Hero")
{
heroId = item.ItemId;
log.info("Character granted " + item.DisplayName);
characterId = server.GrantCharacterToUser({PlayFabId:currentPlayerId, CharacterName:item.DisplayName, CharacterType:item.ItemClass}).CharacterId;
}
else if(item.ItemClass == "Card")
deckData.Cards.push(item.ItemId);
else
log.info("Bundle item count " + item.BundleContents.length);
}
log.info("Num cards granted " + deckData.Cards.length + " total items : " + result.ItemGrantResults.length);
var serializedDecks = JSON.stringify(deckData);
server.UpdateCharacterReadOnlyData({PlayFabId:currentPlayerId, CharacterId:characterId, Data:{"CardId":heroId, "XP":"0", "PowerId":"0","TraitId":"0","DefenseBonusId":"0", "MercBonusId":"0", "NumDecks":"1", "Deck0":serializedDecks}});
}

log result :
info : "Granted Starter pack Starter Orc Num Elements :30"
info : "Bundle item count 31"
info : "Character granted Orc Chief"
info : "Num cards granted 28 total items : 30"
info : "Granted Starter pack Starter Elf Num Elements :28"
info : "Bundle item count 31"
info : "Character granted Elven Lord"
info : "Num cards granted 26 total items : 28"
info : "Granted Starter pack Starter Vampire Num Elements :28"
info : "Bundle item count 31"
info : "Character granted Vampire Noble"
info : "Num cards granted 26 total items : 28"

What's going on ? :(

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

·
brendan avatar image
brendan answered

I created a player profile in your game and confirmed that all the cards in the bundle are indeed being granted to the player. I believe what's tripping you up is the fact that a stacked item is listed only once in the user's inventory, with its stack count being the RemainingUses for the item.

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.