question

VipulSingh avatar image
VipulSingh asked

Player Gifting another Player?

I have few items in catalog....player can purchase those items via virtual currency....but how can one player gift another player items from his/her inventory?,I have added few items in catalog, Every player can purchase those items by virtual currency.... Now if one player wants to gift other player a item from his/her inventory...how this can be achievable using PlayFab APIs ?

Player Inventory
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

VipulSingh avatar image VipulSingh commented ·

Sorry for Repetition of text...

0 Likes 0 ·

1 Answer

·
Rick Chen avatar image
Rick Chen answered

This can be done with OpenTrade API and AcceptTrade API in following steps:

  1. Player A who offer gifts, call OpenTrade API with gifts instance ids inside "OfferedInventoryInstanceIds" parameter, you can leave "RequestedCatalogItemIds" parameter blank to make the trade a gift. To restrict the players that can receive this gift, you can put their PlayFabId inside “AllowedPlayerIds”.
  2. After calling OpenTrade API, a TradeId is returned to Player A, he can then send this TradeId along with his PlayFabId to Player B who receives the gift.
  3. Player B then call AcceptTrade API with the TradeId and Player A’s PlayFabId to receive the gift.

These two APIs can be used to trade the item instance in players’ inventories, but not in Characters’ inventories. If you want to trade the instance in a character’s inventory, you may use server API (In CloudScript) MoveItemToUserFromCharacter first to move the item from Character’s inventory to player’s inventory, then call the Trade API, and then use MoveItemToCharacterFromUser API to move it back to Character.

Another quick way to implement this is to use server APIs RevokeInventoryItem and GrantItemsToUser or GrantItemsToCharacter in your CloudScript or Azure Function.

On CloudScript, you can define your function GiftToPlayer, which takes away Player A’s item using RevokeInventoryItem and gives Player B a new item using GrantItemsToUser. Be aware that in this way, the function grants the new item to the receiver, some item instance data from the sender could be missing, such as custom data of the instance.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Good Guy avatar image Good Guy commented ·

@Rick Chen : @Brendan

Using the Trade API does an item "carry over" its Custom Data too? Or does the system grant the recipient a new instance of the "base" item from the Catalog and then simply revoke the item from the giving player?

eg:
Player A has CARD1 and has "levelled it up" resulting in some Custom Data modified to indicate it's gone from base Level 1 to Level 4.

Player A Trades their CARD1 to Player B

Player B now has CARD1 but will it have Level 1 (base definition of Custom Data from Catalog) or will it have Level 4 (the modified Custom Data that Player A had) ?

0 Likes 0 ·

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.