Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by rewardclients · May 13 at 01:22 PM · CloudScriptPlayer Inventory

Cloud Script - get player inventory (update)

Hey!

I have to know how to get player inventory through Cloud Script, I mean that other player would run this Cloud Script and the second player inventory would be updated and he would see that on his device like this method:

    public void GetInventoryItemTime(string id)
    {
        var request = new PlayFab.ServerModels.GetUserInventoryRequest
        {
            PlayFabId = id,


            
        };


        PlayFabServerAPI.GetUserInventory(request, OnGetInventoryItemTime, OnError);
    }

but called by other player through Cloud Script.

I made something like this:

C# (Unity):

	public void OnRewardRevokedSuccess(PlayFab.AdminModels.RevokeInventoryResult result)
    {
		Debug.Log("Revoked Success");




		var request = new ExecuteCloudScriptRequest
		{
			FunctionName = "removeItem",


			FunctionParameter = new
			{
				playerID = whatID


			}


		};


		PlayFabClientAPI.ExecuteCloudScript(request, OnExecuteSuccess, OnExecuteError);


	}

public void OnExecuteSuccess(PlayFab.ClientModels.ExecuteCloudScriptResult result)
    {
		GameObject.Find("objects").GetComponent<objectsScript>().GetInventoryItemTime(result.FunctionResult.ToString());
    }


-------------------------------

Cloud Script:

handlers.removeItem = function(args){
    var playerID = args.playerID;


 
 return playerID;


}

But it doesn't works, please help guys, thanks!

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by rewardclients · May 16 at 07:48 AM

@Rick Chen can you please help?

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Gosen Gao · May 16 at 09:30 AM

From what I understand, you want to get other player's inventory through Cloud Script. You can call server.GetUserInventory in Cloud Script to get this info and return it to the client. You should not enable server API or admin API in your client project, because it may cause some security issues.

Here the Cloud Script code example:

handlers.removeItem = function(args){
	var playerID = args.playerID;//playerID should be PlayfabId
	var getInventoryResult = server.GetUserInventory({PlayFabId:playerID});
	return getInventoryResult.Inventory;
}

If there are any other problems ,feel free to let us know.

Comment

People who like this

0 Show 0 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    12 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Question on granting items 1 Answer

    PayPal Return Link Parameters and HTML5 Implementation 1 Answer

    ​ ​I want to have reviews for each catalog item? 1 Answer

    Getting item,How to get ItemInstanceId in GrantItemsToUse 1 Answer

    [CloudScript] Playfab Account Initialization 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges