Title ID: 44B1
Dear PlayFab community,
I am trying to figure out what the recommended "best practice" is to grant some initial inventory to a new player for a title.
Based on this link, it seems like I could potentially leverage the player_added_title event. In theory, this would work well for me.
However, my current application flow is to request both the player inventory and the title data on login. I presume that if a player is NewlyCreated on login, and that event is fired and I trigger an inventory grant, that inventory likely will *not* be returned with the login GetPlayerCombinedInfoResultPayload. (That is, I'm guessing there is some latency in which the player is created and the event is fired -- they're not synchronous and "on the same thread", so to speak.)
In an ideal world, that player_added_title event *would* get fired as soon as it happens, the inventory granted, and the default items would be sent down with the login results for the NewlyCreated=true player. ;-)
But, if my assumption is correct and it doesn't work like I hope, what is the recommended approach with which to grant a new player their default inventory? Perhaps in the delegate from the login, check the NewlyCreated flag, and issue another call to grant the default inventory? Or...?
Any advice would be greatly appreciated. Thanks in advance!
Answer by Brendan · Sep 28, 2017 at 02:36 AM
In general, you would use the event as described to add the items. But PlayStream events, and the calls triggered by them, do not block your normal API calls - that would create severe issues if there were ever a slowdown in event processing. In general, those events will be processed in seconds, though. So if you simply wait until you're done with your game intro animation or text, you should be able to get the player's inventory with all the items in it. If you want to have absolute control over that process, then yes, I would recommend using a call from the client to trigger adding the starting items, and put appropriate checks into the Cloud Script logic to ensure they really are a first-time user.
Thanks, Brendan! I will noodle on the various approaches. I feel like I do want "absolute control", but I also want to limit the ways in which the client can trigger inventory changes.
Answer by Jeff Posey · Aug 21 at 09:58 PM
I'm in the middle of implementing catalogs and inventory and was looking for a place to set starting inventory of players with the nice PlayFab dashboard. Didn't find it, and this is the only forum post I could find on the subject. It really seems like this would be a common feature request.
Does it still require writing server and client code to give players a starting inventory?
The way we do it right now is we have an item bundle in our catalog for new players and set up a Rule (under Automation -> Rules) that grants the item bundle to a player on the player created event (com.playfab.player_created). If you have to setup any separate values or anything on the items that are unique to their player, then you'll probably need to run some more expansive verification checks to make certain the player has received the items and that they've been setup correctly. We do that with our server at the moment, but a while back had a simple CloudScript that could handle it. Hope that helps!
Thanks for the reply! I was just messing around with Rules and the ability to Grant Item based on the player_title_added event. (you may want to switch to that event in case you start to have multiple titles under one publisher).
Thank you for the tip on using a Bundle to specify the starting Inventory. Smart!
So this isn't too bad at all. I shouldn't need to do a cloud script. But I think it's still worth having it be more explicit with a Starting Inventory tab somewhere under Economy. And especially if it is possible that I could request inventory before that event and actions finished happening, right? So I'll make sure to delay it, but building it in and ensuring it would be nice.