question

Konstantin Kokhno avatar image
Konstantin Kokhno asked

How I can make the Rent System?

Hi, i need to make rent system, when player purchase some item for specific time.

Еechnical task:

1) the player can rent an item for any time for which he has enough money, given the fact that every hour is worth a certain amount.

2) the player also can in the store to buy the rental time, if the item has already been purchased

3) if player rent item for a long time, for exampe for a year, it is not make thousands of items in inventory.

My algorithm:

* Make stackable item with consume time by 1 hours

* add this to store

* player can purchase, by transaction (PlayFabClientAPI.StartPurchase), any items count, that represents desired time. (example 1 day is 24 items)

Problem: if player purchase for example 24 items, it consumed whole stack by one hour, because stack is not add "expires time".

My thoughts:

Maybe i can add "expires time" when item is purchase and stacked?

Maybe i need to use another approach?

10 |1200

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

franklinchen avatar image
franklinchen answered

For the bugs we found in this thread have been fixed:

1. Stackable and time group name enabled items get stacked but expiration time don't add up when there is at least one item in the player's inventory

2. Stackable items don't get stacked and expiration time doesn't add up according to time group name settings when inventory is empty

1 comment
10 |1200

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

Konstantin Kokhno avatar image Konstantin Kokhno commented ·

Thanks very much.

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

Hi, it’s very convenient to make a Rent System using PlayFab, which only needs a minor variation to your approach. In the editor of a Catalog Item, for instance, the Item is called “ItemForRent1”. Type “ItemForRent1” in the “Time group name” field at the right bottom corner in the CONSUMABLE Configuration:

This way enables the same usage period group for the item, which means that if you bug one and then immediately buy the other, you would have an expiration time of 2 hours out. For example, I bought triple times and the inventory shows that I have 3 hours usage time:

You can try it out in your title, any issues please let us know:)


consumable.jpg (22.7 KiB)
10 |1200

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

Konstantin Kokhno avatar image
Konstantin Kokhno answered

thanks for answer. I tune my item, and but when i try to purchase it i have following error:

HTTP/1.1 409 Conflict

My item:

Whether i purchase one or three items, i has following error:

ConfirmPurchase error: HTTP/1.1 409 Conflict

The unity test purchase code:

public void MakePurchase()
		{
			PlayFabClientAPI.StartPurchase(new StartPurchaseRequest {
					AuthenticationContext = LoginService.AuthenticationContext,
					CatalogVersion = m_CatalogVersion,
					Items = new List<ItemPurchaseRequest> {
						new ItemPurchaseRequest {
							ItemId = m_ItemId,
							Quantity = m_Quantity
						}
					},
					StoreId = m_StoreId
				},
				startPurchRes => {
					PlayFabClientAPI.PayForPurchase(new PayForPurchaseRequest {
							AuthenticationContext = LoginService.AuthenticationContext,
							Currency = m_Currency,
							OrderId = startPurchRes.OrderId,
							ProviderName = "Title" + PlayFabSettings.TitleId
						},
						payRes => {
							PlayFabClientAPI.ConfirmPurchase(new ConfirmPurchaseRequest {
									AuthenticationContext = LoginService.AuthenticationContext,
									OrderId = payRes.OrderId
								},
								confRes => { Debug.Log($"Is purchased", transform); },
								confErr => {
									Debug.LogError($"ConfirmPurchase error: {confErr.ErrorMessage}",
										transform);
								});
						},
						payErr => {
							Debug.LogError($"PayForPurchase error: {payErr.ErrorMessage}", transform);
						});
				},
				err => { Debug.LogError($"PayForPurchase error: {err.ErrorMessage}", transform); });
		}

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.

Konstantin Kokhno avatar image Konstantin Kokhno commented ·

in addition:
this way will add in my inventory three items with expires one minute(one minute for test)

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Konstantin Kokhno commented ·

Hi,

I see that you are using StartPurchase, PayForPurchase, ConfirmPurchase to implement the purchase process, looks like you are doing a Non-receipt payment processing. However, at line 19 in your code, you passed “Title + your_title_id” to the ProviderName property, which confuses me. The ProviderNames are supposed to Correspond to payment providers such as Facebook, PayPal or Steam (Xsolla is an exception and is explained in the last part of the doc) which need to be installed on the Add-ons page first. Therefore, the 409 Conflict error you are encountering might derive from this.

Moreover, PurchaseItem buys a single item with virtual currency, it’s a simpler and convenient way to test.

I tried to reproduce your issue that three items are not stacked and usage time not merged in inventory, however, my title worked fine:

Can you provide your title id to investigate? Thanks.

0 Likes 0 ·
inventory.jpg (19.1 KiB)
Konstantin Kokhno avatar image Konstantin Kokhno Citrus Yan commented ·

The fact is that my way can purchase items correctly, when time group name is empty.

Mainly, why i use StartPurchase, PayForPurchase, ConfirmPurchase is, as i know it is only way to purchase thousand items without thousand invocations to PlayFab. (it need when user want rent item for thousand hours)

I use PurchaseItem in old scripts, when need to purchase one item. PurchaseItem can not purchase for example thousand items in one iteration - it will need thousand invocations. Or i wrong?

0 Likes 0 ·
Show more comments
Konstantin Kokhno avatar image
Konstantin Kokhno answered

Exactly, purchasing items fails when time group name is filled in.

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.

Citrus Yan avatar image Citrus Yan commented ·

Did it ever succeed? I might need to reproduce it and discuss with the team.

0 Likes 0 ·
Konstantin Kokhno avatar image Konstantin Kokhno Citrus Yan commented ·

It is never succeed. Maximum effect is grant 3 items, not stack, when i try purchase 3 items in stack - completely unexpected behavior and 409 Conflict Error. PlayfabID is 8D72.
Test player is player is 5302DFC40BF26681
Test Itemid is RPK74 in main catalog

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Konstantin Kokhno commented ·

Hi, I can reproduce it in my title. However, I get the 409 error on the first few tests, then it works fine when I test it again several times. I will discuss with the team later. Any updates will let you know.

0 Likes 0 ·
Show more comments
Konstantin Kokhno avatar image
Konstantin Kokhno answered

ok, thanks, it is very important for our project

10 |1200

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

Konstantin Kokhno avatar image
Konstantin Kokhno answered

A related question arose:

My CloudScript must provide loot for user, for example RPK74 for year or month randomly.

How to use a CloudScript to immediately grant thousands of items, without thousands invocations to PlayFab?

It is not StartPurchase, PayForPurchase, ConfirmPurchase...

GrantItems can grant only one item in stack.

If i make bundle, then it means, than i can not grant random(1, 1000) items stack.

One way, i see, is GetPlayerInventory then ModifyItemUses or GrantItem. Is there a way to do this in one invocation?
Moreover, if i need grant 100 items it need 201 invocations (get items in inventory, check it all, grant all items and/or add items to stack O(2N+1)) , instead of one invocation such as GrantItems. Not to mention the onalysis cycle

10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

@Konstantin Kokhno Hi Konstantin, sorry for this late reply. I am answering your last rely here due to character limit:

>>How to use a CloudScript to immediately grant thousands of items, without thousands invocations to PlayFab?

For now PlayFab does not support granting thousands of items with one invocation, however, there is a way to significantly cut down invocations if we are stilling talking about the Rent System in our last conversation. For instance, let’s say the minimum rent time for RPK74 is 1 minute, go ahead and define more RPK74 with the same time group name and consumable time with exponential growth (2, 4, 8, 16, 32, …, minutes), the key idea is to provide more rent time granularity. Now let’s say the player wants to rent it for a year(525600 minutes), you’ll need to call GrantItems four times(2^19 + 2^10 + 2^8 + 2^5), of course, you can directly set an item with 1 year’s rent time. You get the idea.

Moreover, making a feature request to enable granting multiple items with one call would be a direct solution: https://community.playfab.com/spaces/24/index.html

>> One way, I see, is GetPlayerInventory then ModifyItemUses or GrantItem. Is there a way to do this in one invocation?

First of all, the “GrantItems” you mentioned means GrantItemsToUser and“100 items” you talked about are 100 different items, is that right? You are saying that you need 201 invocations when granting 100 items, however, I think that you will need 102 invocations( O(N+2) ). Call GetPlayerInventory, GrantItemsToUser once and call ModifyItemUses 100 times to add uses for each item. And, one thing I noticed is that expiration time will not be added accordingly when you use ModifyItemUses to add uses, which might affect your rent system.

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.

Konstantin Kokhno avatar image Konstantin Kokhno commented ·

As i understand, it means, that i need duplicate all settings for RPK74 in all items (for 2,4,8,16..., minutes), which may be many.

Many information in many items is too many information and traffic in initial requests...

And if i need to change KPK74, i will change all items (moreover some designers, who can not understand this can change only one RPK74 and it will errors occured).

By the way, what did the team say about the unexpected behavior with time group discussed earlier?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Konstantin Kokhno commented ·

Yes, you are right, it will surely generate a large amount of duplicate information. However, based on the current situation, I think this is a trade-off you have to make between duplicate information for item settings and larger amount of invocations.

About the time group discussed earlier, I've already filed a bug for the engineering team to investigate, any updates will keep you informed. By the way, I happened to notice that the quantity is limited to 1-25 in StartPurchase API, hence you cannot buy a large number of items in a single purchase, which might affect your rent system.

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.