laurentiumarianivan avatar image
laurentiumarianivan asked

Random generate unique items

Hello, it's me again. I have this CloudScript function, which, for now, I call from the client with ExecuteCloudScript method, but soon I will call it every 24 hours using scheduled task:

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};

The problem is that sometimes I get a mail, saying that "CloudScript execution API requests issued (triggered action)" regarding that function (and that I make 6 API calls when the limit is 5). I guess it's probably because sometimes I make too many server API calls using that while.
But how could I get random items from the tables and ensure that they are unique between them? I have around 12 items (4 rarities, 3 items for each rarity, each drop table has different chances of dropping an item from a rarity, some have a chance for each rarity, some have chances to drop only 2 rarities).
Any idea/ workaround about how to fix this?? This is more of an MVP also, so it doesn't need to be 100% safe or efficient.
apisCloudScriptlimitsscheduled tasks
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

Yes, don't use EvaluateRandomResultTables - use GetRandomResultTables, and use the odds in the table to determine the items to give the player in the script. That would also be faster, since it wouldn't be making 3+ Web API calls from the script - just 1.

1 comment
10 |1200

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

laurentiumarianivan avatar image laurentiumarianivan commented ·

Hey Brendan,

Thanks a lot for the fast answer. I am afraid I am not exactly sure how to use GetRandomResultTables. I looked over the API documentation and also over Drop Tables example, but it is still not very clear for me. I am not sure how to use the odds in the tables and to give the player those items

Some more details, in case they help:
I have 4 drop tables 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%)

As you can see in my snippet, I am getting each item from those item_slot tables and setting them in Player Read Only Data.
Could you provide me a code snippet or some hints/ more details about using EvaluateRandomResultTables in my case?

Thanks again for all the help!

0 Likes 0 ·

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.