Custom inventory and quest items count
Custom inventory and quest items count
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!!
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
Hello,
I recommend writing a C# method. Given an item ID, return the quantity. Example:
Then register the method with Lua. Example:
and add an entry in a Custom Lua Function Info asset.
Finally check the method in your conversation. Example dialogue entry:
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];
}
Code: Select all
void OnEnable()
{
Lua.RegisterFunction(nameof(GetItemQuantity), this, SymbolExtensions.GetMethodInfo(() => GetItemQuantity(0)));
}
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
- Quest > Entry 1: "[lua(GetItemQuantity(42))] / 3 Bananas Collected"
- Video Tutorial: How to Connect Your Own Code to Lua
- Manual
Re: Custom inventory and quest items count
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!
I did what you seggested (or tried to) but nothing hapens. At least i get some errors.
Everything is attached.
Thanks!
- Attachments
-
- CustomFunctionLua.JPG (95.93 KiB) Viewed 330 times
-
- CustomFunctionLua LOG.JPG (106.99 KiB) Viewed 330 times
-
- CustomFunctionLua 4.JPG (24.44 KiB) Viewed 330 times
-
- CustomFunctionLua 3.JPG (33.01 KiB) Viewed 330 times
-
- CustomFunctionLua 2.JPG (27.33 KiB) Viewed 330 times
Re: Custom inventory and quest items count
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
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
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
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
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!!
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
If you have a C# method that changes the inventory amount, add this line of code to it:
This will update the quest UIs.
Code: Select all
DialogueManager.SendUpdateTracker();
Re: Custom inventory and quest items count
Thanks! Work perfect.
Re: Custom inventory and quest items count
Great! Glad to help.