I need to create a timer

Hi, I want to create a timer for items that expire in a user's inventory.
After these items expire, they disappear from the inventory. (The inventory is also based on UGS)

Could a script on Cloud Code help me do that to avoid a player cheating by manipulating device time?
Would that cause too much unnecessary usage at scale?

Is there some ready-made timer feature as in other similar services?
Or some other solution you would suggest?

Thank you.

1 Like

Hi Soleron,

That is a great use case. An inventory item that expires at a pre-determined time is an excellent example of using Cloud Code along with Economy. As you point out, this would be server authoritative to prevent client side exploitation.

Some of the Cloud Code Use Case examples show how to use Cloud Code with Economy, but we don’t have an example for exactly that use case. But, you’ve got me intriguied, so I’ll do some further investigation on this and let you know what I find.

Regarding the usage at scale, this will depend on how the cloud code is implemented, but I’m sure if cloud code is only touched on the creation and attempted use of the item it should be OK.

2 Likes

Hi Soleron,

I took a look at your use case, have created a sample project and can confirm that it works.

I used Cloud Code and Economy together to perform a sever authoritiative reward ticket creation and redemption mechanic.

Cloud Code issues reward tickets with a random reward value and expiry duration and drops them into the player’s Inventory managed by Economy. When the player attempts to redeem a ticket a second Cloud Code script retrieves the ticket from the player’s Invenory, checks the expiry date and incements the player’s currency balance by the correct amount if the ticket hasn’t expired.

I have attached a Unity Package file for you to check out. It contains the files you’ll need and a readme containing more details.

To run the sample:

  • Create a new Unity Project
  • Add the Authentication, Economy and Cloud Code UGS package definitions to your Package/manifest.json file
  • Connect your project to a Unity Dashboard project in Editor ‘Project Settings > Services’ page
  • Import the attached ‘Expiring_Items.unitypackage’
  • You will need to create a TICKET inventory item and a GOLD virtual currency in the Unity Economy dashboard (more details on these can be found in the project’s readme)
  • You will need to create two Cloud Code scripts in the Unity Cloud Code dashboard. The code for the GenerateRandomItem and RequestTicketReward scripts is in the Cloud Code folder of the attached project
  • Open the ‘Expiring Items’ scene
  • Set the Game display to a resolution similair to a phone e.g. Portrait 1125x2436 and hit Play.

I will build this out a bit further and pass it over to the Samples team to consider for inclusion in the Use Case Samples project.

I hope it helps.

7888297–1003885–Expiring_Items.unitypackage (2.31 MB)

4 Likes

Thank you very much!