question

Kim Strasser avatar image
Kim Strasser asked

How can I avoid that a player purchases a certain item more than once?

I want to create an item in my catalog that the player needs to purchase if he/she wants to participate in a weekly leaderboard for a certain level. I have already created a scheduled task to start and end the weekly leaderboard. But I'm not sure what type of item(durable or consumable?) that I should create in my catalog so that the player can only purchase it once for each weekly leaderboard. It should only be possible to buy the item if the player doesn't already have it in his/her inventory.

I use this client code to purchase the item:

var result = await PlayFabClientAPI.PurchaseItemAsync(new PurchaseItemRequest()
{
    CatalogVersion = shopname,
    ItemId = itemid,
    Price = itemprice,
    VirtualCurrency = itemcurrency
});

But I have the following problem:

At the moment, a player can purchase an item(Level 1-1_Ticket) more than once for the same weekly leaderboard in the catalog. The problem is that the player would pay too much because he/she can purchase the item more than once for the same weekly leaderboard.

What can I do so that the player can not purchase the item more than once for the same weekly leaderboard?

It should only be possible to purchase the same item again when the first purchase was already consumed(in CloudScript).

Finally: Immediately after the weekly leaderboard has ended, a rule for the event type player_ranked_on_leaderboard_version is executed and I call this CloudScript code to consume the item Level 1-1_Ticket:

var result = server.ConsumeItem(
{
    PlayFabID: currentPlayerId,
    ConsumeCount: 1,
    ItemInstanceId: iteminstanceid
});

EDIT: It works now.

I use client API GetUserInventory to check if the player has already this item in his/her inventory. And I only call PurchaseItem if the item is not in his/her inventory.

In-Game Economy
10 |1200

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

1 Answer

·
Seth Du avatar image
Seth Du answered

This question is in the scope of anti-cheating, while it depends on the detailed design of your game. In the common scenario, as long as the leaderboard aggregation is not accumulated (sum method in PlayFab), it should be fine to do it locally on the client via checking the player’s inventory to enable/disable the items in the merchant, because it doesn’t affect other player’s gaming experiences badly even they are malicious users.
I think you are on the right track.

10 |1200

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

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.