question

Santiago Rollheiser avatar image
Santiago Rollheiser asked

Regenerate Currency every 15 Min Over Unreal Engine (Blueprint)

Hi, im trying to implement a casual game logic Lives like Candy Crush.

The users need 5 points of energy to can start the game. This energy need autoregenerate 5 points each 15 min.

I was check this example here:
https://github.com/PlayFab/PlayFab-Samples/tree/master/Recipes/RegeneratingCurrency

Using the example over JavaScript work well like expect, but i need know what is the way to do that over Blueprint in Unreal Engine, all examples are using Unity or C++.

The documentation no have examples related Blueprints or Unreal.

Now only have the logic to add and remove amounts over my others currency like gems and coins, but for the energy i need make that mention before.

I was make this CloudConfig followig the example in java Script:

handlers.RegenerateEnergy = function(args) {
	// get the calling player's inventory and VC balances
	var GetUserInventoryRequest = {
        "PlayFabId": currentPlayerId
    };


    var GetUserInventoryResult = server.GetUserInventory(GetUserInventoryRequest);
	var userInventory = GetUserInventoryResult.Inventory;
	var userVcBalances = GetUserInventoryResult.VirtualCurrency;
	var userVcRecharge = GetUserInventoryResult.VirtualCurrencyRechargeTimes;


	// make sure the player has > 0 lives before proceeding. 
	try
	{
		if(!CheckLives(userVcBalances))
		{
			throw "No lives remaining. Purchase additional lives or wait: " + userVcRecharge[ENERGY_CURRENCY_CODE].SecondsToRecharge + " seconds.";
		}
	}
	catch(ex)
	{
		return JSON.stringify(ex);
	}
};




function CheckLives(vcBalnces)
{
	if(vcBalnces != null && vcBalnces.hasOwnProperty(ENERGY_CURRENCY_CODE) && vcBalnces[ENERGY_CURRENCY_CODE] > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}


function AddVc(vcBalnces, code, qty)
{ 
	if(vcBalnces != null && vcBalnces.hasOwnProperty(code) &&  vcBalnces[code] > 0)
	{
		vcBalnces[code] += qty;
	}


	var AddUserVirtualCurrencyRequest = {
	    "PlayFabId" : currentPlayerId,
	    "VirtualCurrency": code,
	    "Amount": qty
    };
    var AddUserVirtualCurrencyResult = server.AddUserVirtualCurrency(AddUserVirtualCurrencyRequest);
}


function SubtractVc(vcBalnces, code, qty)
{
	if(vcBalnces != null && vcBalnces.hasOwnProperty(code) &&  vcBalnces[code] > 0)
	{
		vcBalnces[code] -= qty;
	}


	var SubtractUserVirtualCurrencyRequest = {
	    "PlayFabId" : currentPlayerId,
	    "VirtualCurrency": code,
	    "Amount": qty
    };


    var SubtractUserVirtualCurrencyResult = server.SubtractUserVirtualCurrency(SubtractUserVirtualCurrencyRequest);
}

But now need help to do the rest...

What is the way to call this and make the regeneration?

Thx

unreal
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

Currently we don’t have an example for Unreal Engine, however, the basic ideas for Unreal are pretty much the same as in our Unity Sample. If you take a closer look at its core logic in here: PlayFab-Samples/RegeneratingCurrency.cs at master PlayFab/PlayFab-Samples (github.com), you’ll find that it mainly does the following:

  1. Authenticate with PlayFab, it calls LoginWithCustomID to login.
  2. Get the player’s inventory, it calls GetUserInventory to get the player’s inventory and save such info locally.
  3. Try buying lives, it calls PurchaseItem to try to buy lives with VC
  4. Battle: it mimics the gameplay via the execution of CloudScript, all the logic are already implemented and you can find them in here: PlayFab-Samples/CloudScript.js at master PlayFab/PlayFab-Samples (github.com)

And, regarding energy regeneration, it’s automatically done by PlayFab if you set the recharge rate for a specific VC and its configuration is also mentioned in our README notes (Preparation -> Step 4). Basically, what you need to do for your Unreal Project is to finish the Preparation steps mentioned here: https://github.com/PlayFab/PlayFab-Samples/tree/master/Recipes/RegeneratingCurrency#preparation, and implement the similar logic from the aforementioned Unity Project.

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

Santiago Rollheiser avatar image Santiago Rollheiser commented ·

Hi @Citrus Yan, i have all steps done on playfab side like the example with some modifications over the time to regenerate and the name of the VC.

After that make some mopdifications over de cloudscript deleting the battle part because is not needed for me.

But on unreal i cant find the variable VirtualCurrencyRechargeTimes to make this:

		VirtualCurrencyRechargeTime rechargeDetails;		if(result.VirtualCurrencyRechargeTimes.TryGetValue(lvCode, out rechargeDetails))		{			string textOut = string.Empty;			if(lvBalance < rechargeDetails.RechargeMax)			{				this.nextFreeTicket = DateTime.Now.AddSeconds(rechargeDetails.SecondsToRecharge);				textOut = string.Format("Next life in: {0:n0} seconds", rechargeDetails.SecondsToRecharge);				this.livesRegen.text = textOut;				this.areLivesCapped = false;			}			else			{				textOut = string.Format("Lives only regenerate to a maximum of {0}, and you currently have {1}.", rechargeDetails.RechargeMax, lvBalance);				this.livesRegen.text = string.Empty;				this.areLivesCapped = true;			}			Debug.Log(textOut);
0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Santiago Rollheiser commented ·

VirtualCurrencyRechargeTimes is returned by GetUserInventory:

https://docs.microsoft.com/en-us/rest/api/playfab/client/player-item-management/getuserinventory?view=playfab-rest#getuserinventoryresult,

in Unreal Blueprint, you can access it via the "Break ClientGetUserInventoryResult" node:

0 Likes 0 ·
Santiago Rollheiser avatar image Santiago Rollheiser Citrus Yan commented ·

Yes, already have that when catch the amount of the VC and store that on a local variable. But i dont know what is the Pin out for VirtualCurrencyRechargeTimes.

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.