Can I run lua script when a quest begins?
-
- Posts: 4
- Joined: Wed Dec 11, 2024 9:09 am
Can I run lua script when a quest begins?
I'd like to run some lua script when a quest begins. I think I can probably do this by attaching script to the dialog manager that has a OnQuestStateChange method... but I was wondering if there is a way to just specify Lua script to run in the dialog database somehow?
Re: Can I run lua script when a quest begins?
Hi,
Yes -- you can add a custom Text field to your quest template. Put the Lua code in there.
Then add a script with an OnQuestStateChange method to the Dialogue Manager. When a quest state changes to Active, check if the quest has the Lua code field. If so, run the Lua code.
For example, template:
Quest:
Code:
You can also do the same thing to give quest rewards. For example, add a custom field named RewardCode. When the quest goes into the Success state, look up this field and run it. You could have it call C# methods to give XP, give items, etc. (Register your C# methods with Lua.)
Yes -- you can add a custom Text field to your quest template. Put the Lua code in there.
Then add a script with an OnQuestStateChange method to the Dialogue Manager. When a quest state changes to Active, check if the quest has the Lua code field. If so, run the Lua code.
For example, template:
Quest:
Code:
Code: Select all
void OnQuestStateChange(string questName)
{
if (QuestLog.IsQuestActive(questName))
{
var startCode = DialogueLua.GetQuestField(questName, "StartCode");
Lua.Run(startCode);
}
}
-
- Posts: 4
- Joined: Wed Dec 11, 2024 9:09 am
Re: Can I run lua script when a quest begins?
Hi again,
Ah, nice - I hadn't thought of using a text field and running the code myself. Thanks for the quick response! Kind regards,
Andy
Ah, nice - I hadn't thought of using a text field and running the code myself. Thanks for the quick response! Kind regards,
Andy
Re: Can I run lua script when a quest begins?
Happy to help!