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 /
  • General Discussion /
avatar image
Question by laurentiumarianivan · Nov 20, 2020 at 01:15 PM · apisCloudScriptlimitsscheduled tasks

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.
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Nov 21, 2020 at 12:21 AM

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.

Comment
laurentiumarianivan

People who like this

1 Show 1 · 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 laurentiumarianivan · Nov 21, 2020 at 12:41 AM 0
Share

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!

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

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    Related Questions

    CloudScript execution time includes server warmup 1 Answer

    Server API: calling GrantUserItems versus ModifyItemUsesRequest. 1 Answer

    Delete Master Account,Deleting Master Account 1 Answer

    How do I add currency to a single user and then to ALL users?,How do I add currency to a single user and then to all users? 1 Answer

    How can you connect to PlayFab using the Kusto.Explorer tool? 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