I want to create achievements in my title account but I don't know how to create them. I always want to update the player's achievements after he finished a level in my game.
Possible achievements that I want to add to my title account:
-Finish this level 5 times-->reward: Granted 100 virtual currency
-Submit your high score of this level to the PlayFab leaderboards-->reward: Granted 100 virtual currency
-Get 500 points in this level-->reward: Granted 200 virtual currency
-Don't get hit in this level-->reward: Granted 300 virtual currency
-Kill all enemies in this level-->reward: Granted a durable item(for example a special sword from the catalog) that you normally need to purchase with virtual currency in the PlayFab shop.
-Win a weekly leaderboard-->reward: Granted a durable item(for example a special sword from the catalog) that you normally need to purchase with virtual currency in the PlayFab shop.
In addition, I want that the all player's achievements are visible to all other players. You don't need to have another player in your friendslist to see his achievements.
How can I create these achievements in my title account? Is it possible to do it in the game manager with READ ONLY DATA in Player Data (Title) or is there a better way to create the achievements?
I want to update/check in CloudScript if a player fulfills the achievements requirements. In addition, I want to count in CloudScript how often a player finished a certain level.
UPDATE:
My CloudScript:
handlers.CreateAchievementsReadOnlyData = function (args, context) { var resultdata = server.GetUserReadOnlyData({PlayFabId: currentPlayerId, Keys: "Finish level 1"}); // first search for the current achievement info if(resultdata.Data.hasOwnProperty("Finish level 1")) { // if achievements info already exists in readonly data log.info("Already has achievements info."); // notify the client that Achievements info already been set } else {// if achievements info hasn't been set yet, set it for the user server.UpdateUserReadOnlyData({ PlayFabId: currentPlayerId, Data: { //The first 5 achievements belong to one certain level in the game, for example level 1. "Finish level 1": "false", "Finish this level 3 times": "0", "Submit your high score of this level to the PlayFab leaderboards": "false", "Get 400 points in this level": "false", "Don't get hit in this level": "false", "Kill all enemies in this level": "false", //The next 5 achievements belong to one certain level in the game, for example level 2. "Finish level 2": "false", "Finish this level 5 times": "0", "Submit your high score of this level to the PlayFab leaderboards": "false", "Get 600 points in this level": "false", "Don't get hit in this level": "false", "Collect 5 treasures in this level": "0", //The next achievements are special achievements, they don't belong to a certain level in the game. "Win a weekly leaderboard": "0", "Finish 100 levels": "0", "Get 10.000 points": "0", // You get points after you finiseh a level. I want to sum all points and check if the player has reached 10.000 points. } }); log.info("Achievements info has now been set."); } return resultdata; }
Client code:
private async Task CreatePlayerAchievements() { var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest() { FunctionName = "CreateAchievementsReadOnlyData", GeneratePlayStreamEvent = true }); if (result.Error != null) Console.WriteLine(result.Error.Error.ToString()); else { if (result.Result.Logs.Count() > 0) Console.WriteLine(result.Result.Logs[0].Message); } }