question

Connor Price avatar image
Connor Price asked

Creating time based items

What I'm trying to accomplish is thus; when a player finishes gameplay, I analyze his play results via cloud script and then if granted, they will be given a chest that has a timer on it.

I figured the best way to approach this would be to save a multidimensional array into their internalData, [timeStamp_endDur, chestTier] and to then return this data for UI visuals on client.

The client would then have a cloudScript where it would get an array return from the server for their chest results and parse that into a UI visual for the timer counting down (i'll use a client counter and just use the server return as a check on its accuracy, rather than using it to adjust the timer because of server delay).

On timer being finished (in server check), their data will be moved from internal to their playerData.
When the chest is clicked, it will be the arrayValue in their playerData that is checked if it can be opened.

My question is, as I've been doing some research on this topic before diving right in is:

1) Has playfab created a built in method that can do as I have mentioned? I was looking into Item/containers and am not 100% sure if what I want can be achieved with that; as the chest rewards are RNG in an array of RNG based values.

2) Is the approach I am planning on taking correct? Im still learning Playfab syntax and best practices.

3) What is the best way to get accurate server time?

In one article, https://community.playfab.com/questions/8921/best-way-to-create-items-with-timers.html it's mentioned that you should "put a timestamp on the item instance (and then check it) via Cloud Script when the timer should start" (Brendan). What is the syntax to do this? I can't seem to find documentation on it.

It was also mentioned you could use "context.playStreamEvent.Timestamp", I tried this and got an error: "TypeError: Cannot read property 'Timestamp' of null\n

Or should I use, server.GetTime({}); as this is the only one I can get a proper return result from?

I appreciate any help,

Connor

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

Basically what you want is that an item will only be available after a specific time, is that correct? In that case, firstly, PlayFab does not have a built-in method for this right now, and, the approach you’re taking looks alright to me: save the chest rewards as Internal Data when they’re not available yet and move them to Player Data once they’re ready. And, it’s also possible for you to treat them as items and move them to the our built-in inventory instead, however, I am not sure whether that applies here without knowing more details of the chest rewards in your game, like what’s the range of the RNG values, how many total results will there be? Could you please share that?

Regarding getting server time, yes, in the CloudScript, you can use “server.GetTime()” to the current server time, or just use “new Date()”. Please note that PlayFab reports the current time in UTC, you may use standard offsets to adjust the local time on the client side.

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

Connor Price avatar image Connor Price commented ·

Thanks for the reply Citrus Yan,

I'm glad to know I'm going in the right direction.
I ended up going with new Date() also, I was running into issues with the format of server.GetTime() and incrementing it by X hours, whereas Date() has built in functions that makes that easy.
As for what the RNG values of my array looks like its:

//["type", min, max] * 5 (aside from bossKey/questKey)
var chestTiers_free = [
    [   //tier 1
        [["gems", 1, 2]], // * 5
        [["gold", 20, 25]],
        [["iron", 5, 10], ["copper", 50, 10], ["tin", 50, 10]],
        [["bossKey", 0, 1], ["questKey", 0, 1]]
    ],
    [   //tier 2
        [["gems", 3, 10]], //* 5
        [["gold", 75, 150]],
        [["iron", 25, 75], ["copper", 25, 75], ["tin", 25, 75]],
        [["sapphire", 3, 5], ["ruby", 3, 5]],
        [["bossKey", 0, 1], ["questKey", 0, 1]]
    ]
];			

I think it may be too complicated to achieve with the built in item system, but at the same time I've heard your item system has a lot of handy service disruption checks incase they lose internet mid purchase, etc. Whereas cloud script does not.

So, if there is a way to make this work, I'd love to implement it!

Thanks,

Connor

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Connor Price commented ·

What does "// * 5" mean? And, does "[["gold", 20, 25]]" mean that there are 6 types of gold for tier 1: ["gold20"],["gold21"],["gold22"],["gold23"], ["gold24"],["gold26"] ?

0 Likes 0 ·
Connor Price avatar image Connor Price Citrus Yan commented ·

// * 5 just means that the end value will be multiplied by 5.

Only 1 type for each arrayIndex:

arrayIndex = chestTiers_free[chestTier][i].length > 1 ? RandomNumberMax(chestTiers_free[chestTier][i].length) : 0;

heres some sample code to explain what I'm doing:

var chestTier = 1; //this int value will be passed to playerData from internalData when chest timer has finished
var arrayIndex = 0;
for(var i = 0; i < chestTiers_free[chestTier].length; i++)
{
	arrayIndex = chestTiers_free[chestTier][i].length > 1 ? RandomNumberMax(chestTiers_free[chestTier][i].length) : 0;
        var itemAmount = RandomNumberInbetween(chestTiers_free[chestTier][i][arrayIndex][1], chestTiers_free[chestTier][i][arrayIndex][2]);
        switch(chestTiers_free[chestTier][i][arrayIndex][0])
        {
            case "gems":
                itemAmount *= 5;
                server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GM", Amount: itemAmount});
                break;
            case "gold":
                itemAmount *= 5;
                server.AddUserVirtualCurrency({PlayFabID: currentPlayerId, VirtualCurrency: "GD", Amount: itemAmount});
                break;
        }
}
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.