This post explains how to set it up.
Let's say you have a C# function named GiveXP() that gives experience points to the player. You've already registered the C# function with Lua (video).
When the player completes a quest, you'd like to call GiveXP(). To do this, create a custom field for the Lua code. In the screenshot below, the quest has a custom field named "Reward Script":
The last step is to run Reward Script's Lua code when the player completes the quest. Add a script to the Dialogue Manager that has an OnQuestStateChange() method. In this method, check if the quest was completed. If so, run the Reward Script code. Example method:
Code: Select all
void OnQuestStateChange(string quest)
{
if (QuestLog.IsQuestSuccessful(quest))
{
Lua.Run(DialogueLua.GetQuestField(quest, "Reward Script").asString);
}
}