question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

How to make cron jobs on Playfab?

Are you familiar with Pokemon Go? In particular, how Pokemon spawn at regular intervals on the map.

Basically, pokemon appear on your map at regular intervals. The pokemon that appear is the same for everyone, so everyone has the same chance to catch it.

We have the islands, and corrupted creatures will appear on the map. I want random creatures to appear on the map at regular intervals (every 1, 4, or 24 hours depending on rarity), but they should be the same for everyone, and the creatures should offer the same loot if defeated.

I believe this type of data is something that needs to be generated regularly (probably ahead of time). With a cron job, or in Firebase, with a cloud scheduler.

How can I achieve this on Playfab?

CloudScriptscheduled taskstasks
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

·
Citrus Yan avatar image
Citrus Yan answered

Hi @Muhammad Roshaan Tariq,

There are a few things I need to confirm with you first. Based on your description, I think the functionality you want from PlayFab is to be able to generate spawn data at regular intervals and all the players can access that data and modify it ( I am thinking that you’ll need to update data when certain creatures are defeated), is that right? Generating spawn data at regular intervals can be done by Scheduled tasks https://docs.microsoft.com/en-us/gaming/playfab/features/automation/scheduled-tasks/quickstart PlayFab offers, you might want to read the doc to get on it.

However, the tricky part is how to store these spawn data for all the player to access and modify, my thinking is that if the number of players is huge, it will certainly involve massive concurrent update operations since you will need to remove certain creature from the map when the player has defeated it. PlayFab as a backend service does not support frequent updates. What you should do is to define the "map" with the configuration information on when things "spawn". This part can be done by schedule tasks. You would then have a dedicated server that takes requests from clients (the client sends up their GPS location), finds the spawns around the player's position, and sends back the information on things that are active around the player based on that spawn information (and whether or not the player has already interacted with the thing in question. Ideally, you would have the player maintain a persistent connection to the server while the game is active so that you don't have to repeatedly query the player's data every time they're trying to interact with something. If you are going to allow the players to interact with things with high frequency (more than a few per minute), that's pretty much a requirement. Cases where player interactions can be seen by each other, or contribute to each other (similar to the "gym" concept), you would use a dedicated server session.

In conclusion, you can utilize PlayFab Schedule Tasks to do the cron jobs to generate spawn data and save them, a dedicated server then can retrieve them and perform following operations without interacting with PlayFab frequently.

6 comments
10 |1200

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

Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq commented ·

Hello @Citrus Yan,

Thank you for taking time and write the answer as detailed as possible. So, yeah I want to generate the data using PlayFab services and about requesting PlayFab for data "Do I really have to get another third-party dedicated server to which my players will request and that server will request PlayFab then?" Because I have the firebase and DigitalOcean servers too but since I'm using PlayFab as BaaS for my game I wanted to keep everything at one place.

Would it be a problem if my players hit the PlayFab server frequently even if I increase the limit by paying more?

0 Likes 0 ·
brendan avatar image brendan ♦♦ Muhammad Roshaan Tariq commented ·

The main problem here is that PlayFab does not have a built-in geographic query. What I mean is, if you're trying to build a geolocation-based game, you need the client to be able to query for things that are immediately around them. That requires that you have a dedicated server that clients connect to, since otherwise you would have each client requesting the complete set of all data for the world every time.

Also, to clarify a point above - games like that do not update the backend data for each "spawn". They have a set of data defining the world - all the spawn points are pre-defined with the information on where they are, what they are, and with what frequency they spawn. They simply use programmatically consistent means to "randomize" (each spawn has a seed value which is combined with the current time, and the random function produces the same results from the same input). So the data is set up from the start and only changed occasionally, to make the world feel more "alive".

As to frequency, if the client is making more than a couple dozen API calls per minute, yes, you're getting into the range of "too frequent".

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Muhammad Roshaan Tariq commented ·

Hi @Muhammad Roshaan Tariq,

>>Do I really have to get another third-party dedicated server to which my players will request and that server will request PlayFab then?

PlayFab does provide custom server hosting service, please check this doc to see if it fits your needs: https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/

>>Would it be a problem if my players hit the PlayFab server frequently even if I increase the limit by paying more?

Increasing the limit may help, but it is not suggested to hit the PlayFab server very frequently.

0 Likes 0 ·
Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq Muhammad Roshaan Tariq commented ·

@Brendan @Citrus Yan

Okay So I have stripped down this requirements to two things only which I want my players to be able to access

1. which creature needs to be spawned at a point(I have some fixed points in my game) and to clear things up I'm not building a geolocation based game.

2. what loot you get when you defeat it

Can this be done using the scheduled tasks on Playfab? And how the PlayFab will handle the generated information?

Another question is whenever server(PlayFab) Scheduled Task generate a new data, Can I relay that data to all my connected clients without having my clients ping the server?

0 Likes 0 ·
brendan avatar image brendan ♦♦ Muhammad Roshaan Tariq commented ·

It's going to be extremely difficult for us to give you accurate advice without knowing the experience you're trying to create. If you could describe it in more detail, that would be helpful.

Whether you're using a real world map or not, that type of game does not change the global data at a high rate, for two reasons: Cost and replication issues. For the latter, since the data has to serve all players, it must be cached/sharded, so when you update anything in it, it takes time to propagate to all endpoints. What these games do is to have the definition of the spawns on the map baked in, and then use pseudo-random (so that the same inputs produce the same results, while appearing random over time) logic to decide what is available at any given time, using dedicated servers that respond to client requests for "what's at x, y, z".

So you can update that Title Data via Scheduled Tasks, but you need to design your data to contain all the changes for at least a day or two out, so it wouldn't make sense to update more than once per day. And you will need to use server-side logic to respond to client queries for what's available.

0 Likes 0 ·
Show more comments

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.