question

brendan avatar image
brendan asked

Question on granting items

Question from a developer:

Hello, why GrantItemsToUsers not work?? This is Javascript in Cloud:
var GrantInventoryToUserResponse = server.GrantItemsToUser({
"ItemGrants": [{
"PlayFabId" : currentPlayerId,
"ItemIds" : "Projectile_0",
"Annotation" : "First Login Setup Inventory",
"Data" : {
"MaxAmmo" : 60,
"AmmoPerClips" : 10,
"InitialClips" : 10,
"TimeBetweenShots" : 2,
"ReloadDuration" : 2
}
}]

});

CloudScriptIn-Game EconomyPlayer Inventory
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

You've got a mix of parameters that are for GrantItemsToUser (PlayFabIds) and GrantItemsToUsers (ItemGrants) in that call. Also, please note that CustomData key/value pairs are string/string. So, if you want to set the CustomData for the item instance when you add it to the user account, the call should be like so:

var GrantInventoryToUserResponse = server.GrantItemsToUsers({
  "ItemGrants": [{
    "PlayFabId" : currentPlayerId,
    "ItemId" : "Projectile_0",
    "Annotation" : "First Login Setup Inventory",
    "Data" : {
      "MaxAmmo" : "60",
      "AmmoPerClips" : "10",
      "InitialClips" : "10",
      "TimeBetweenShots" : "2",
      "ReloadDuration" : "2"
    }
  }]
});
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.