Include questing

What it does
This include file makes designing quests easier.

Important
this include file uses the nw_i0_tool include file. When you use my include file and want to use nw_i0_tool as well, you don't need to add the line #include "nw_i0_tool" to use the functions from that file. If you do put that line in your script, the compiler will give a warning.

Send comment, questions and suggestions to wim_haeck@hotmail.com or send me a message on the bioware forums (username: thadeus).

I have a module which uses this system. If you want to take a look at it, send me a message.

The file itself
//:://///////////////////////////////////////////// //:: thadeus' Questing And Journal Setting Functions //:: INCLUDE_QUESTING //::////////////////////////////////////////////// /*   This include file contains all functions to set the state of a quest and the appropriate journal entry. //::////////////////////////////////////////////// //:: Created By: Wim "thadeus" Haeck //:: Created On: July 25, 2002 //:: Send comment or suggestions to wim_haeck@hotmail.com or send me a message //:: on the bioware forums (username: thadeus). //::////////////////////////////////////////////// //::////////////////////////////////////////////// // GENERAL COMMENT - READ THIS BEFORE USING //::////////////////////////////////////////////// /*   As a general convention the quest state equals the number of the entry of    the journal. This way, setting the next state in the quest can be used to   automaticaly set the journal to the right level. The following quest states are defined: 0 = an unassigned quest 1,...,999 = a quest that has been assigned and has advanced to a higher state, I suppose no quest will have more than 999 journal entries. 1000 = a completed quest The quest state is always the number of the journal entry, the only exception is the journal entry of the finished quest (which can be any   number you wish). Examples of quest states: 1. a linear quest, eg: main quest NWN chapter 1 0 = not assigned 1 = just assigned "find 4 creatures" 2 = found 1 creature 3 = found 2 creatures 4 = found 3 creatures 5 = found 4 creatures - this is the final entry 2. quest with multiple ways of completing a state, eg: get in prison (peninsula district) 0 = not assigned 1 = just assigned "get in prison" 2 = get key (set if you speak to the right person) 3 = got key (won't happen if state 2 isn't set) 4 = got in prison with key 5 = got in prison through tunnel, have key but did not use it           6 = got in prison through tunnel, didn't even know about a key 7 = killed intellect devourer Every quest must have a unique identifier called the QUEST_ID, this is a   string which will be used to generate the names of various variables in    which information will be stored. The tag of every quest in the journal should always be of the form "JOURNAL_" + QUEST_ID. When you pay attention to this, all of the underlying functions should function normally. There is no checking whatsoever if the object oPlayer is a PC, the user must make sure that this object is a PC. This is important since this object will be used to set the journal entry. // IMPORTANT: this include file uses the nw_i0_tool include file. When you // use my include file and want to use nw_i0_tool as well, you don't need // to add the line #include "nw_i0_tool" to use the functions from that // file. If you do put that line in your script, the compiler will give // a warning. //::////////////////////////////////////////////// // DEFINING A FEW IMPORTANT CONSTANTS //::////////////////////////////////////////////// int QUEST_UNASSIGNED = 0; // an unassigned quest int QUEST_COMPLETED = 1000; // a completed quest //::////////////////////////////////////////////// // FUNCTIONS //::////////////////////////////////////////////// int GetQuestState(string QUEST_ID); // Returns the current quest state int GetQuestAssigned(string QUEST_ID); // Returns TRUE if the quest has been assigned and not completed // Returns FALSE if the quest has been completed or not assigned at all int GetQuestUnassigned(string QUEST_ID); // Returns TRUE if the quest has not been assigned // Returns FALSE if the quest has been assigned or completed int GetQuestCompleted(string QUEST_ID); // Returns TRUE if the quest has been completed void GiveQuestXP(object oPlayer, string QUEST_ID); // Gives the players the XP associated with the quest void SetQuestState(object oPlayer, int QUEST_STATE, string QUEST_ID); // Sets the quest to the required state void SetQuestNextState(object oPlayer, string QUEST_ID); // Sets the quest to the next state (the state is incremented by one) void SetQuestCompleted(object oPlayer, int JOURNAL_NUMBER, string QUEST_ID); // Sets the quest to completed and the journal to the final entry with // number JOURNAL_ID // See the comment within each function for more details //::////////////////////////////////////////////// // FUNCTION IMPLEMENTATION //::////////////////////////////////////////////// int GetQuestState(string QUEST_ID) /*   QUEST_ID = the ID of the quest Returns the current quest state of the quest given by QUEST_ID. This function can be used to check the quest state so that certain events are fired (eg. an ambush like the assassins in chapter 1) or to allow a   certain dialogue line in a conversation file. {   string QUEST_STRING = "QUEST_" + QUEST_ID; // the name of the variable in which the quest state will be stored return (GetLocalInt(GetModule,QUEST_STRING)); // return the value stored in the variable with name QUEST_STRING } int GetQuestAssigned(string QUEST_ID) /*   QUEST_ID = the ID of the quest Returns TRUE if the quest has been assigned and not completed. Returns FALSE if the quest has been completed or not assigned at all. {   int CURRENT_STATE = GetQuestState(QUEST_ID); // Retrieve the current state of the quest if ((CURRENT_STATE == QUEST_UNASSIGNED) || (CURRENT_STATE == QUEST_COMPLETED)) // if the quest is unassigned or completed, return FALSE {       return FALSE; }   return TRUE; } int GetQuestUnassigned(string QUEST_ID) /*   QUEST_ID = the ID of the quest Returns TRUE if the quest is not assigned Returns FALSE if the quest has been assigned or completed {   int CURRENT_STATE = GetQuestState(QUEST_ID); // Retrieve the current state of the quest if (CURRENT_STATE != QUEST_UNASSIGNED) // if the quest is not unassigned (this is assigned or completed), //return FALSE {       return FALSE; }   return TRUE; } int GetQuestCompleted(string QUEST_ID) /*   QUEST_ID = the ID of the quest Returns TRUE if the quest has been completed Returns FALSE if the quest has not been completed {   int CURRENT_STATE = GetQuestState(QUEST_ID); // Retrieve the current state of the quest if (CURRENT_STATE != QUEST_COMPLETED) // if the quest is not completed, return FALSE {       return FALSE; }   return TRUE; } void GiveQuestXP(object oPlayer, string QUEST_ID) /*   oPlayer = this must be a PC    QUEST_ID = the ID of the quest Gives the players the XP associated with the quest. {   string JOURNAL_STRING = "JOURNAL_" + QUEST_ID; // Name of the journal category in which the journal entries of the // quest are stored int QUEST_XP = GetJournalQuestExperience(JOURNAL_STRING); // Get the XP   RewardPartyXP(QUEST_XP,oPlayer,TRUE); // Give the XP } void SetQuestState(object oPlayer, int QUEST_STATE, string QUEST_ID) /*   oPlayer = this must be a PC    QUEST_STATE = the quest state you want to set QUEST_ID = the ID of the quest This function sets the quest state of the quest given by QUEST_ID to the state given by QUEST_STATE. The journal is set then to the QUEST_STATE. If the current state is the one to be set, if the state to be set is lower than the current state or if the quest has been completed, nothing will happen. BEWARE: NO BACKSETTING IS POSSIBLE, design quests so that no quest must be   set to a lower state. This function can be used to set the state to a particular value when multiple ways of reaching a goal are possible. {   string QUEST_STRING = "QUEST_" + QUEST_ID; // the name of the variable in which the quest state will be stored string JOURNAL_STRING = "JOURNAL_" + QUEST_ID; // Name of the journal category in which the journal entries of the // quest are stored int CURRENT_QUEST_STATE = GetQuestState(QUEST_ID); // retrieve the current quest state if (!(GetQuestCompleted(QUEST_ID)) && !(CURRENT_QUEST_STATE >= QUEST_STATE)) // the quest may not be completed and the current quest state may not be       // greater or equal the one to be set {       SetLocalInt(GetModule,QUEST_STRING,QUEST_STATE); // Setting the new state AddJournalQuestEntry(JOURNAL_STRING,QUEST_STATE,oPlayer); // Adjusting the journal accordingly } } void SetQuestNextState(object oPlayer, string QUEST_ID) /*   oPlayer = this must be a PC    QUEST_ID = the ID of the quest This function sets the quest state of the quest given by QUEST_ID to the next state. The journal is set to the next entry. When the quest has been completed, nothing happens. This is a function that can be used for a entirely linear quest, still: care must be taken when using this function since it is possible for a certain (repeating) event to increase the state multiple times! I recommend using the SetQuestState function. {   string QUEST_STRING = "QUEST_" + QUEST_ID; // the name of the variable in which the quest state will be stored string JOURNAL_STRING = "JOURNAL_" + QUEST_ID; // Name of the journal category in which the journal entries of the // quest are stored if (!(GetQuestCompleted(QUEST_ID))) // the quest may not be completed {       int QUEST_STATE = GetLocalInt(GetModule,QUEST_STRING); // Retrieving current quest state QUEST_STATE++; // Increment the quest state SetLocalInt(GetModule,QUEST_STRING,QUEST_STATE); // Setting the new state AddJournalQuestEntry(JOURNAL_STRING,QUEST_STATE,oPlayer); // Adjusting the journal accordingly } } void SetQuestCompleted(object oPlayer, int JOURNAL_NUMBER, string QUEST_ID) /*   oPlayer = this must be a PC    JOURNAL_ID = the entry the journal must be set to when the quest is                 completed QUEST_ID = the ID of the quest This function sets the quest state of the quest given by QUEST_ID to   completed. The journal is set to the entry with number JOURNAL_NUMBER. The players will receive the XP reward of the quest. When the quest has already been completed, nothing happens. Make sure the entry is a finishing entry so   that it will be put in the completed quests. This function can be used to set multiple endings of a quest. {   string QUEST_STRING = "QUEST_" + QUEST_ID; // the name of the variable in which the quest state will be stored string JOURNAL_STRING = "JOURNAL_" + QUEST_ID; // Name of the journal category in which the journal entries of the // quest are stored if (!(GetQuestCompleted(QUEST_ID))) // if the quest is not completed {       SetLocalInt(GetModule,QUEST_STRING,QUEST_COMPLETED); // Setting the quest to completed AddJournalQuestEntry(JOURNAL_STRING,JOURNAL_NUMBER,oPlayer); // Adjusting the journal accordingly GiveQuestXP(oPlayer,QUEST_ID); // Give players XP of the quest } }
 * 1) include "nw_i0_tool"
 * 1) include "nw_i0_tool"