I want to create a rule that checks if the player has finished the current level the very first time. I f yes, then create a rating based on his score and add 100 gold coins to his account.
https://api.playfab.com/docs/tutorials/landing-automation/using-cloud-script-actions-with-playstream
I followed this tutorial but I'm not sure if my CloudScript is correct. What are the last two lines doing? Are they necessary?
var content = JSON.stringify({user: profile.PlayerId, event: psEvent.EventName}); var response = http.request('https://httpbin.org/status/200', 'post', content, 'application/json', null, true);
In addition, what is the Arguments (JSON) text box in my picture? When should I use this text box? Could you give me an example?
My problem is that the rule is not working. The function handlePlayStreamEventFirstTimeLevelFinished seems not to get executed, because I can not see a PlayStream event in the Game Manager and the player doesn't get his virtual currency. I only have a PlayStream event for player_finished_level_first_time in Game Manager but not for handlePlayStreamEventFirstTimeLevelFinished.
Raw event JSON { "EventName": "player_finished_level_first_time", "EventNamespace": "title.BFD0A", "Source": "BFD0A", "EntityType": "player", "TitleId": "BFD0A", "EntityId": "C30AD4505A3C3388", "EventId": "d52f1c2dd2174aba8a8e302ee7a3782c", "SourceType": "GameServer", "Timestamp": "2019-12-13T08:49:38.1730706Z", "History": null, "CustomTags": null, "Reserved": null, "PlayFabEnvironment": { "Vertical": "master", "Cloud": "main", "Application": "mainservercloudscriptint", "Commit": "f94b0ae" }, "IsFirstTime": "true", "Comment": "The player finished this level the first time.", "Level": "1", "Playerscore": "80" }
In addition, is it possible to get the rating somehow displayed in the client or is it not possible to return something from the function handlePlayStreamEventFirstTimeLevelFinished in my game?
handlers.UpdateLeaderboard = function (args, context) { ... var isfirsttime = true; var resultevent = server.WritePlayerEvent({ PlayFabId: currentPlayerId, EventName: "player_finished_level_first_time", Body: { "IsFirstTime": isfirsttime.toString(), "Comment": "The player finished this level the first time.", "Level": args.Level.toString(), "Playerscore": args.Playerscore.toString() } }); if (resultevent.Error == null) log.info("Writing player_finished_level_first_time event successful."); else log.info("Writing player_finished_level_first_time event not successful."); } handlers.handlePlayStreamEventFirstTimeLevelFinished = function (args, context) { // The event that triggered the action // (https://api.playfab.com/playstream/docs/PlayStreamEventModels) var psEvent = context.playStreamEvent; // The profile data of the player associated with the event // (https://api.playfab.com/playstream/docs/PlayStreamProfileModels) var profile = context.playerProfile; var level = context.Level; var playerscore = context.Playerscore; var rating = ""; if (Number(playerscore) < 50) { rating = "Not bad for your first time."; server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GO", Amount: "100"}); } if ((Number(playerscore) >= 50) && (Number(playerscore) < 150)) { rating = "The first time and already a professional."; server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GO", Amount: "100"}); } if (Number(playerscore) >= 150) { rating = "Is this the first time you played this level? This was amazing!"; server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GO", Amount: "100"}); } log.info("Level: " + level + "Your highscore: " + playerscore + " " + rating); log.info("Congratulations! You just got 100 gold coins for finishing " + level + " the first time."); // Post data about the event to an external API var content = JSON.stringify({user: profile.PlayerId, event: psEvent.EventName}); var response = http.request('https://httpbin.org/status/200', 'post', content, 'application/json', null, true); return { externalAPIResponse: response }; }