Hi All,
I'm struggling with a function I'm trying to write that would grant a User multiple items but also set the CustomData on the instanced item at the same time - I know the GrantItemsToUsers function will allow me to do this but I can figure out the syntax to use to get it working (Its errors in PlayFab saying "The ItemGrants field is required.")
I'd just like some input on how to go about setting up my code for this
I have a custom struct that I use for adding custom data such as CharacterData etc and want to do the same with the inventory items.
CloudScript:
handlers.GrantItemsToUsers = function (args, context) { var request = { ItemGrants: args.itemIDs } var result = server.GrantItemsToUsers(request); return result }
My Code:
public void StartCloudGrantUsersItems() { var request = new ItemGrantStruct[2]; request[0] = new ItemGrantStruct { PlayFabId = PlayFabID, ItemId = "Axe001", Data = new RelicData { AttackSpeed = 11, Defence = 100 } }; request[1] = new ItemGrantStruct { PlayFabId = PlayFabID, ItemId = "Axe001", Data = new RelicData { AttackSpeed = 11, Defence = 4 } }; var jsonRequest = JsonUtility.ToJson(request); Debug.Log("REQUEST: " + request); Debug.Log("REQUEST: " + jsonRequest); PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "GrantItemsToUsers", // Arbitrary function name (must exist in your uploaded cloud.js file) FunctionParameter = new { itemIDs = jsonRequest }, // The parameter provided to your function GeneratePlayStreamEvent = true, // Optional - Shows this event in PlayStream }, OnStartCloudGrantUserItems, OnErrorShared); }
Probably not the most elegant code so I'd be happy for anyone to offer up a better way to achieve the end result
RelicData is just a struct with a load of fields in it
ItemGrantScruct is a struct with PlayFabId, ItemId and RelicData (Instead of a Dictionary that the standard ItemGrant requires)
Many Thanks in advance!