Hello,
I have 4 drop tables, one for each rarity (common, rare, epic, legendary), each drop table containing the items corresponding to that rarity. I have another 3 drop tables, each having a specific drop chance:
item_slot_one -> common_items (70%), epic_items (10%), legendary_items (5%), rare_items (15%)
item_slot_two -> rare_items (50%), epic_items (50%)
item_slot_three -> epic_items (33%), rare_items (33%), legendary_items (33%)
Every 24 hours, I want to generate 3 items (one from each item_slot, and all 3 items different from each other) and set them into the User Read Only Data. For now and for testing purposes, this method is called whenever an user logs in. Later on, I will probably use a Scheduled Task to run this cloudscript function (I know it is not very efficient, but this is an MVP and it won't have many players).
Here is my code:
handlers.getRandomDropTableItems = function (args, context) { var first_item = server.EvaluateRandomResultTable({"TableId" : "item_slot_one"}); var second_item = server.EvaluateRandomResultTable({"TableId" : "item_slot_two"}); var third_item = server.EvaluateRandomResultTable({"TableId" : "item_slot_three"}); while(first_item.ResultItemId == second_item.ResultItemId || first_item.ResultItemId == third_item.ResultItemId || second_item.ResultItemId == third_item.ResultItemId) { first_item = server.EvaluateRandomResultTable({"TableId" : "item_slot_one"}); second_item = server.EvaluateRandomResultTable({"TableId" : "item_slot_two"}); third_item = server.EvaluateRandomResultTable({"TableId" : "item_slot_three"}); } var data = {}; data["item_one"] = first_item.ResultItemId; data["item_two"] = second_item.ResultItemId; data["item_three"] = third_item.ResultItemId; server.UpdateUserReadOnlyData({"PlayFabId" : currentPlayerId, "Data" : {data: JSON.stringify(data)}}); return { messageValue: data}; };
As you can see in my snippet, I am getting each item from those item_slot tables and setting them in User Read Only Data. The problem is that the server API calls exceed my limit (which is 5, and the calls made are usually 6). I want all those 3 items to be different from each other, and that is why the while is there.
From a previous post, I understand that I need to use GetRandomResultTables. But I am not exactly sure how (I looked through the API documentation and a few examples, but it is not exactly clear for my case). Could you provide me a code snippet or some hints/ more details about using GetRandomResultTables in my case?
Thanks again for all the help!