Page 1 of 1
Custom inventory and quest items count
Posted: Tue Mar 28, 2023 10:36 am
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!!
Re: Custom inventory and quest items count
Posted: Tue Mar 28, 2023 1:23 pm
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:
Re: Custom inventory and quest items count
Posted: Tue Mar 28, 2023 8:33 pm
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!
Re: Custom inventory and quest items count
Posted: Tue Mar 28, 2023 8:34 pm
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?
Re: Custom inventory and quest items count
Posted: Tue Mar 28, 2023 8:52 pm
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:
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
Re: Custom inventory and quest items count
Posted: Tue Mar 28, 2023 9:56 pm
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!!
Re: Custom inventory and quest items count
Posted: Tue Mar 28, 2023 11:03 pm
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.
Re: Custom inventory and quest items count
Posted: Wed Mar 29, 2023 9:25 pm
by lupiyo
Thanks! Work perfect.
Re: Custom inventory and quest items count
Posted: Wed Mar 29, 2023 9:43 pm
by Tony Li
Great! Glad to help.