question

brendan avatar image
brendan asked

Energy and timers?

Question from a developer:

I'm making a game that has energy which is consumed by player actions and needs to regenerate over time. Also, those actions can be used to start construction of objects which are built over time, so I'd like timers as well. How can I implement these?

10 |1200

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

brendan avatar image
brendan answered

For energy, you can use a regenerating virtual currency (set the Recharge Rate on the VC in the Economy->Currencies tab in the Game Manager).

For timers, the way to do this would be by setting the timestamp for when construction was started in User Read Only Data, along with any modifiers (time buy-downs that players use on the thing being built). That way, you can check the server-authoritative time to ensure that the player can't cheat the countdown to completion.

10 |1200

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

Steve [not provided] avatar image
Steve [not provided] answered

Thanks Brendan!

So, if I use a regenerating VC as 'energy', is there a method with which I could use that if a player purchases a specific item, I can 'refill' said VC?

 

10 |1200

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

brendan avatar image
brendan answered

Yes - if an item in your catalog is a Bundle or Container, it can have Virtual Currency which is added to the player's balance. So, you could have a Bundle item which is what you sell in your in-game store and when it is purchased, the VC you specify as being in the bundle will be added. I would also recommend setting the UsagePeriod to 1 second, so that the bundle "host" doesn't hang out in the player's inventory. Using that, you can push the player over the regeneration limit for the VC, as well.

So, if a VC has an initial deposit of 25, a regeneration rate of 288 units per day (1 every 5 minutes), and a recharge max of 50, you could still have an item which grants the player 100 units if you wanted to. Their new balance at that point would be [current balance] + 100. Obviously, since they'd be over the recharge max at that point, they would stop regenerating until they were below 50.

Now, if you want an item that just sets the player to the recharge max, you'll want to add that as a consumable item and manage the set of the VC balance in Cloud Script. You would use these API methods to do that:

server.AddUserVirtualCurrency

server.SubtractUserVirtualCurrency (the balance is returned from AddUserVirtualCurrency, so just in case it goes over - and we have a backlog item for "SetUserVirtualCurrency", just so you know, but it isn't on the schedule right now)

server.ModifyItemUses

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

Dustin avatar image Dustin commented ·

Regarding the energy system, how would I implement this if I wanted each player to have a different max energy? For example, as you level up you will have a higher max energy. I am only seeing a global maximum amount in the dashboard. It would be helpful if there was a max amount of currency allowed on a per player basis.

0 Likes 0 ·
brendan avatar image brendan Dustin commented ·

I'd recommend posting this to the Feature Requests forum, so that others can vote it up if they like it. Alternately, if this is a key need for your title, we could talk about a custom dev contract to get this into our schedule sooner. Right now, one way would be to set the VC to the max for any player, store the actual player max in their read only data, and use Cloud Script to gate their use of VC, so that you can apply their max. Since a hacked client could call PurchaseItem directly though, it'd be best to talk through the details with us at devrel@playfab.com.

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.