question

abdulmunim2005 avatar image
abdulmunim2005 asked

Check if catalog item is owned or not

I am working in unity.I want to initialize the shop by checking if the item is owned or not I have done this offline but now i want to do it online for safer approach so each time user choose to play an online match or opens the shop I will check the car is owned if yes it is in it's original color if not then in black or hidden .

I have done importing GetUserInventory,Getcatalogitems but I do not know how to compare the item inctances.

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

·
brendan avatar image
brendan answered

The user (player) inventory is the set of items that the player possesses, so the way to do this would usually be by checking the ItemId of the inventory item instances in the player's inventory, to see if the appropriate item is there. Depending on the specifics of your game, there are a number of different ways you may want to do this check. The most secure would be if your game uses dedicated servers for gameplay, in which case the server could query the inventory of the players when they join the session, and then use that to determine what the player is allowed to do/see/etc. in gameplay - that way, a hacked client wouldn't be able to say that it has an item the player actually doesn't.

12 comments
10 |1200

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

abdulmunim2005 avatar image abdulmunim2005 commented ·

But how wold check all I get is a list of item instances which I do not even know how to use

0 Likes 0 ·
brendan avatar image brendan abdulmunim2005 commented ·

What specifically are you looking to do? The ItemId on each item - whether the listing in the catalog or as a property of an item instance in player inventory - is the field that you would use to match on, to determine if a player owns an instance of a particular item. So, to see if a player owns an item from the catalog, you would look to see if any item instance in that players inventory has the same ItemId as the catalog item in question.

0 Likes 0 ·
abdulmunim2005 avatar image abdulmunim2005 abdulmunim2005 commented ·

No my bad it was array of items not list sorry for disturbing thnx.

0 Likes 0 ·
abdulmunim2005 avatar image abdulmunim2005 commented ·

plz help me getting following error on car purchase

System.Collections.Generic.List`1[PlayFab.ClientModels.ItemInstance]

0 Likes 0 ·
abdulmunim2005 avatar image abdulmunim2005 commented ·

it gets right in 1 try then it unlocks all cars when store opens second time.It does this all times 1 then 2.

my code:

if (PlayfabRequest.Inctance.SessionTicket != "")
        {
            foreach (ItemInstance item in ValidateScript.Inctance.Items)
            {
                for (int t = 0; t < ValidateScript.Inctance.CItems.Length; t++)
                {
                    if (item.ItemId == ValidateScript.Inctance.CItems[t].ItemId)
                    {
                        SaveManager.Inctance.UnlockCar(t);
                    }
                    else
                    {
                        SaveManager.Inctance.LockCar(t);
                    }
                }


            }
        }
        else
        {
            PlayfabRequest.Inctance.Show(true);
        }

0 Likes 0 ·
brendan avatar image brendan abdulmunim2005 commented ·

Sorry, but for both of these, can you clarify what PlayFab API calls you are using, and what issues you are having using the results of those calls?

0 Likes 0 ·
abdulmunim2005 avatar image abdulmunim2005 brendan commented ·

I am using GetUserInventory,GetCatalogeItems calls the problem I am facing is that when i buy any car then open the shop it shows correct that 1 car is owned but when second time all cars are owned then 3rd time the first behavior(correct)then 4th time 2nd behavior (wrong) and so forth...

0 Likes 0 ·
Show more comments
abdulmunim2005 avatar image abdulmunim2005 commented ·

@Brendan

Game Id 23E4

Playfab Id of my test account

10F31C2D483EEC9E

plz run the code I used and check if I am having a bug or it is simply my mistake

0 Likes 0 ·
brendan avatar image brendan abdulmunim2005 commented ·

Given that I don't have your project (and so, don't have your "LockCar", for example), I can't really run your code. However, it's clear to see why the inventory for the player has that car. Here's the purchase history for the player:

https://developer.playfab.com/en-us/23E4/players/10F31C2D483EEC9E/purchases

So you can see the specific timestamp for when each car was purchased. Similarly, here's the audit log for the title:

https://developer.playfab.com/en-us/23E4/settings/audit-history

Which also clearly shows when each of the other cars were revoked.

0 Likes 0 ·
abdulmunim2005 avatar image abdulmunim2005 brendan commented ·

I revoked them so I can test again and again

so I understand that I have to check only granted items not all that player has so,

can you plz show me the manual/docs for that.

0 Likes 0 ·
Show more comments

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.