question

jonathanjarri avatar image
jonathanjarri asked

Change VC's recharge maximum according to player's data

Hello everyone,

I'm using a virtual currency as stamina that recharges 1 point every 3 minutes, but I don't want to increase the stamina amount if it reached the maximum.

From what I learned from the documentation, this behaviour is supported thanks to "Recharge rate" and "Recharge maximum" field of a virtual currency. The problem is that thie "Recharge maximum" seems to be the same for all players, whereas it depends on the player's level in my case.

Is there a way to do what I want?

Thanks in advance for your answer.

Player Data
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

·
1807605288 avatar image
1807605288 answered

My immediate answer for you is "not out of the box". But you could still implement this feature as a calculation of multiple VC's.

Step 1, create the recharging VC, which (always) has a max of WAAAY beyond what your actual players' max values will ever be, for the life of your game. (This part is important).

So, basically, if 1 stamina represents 1 minute, set a maximum recharge at like... a year. Lets round up, and say 600,000 is the max stamina for every player, and every player STARTS with max, and go from there.

Have a second vc, which is the "actual" max, for this player, called maxStamina. This is not a regenerating currency.

SO, there's a hard coded constant:
MAX_REGEN = 600k
And Two variables:
stamina = (starts at 600k)
maxStamina = (1 hour would be 60, so let's assume that is your initial, and players can buy more)

Finally, calculations:
int spentStamina = MAX_REGEN - stamina;
int remainingStamina = maxStamina - spentStamina;
bool canPurchase = remainingStamina > 0;

So basically, "maxStamina" is how much you're allowed to spend, out of your ridiculously but invisibly large pool. Unfortunately you WILL have to do your purchase logic within a Cloud Script, because our default purchase logic will test that 600K is > 0, and that's the wrong calculation.

Recap:
What you're specifically asking for isn't supported, but the same effect can be delivered with multiple currencies, and a bit of Cloud Script calculations.

10 |1200

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

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.