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!
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.
script exrcution problem 5 Answers
Clone player info to other title/studio 1 Answer
Question on granting items 1 Answer
PayPal Return Link Parameters and HTML5 Implementation 1 Answer