Page 1 of 1

Quest Reward

Posted: Sat Dec 05, 2015 3:03 pm
by r3nrohan
I have a script to record variables and I want to manipulate those variables after quest is finished, I need help

Re: Quest Reward

Posted: Sat Dec 05, 2015 5:26 pm
by Tony Li
Hi,

Does your script record C#/UnityScript variables, Dialogue System Lua variables, or some other type of variable?

How are you finishing the quest?

In most cases, you can use Lua. Here's how:

If the quest finishes in a conversation -- for example, when you give quest items to an NPC -- you can set Lua variables in the Script field. If you're recording C# variables, you can register a function with Lua.

The same applies if the quest finishes through a trigger such as Quest Trigger, Dialogue System Trigger, or Condition Observer. Put your Lua code in the Lua Code field.

For example, say you have a script to keep track of your character's experience points (XP). Register a Lua function called something like "GiveXP". Say the quest finishes during a conversation with an NPC. You can set the NPC's dialogue entry to:
  • Dialogue Text: "Great job! Thanks!"
  • Script:

    Code: Select all

    GiveXP(50);
    Variable["Alert"] = "Gained 50 XP!";
    Quest["Some_Quest"].State = "success"
Your C# script might have some code that looks like this:

Code: Select all

public class PlayerLevel : MonoBehaviour {

    public int xp;

    void OnEnable() {
        Lua.RegisterFunction("GiveXP", this, typeof(PlayerLevel).GetMethod("GiveXP"));
    }

    void OnDisable() {
        Lua.UnregisterFunction("GiveXP");
    }

    public void GiveXP(double amount) { //<--Numbers must be doubles.
        // Your code here to award XP. For example:
        xp += (int) amount;
    }
}