Custom inventory and quest items count

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
lupiyo
Posts: 13
Joined: Sun Mar 26, 2023 9:27 pm

Custom inventory and quest items count

Post by lupiyo »

Hello!

Thanks for replaying my last question, but this is a new topic, so i created a new one.

I'm trying to link my inventory system to the quest items. following the tutorial it was not so clear for me what I have to do. I saw in other topics that you sugested to create a variable in te database, but I even could find where I can create It.

My idea is to put an IF in my script to call a function from Dialog System that updates the counter, but for this there are few points:
1- How the system will know if the items is correct?
2- How the system counts it?

The example with crates was ver far away from what I have here. My inventory is home made (lol) i used 2 vectors of int (item ID / quantity) to store them by index. Do you have any tutorial or examples to handle this, please?

Thanks!!
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom inventory and quest items count

Post by Tony Li »

Hello,

I recommend writing a C# method. Given an item ID, return the quantity. Example:

Code: Select all

public double GetItemQuantity(double itemID)
{
    return Inventory[(int)itemID];
}
Then register the method with Lua. Example:

Code: Select all

void OnEnable() 
{
    Lua.RegisterFunction(nameof(GetItemQuantity), this, SymbolExtensions.GetMethodInfo(() => GetItemQuantity(0)));
}
and add an entry in a Custom Lua Function Info asset.

Finally check the method in your conversation. Example dialogue entry:
  • Description: Show this node if player has fewer than 3 bananas (item ID 42).
  • Dialogue Text: "Sorry, you don't have enough bananas."
  • Conditions: GetItemQuantity(42) < 3
You can also use the [lua(code)] markup tag in quest text and dialogue text:
  • Quest > Entry 1: "[lua(GetItemQuantity(42))] / 3 Bananas Collected"
More details:
lupiyo
Posts: 13
Joined: Sun Mar 26, 2023 9:27 pm

Re: Custom inventory and quest items count

Post by lupiyo »

Hello, thank you for the fast reply!

I did what you seggested (or tried to) but nothing hapens. At least i get some errors.
Everything is attached.

Thanks!
Attachments
CustomFunctionLua.JPG
CustomFunctionLua.JPG (95.93 KiB) Viewed 298 times
CustomFunctionLua LOG.JPG
CustomFunctionLua LOG.JPG (106.99 KiB) Viewed 298 times
CustomFunctionLua 4.JPG
CustomFunctionLua 4.JPG (24.44 KiB) Viewed 298 times
CustomFunctionLua 3.JPG
CustomFunctionLua 3.JPG (33.01 KiB) Viewed 298 times
CustomFunctionLua 2.JPG
CustomFunctionLua 2.JPG (27.33 KiB) Viewed 298 times
lupiyo
Posts: 13
Joined: Sun Mar 26, 2023 9:27 pm

Re: Custom inventory and quest items count

Post by lupiyo »

There are 2 prints almost indentical, just the condition changes and this is a doubt that i have, which sintax is correct, please?
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom inventory and quest items count

Post by Tony Li »

Hi,

The first syntax is correct for the Conditions field. (But see important note below about function name.)

The other syntax -- [lua(code)] -- should only be used in text such as Entry 1 or Dialogue Text.

Please make sure to read the online manual section and/or watch the video. Your method should use "double" number types, not "int". In the example I posted above, the method uses double and casts it to (int) in the C# code.

Also make sure you've added your script to the scene. (See the video tutorial for important details.)

Also note that Lua.RegisterFunction() registers the function under a specific name. In your code, you're defining a function "GetQtdByID" available to Lua. But in your Conditions field you're trying to check "GetQuantityByID" which is not registered. Try changing your Conditions to:

Code: Select all

GetQtdByID(13) >= 2
Then temporarily set the Dialogue Manager's Other Settings > Debug Level to Info. When you play, look in the Console for a line like:

Dialogue System: Registering Lua function GetQtdByID

If you see this line, the Lua function has been unregistered and is no longer available to Conditions:

Dialogue system: Unregistering Lua function GetQtdByID
lupiyo
Posts: 13
Joined: Sun Mar 26, 2023 9:27 pm

Re: Custom inventory and quest items count

Post by lupiyo »

Many thanks! Sorry if my questions are very simple hahah, but I figured out that I could change drom double to int whenever i wanted. But everything is working now, thank you!!

I have another problem, on the crate example you put the "update" in a Dialog system trigger on the crate, and add the increment on action On Use. The thing is, I have 2 kind of drops, one that goes directly to my inventory (array) and the other that drop on the ground and then i pick it. The On Use cover these cases?
Everytime i pick the item, the quest counter on screen doesnt changes, but I can deliver! It reaches the condition to deliver.

I didn't have the opportunite (or time) to see quests that kill X number of monsters, but I think that it is a matter of understand all these triggers right?

Thank you!!
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom inventory and quest items count

Post by Tony Li »

If you have a C# method that changes the inventory amount, add this line of code to it:

Code: Select all

DialogueManager.SendUpdateTracker();
This will update the quest UIs.
lupiyo
Posts: 13
Joined: Sun Mar 26, 2023 9:27 pm

Re: Custom inventory and quest items count

Post by lupiyo »

Thanks! Work perfect.
User avatar
Tony Li
Posts: 21684
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom inventory and quest items count

Post by Tony Li »

Great! Glad to help.
Post Reply