Advertisement
TheKeeper81

The Quest System Multiplayer

Nov 21st, 2024
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////
  2. //Setting up the prereq checks
  3. /////
  4.  
  5. integer Prereqs = FALSE;
  6. string PrereqIncoming;
  7. string PrereqsNone = "No Prereqs Needed";
  8. string PrereqMessage = "Please show you meet the prerequisites for this quest.";
  9.  
  10.  
  11. /////
  12. //Setting Up The Quest Objective channels and Listeners
  13. /////
  14.  
  15. integer chanBase;
  16.  
  17. string questChanString;
  18. list questChanList;
  19. integer questChan;
  20. integer questChanOffset;
  21. integer listen_quest;
  22.  
  23. /////
  24. //Setting Up The XP Giver
  25. /////
  26. integer objectchanoffset = -1234555;    //The number to offset the object channel by
  27. integer objectchan; //The object channel this object sends to and receives from
  28. integer listen_object;  //The object channel's listener
  29. string StatItem = "Stat Item, ";    //Message to HUD: This is a Stat Aletering message
  30. string Stat; //Message to HUD: The stat to alter
  31. string StatAmt;   //Message to HUD: The amount to alter the stat by
  32. key TouchingAvatar; //The UUID of the avatar touching this object
  33. key ThisObject; //They UUID of this object, in case it's needed
  34.  
  35. /////
  36. //Setting up the Difficulty Checker
  37. /////
  38.  
  39. string DiffCheck = "Difficulty Check";  //Message to HUD: This is a Difficulty Check message
  40. integer DiffNum;    //Message to HUD: The difficulty number
  41. string DCStat;  //Message to HUD: the stat to use for the Difficulty Roll
  42. string MakeRoll = "Make Roll";
  43.  
  44. /////
  45. //Setting up the Menu Variables
  46. /////
  47.  
  48. list menuButtons;   //The list containing the menu buttons
  49. string Yes = "Yes, Reset"; //The yes button
  50. string No = "No, Reset";   //The no button
  51. list menuResetOptions = [Yes, No];  //The menu buttons for the Quest Reset Options
  52. integer menuChan;   //The menu channel
  53. integer listen_menu;    //The listener
  54. string menuText;   //The menu text
  55.  
  56. /////
  57. //The Notecard Reading Setup
  58. /////
  59.  
  60. string notecardName = "Dialog"; //The name of the notecard
  61. integer notecardLine;   //The line of the notecard being referenced for the notecard reading
  62. key notecardQueryID;    //Identifier for the dataserver event
  63. key notecardKey;    //Store the notecard's key, so we don't read it again by accident.
  64. integer Results = 64; //The number of search results to return
  65. list DiagOptions;   //The Dialog Options List
  66. string Start = "#Start";    //The start of the dialog chain
  67. string End = "#End";    //The end of the dialog chain
  68. string DiagComp = "Dialog Complete";    //Dialog Complete Caption
  69. string ItemReward = "#Item";    //The LineID called ItemReward
  70. string NoReward = "No Reward"; //What to put if the "item reward" is nothing, and instead just used to alter stats
  71. string NextNotecard = "#NextNotecard";  //The LineID called NextNotecard
  72. string LineID;  //The line ID
  73. string Caption; //The line Caption
  74. integer numOptions; //The Number of Options
  75. string Options; //The Options
  76. string NextID;  //The next set of line IDs
  77. list NextIDList;    //The list of the next line IDs
  78. integer index;  //The index of the menu button chosen
  79. string FindID; //The next ID to find
  80. integer LineNumber; //The line number of the next ID
  81. string OptionString;    //The dialog options in string format
  82. list OptionList;    //The dialog options in list format
  83.  
  84. string QuestName = "#QuestName";    //The name of the Quest or Chain of Quests
  85. string QuestNameData;   //For tracking purposes, this variable is associated with the name of the Quest
  86.                         //The original intent is to take down the line number so that the NPC remembers where the Player left off
  87.                         //I might still use this, so keeping it
  88. string QuestObjective = "#QuestObjective";   //The Objective of the Quest
  89. string QuestComplete = "Quest Objective Complete";    //The status of the Quest Objective: the Quest is complete
  90. string QuestFailed = "Quest Obbective Failed";  //The status of the Quest is Failed
  91. string Objective;   //The Quest Objective received from the Quest Item
  92. integer ObjectiveNumber;    //The Objective Number value the Quest Item is worth
  93. string QuestPassFail;   //The notice from the Quest Item whether reaching 0 in Current Count is a Pass or Fail
  94. integer QuestStartingNumber;   //In case of quest failure, the script can retrieve the Quest Starting Number to reset the quest status
  95. string QuestPasses = "Pass";    //The message from the Quest Item letting the Quest Controller know Current Count reaching 0 is a Pass
  96. string QuestFails = "Fail"; //The message from the Quest Item letting the Quest Controller know Current Count reaching 0 is a Fail
  97. string QuestID; //The Quest Objective taken from the LineID; just separated out the # in front of it
  98. integer QuestIDNum = -999;  //This identifies the line that has the Quest Objective in the LineID
  99. string QuestUpdate1 = "Your progress in Quest Objective ";  //The message to update progress
  100. string QuestUpdate2 = " is: ";  //The second part of the message to update progress
  101. string QuestUpdate3 = " is now complete!";  //Informing the Player the Quest Objective is now complete
  102. string QuestUpdate4 = " has failed.";
  103. string TaskReminder;    //The task reminder message the NPC gives when the Player hasn't completed the task
  104. string CompleteQuestOption = "Complete Quest";  //The Options Label to look for when processing the Quest Objectives
  105.  
  106. /////
  107. //Misc Variables
  108. /////
  109.  
  110. string Greeting;    //The greeting the NPC object gives the Player
  111. string Congrats;    //The congratulations message the NPC object gives the Player upong completing the quest
  112. string NextQuest;   //The message informming the Player that the NPC object needs to be touched again due to a new line in the quest
  113. string ResetQuest = "Would you like to replay this adventure?";
  114. string QuestResetMessage = "Reset Quest";
  115. string PlayerQuestSpot;
  116.  
  117.  
  118. /////
  119. //Channel Setup - Unique Channel for the RP System
  120. /////
  121.  
  122. integer Key2Chan(key ID)
  123. {
  124.     return 0x80000000 | (integer)("0x"+(string)ID);
  125. }
  126.  
  127. /////
  128. //Read Notecard
  129. /////
  130.  
  131. ReadNotecard()
  132. {
  133.     if (llGetInventoryKey(notecardName) == NULL_KEY)     //Check if the notecard exists in inventory and has been saved since it's creation (newly created notecards that are yet to be saved are assigned NULL_KEY).
  134.     {
  135.         llOwnerSay( "Notecard '" + notecardName + "' is missing, unwritten, or not full permission."); //Notify user.
  136.         return; //Don't do anything else.
  137.     }
  138.    
  139.     else if (llGetInventoryKey(notecardName) == notecardKey) //This notecard has already been read - call to read was made in error, so don't do anything. (Notecards are assigned a new key each time they are saved.)
  140.     {
  141.         return;
  142.     }
  143.  
  144.     llOwnerSay("Began reading notecard: " + notecardName); //Notify user that read has started.
  145.     llLinksetDataReset();   //Clear the Linkset Data
  146.     notecardLine = 0;   //Make sure notecardLine starts at 0
  147.     notecardQueryID = llGetNotecardLine(notecardName, notecardLine);    //Get the notecard line
  148. }
  149.  
  150.  
  151. /////
  152. //Linkset Data Dump
  153. /////
  154.  
  155. lsdDump()
  156. {
  157.     integer item;   //The Linkset Data Key Number (The Data Key is the name of the Data; The Data Key Value is the string value assigned to that Data Name; Basically, "What does this name represent?")
  158.     integer items = llLinksetDataCountKeys();   //The number of unique Data Keys in the Linkset Data
  159.     for (item = 0; item < items; item++)    //For each Data Key, do the following
  160.     {
  161.         string k = llDumpList2String(llLinksetDataListKeys(item,1),",");    //Make the Linkset Data Key into a string
  162.         string v = llLinksetDataRead(k);    //Read the Linkset Data Key's Value
  163.         llOwnerSay((string)["Dump (", 1+item, "/", items, ") >> ", k, "=", v]); //Say in chat the Linkset Data Name and its Value
  164.     }
  165. }
  166.  
  167. /////
  168. //Get Stat's Value - Integer
  169. /////
  170.  
  171. integer get(string stat)
  172. {
  173.     return (integer)llLinksetDataRead(stat);    //Get the Value of the Linkset Data Key and return it as an integer (The Data Key is the name of the Data; The Data Key Value is the string value assigned to that Data Name; Basically, "What does this name represent?")
  174.  
  175. }
  176.  
  177. /////
  178. //Get Stat's Value - String
  179. /////
  180.  
  181. string getstring(string stat)
  182. {
  183.     return llLinksetDataRead(stat); //Get the Value of the Linkset Data Key and return it as a string (The Data Key is the name of the Data; The Data Key Value is the string value assigned to that Data Name; Basically, "What does this name represent?")
  184. }
  185.  
  186. /////
  187. //Set Stat's Value - Integer
  188. /////
  189.  
  190. set(string stat, integer value)
  191. {
  192.     llLinksetDataWrite(stat, (string)value);    //Write the new value in for the Linkset Data Key; here, the expected data is an integer (The Data Key is the name of the Data; The Data Key Value is the string value assigned to that Data Name; Basically, "What does this name represent?")
  193. }
  194.  
  195. /////
  196. //Set Stat's Value - String
  197. /////
  198.  
  199. setstring(string stat, string value)
  200. {
  201.     llLinksetDataWrite(stat, value);    //Write the new value in for the Linkset Data Key; here, the expected data is already a string (The Data Key is the name of the Data; The Data Key Value is the string value assigned to that Data Name; Basically, "What does this name represent?")
  202. }
  203.  
  204. /////
  205. //Item Collection Counter
  206. /////
  207.  
  208. ItemCollection(string questObjective, integer Count, string PassFail)    //The two values are the name of the Quest Objective and how mych to reduce the total Quest Count Number by
  209. {
  210.     integer CurrentCount = (integer)llLinksetDataRead(questObjective); //Get the current count of the Quest Objective from the LinksetData
  211.     CurrentCount -= Count;  //Subtract the Count from the Current Count
  212.     set(questObjective, CurrentCount); //Set the Current Count to the Quest Objective
  213.    
  214.     if (CurrentCount > 0) //When the Current Count is greater than zero, display the message
  215.     {
  216.         llSay (0, QuestUpdate1 + questObjective + QuestUpdate2 + (string)CurrentCount);
  217.     }
  218.    
  219.     else    //When the Current Count is 0 or less, set to zero then display the messages
  220.     {
  221.         CurrentCount = 0;
  222.         llSay (0, QuestUpdate1 + questObjective + QuestUpdate2 + (string)CurrentCount);
  223.        
  224.         if (PassFail == QuestPasses)
  225.         {
  226.             setstring(questObjective, QuestComplete);   //We're marking the Quest Objective as complete
  227.             llSay (0, questObjective + QuestUpdate3);
  228.         }
  229.        
  230.         else
  231.         {
  232.             setstring(questObjective, QuestFailed); //We're marking the Quest Objective as failed
  233.             llSay (0, questObjective + QuestUpdate4);
  234.         }
  235.     }
  236.    
  237. }
  238.  
  239. /////
  240. //The Branching Dialog Function
  241. /////
  242.  
  243. list FindingDiagOptions (string messagereceived)
  244. {
  245.     NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
  246.     index = llListFindList(menuButtons, [messagereceived]); //The index is set to be the index of the menu button selected
  247.                                                             //The message is the menu button the Player selected
  248.     if (!~index)    //The index = -1 when the menuButtons = "Make Roll"; here, we're looking for the Pass/Fail message
  249.     {
  250.         index = llListFindList(NextIDList, [messagereceived]);  //Adjusting for the Pass/Fail message to get the proper index
  251.     }
  252.            
  253.     FindID = llList2String(NextIDList, index);      //The NextID list is the same length as the Options List and should have one to one correspondence with that list
  254.                                                     //The exception is the "Make Roll" lines in the notecard, as they only have "Make Roll" in the Options List, while the NextID List has two items: Pass and Fail
  255.     DiagOptions  = llFindNotecardTextSync( notecardName, FindID, 0, Results, [] );  //Search the notecard for the text of the Next ID
  256.    
  257.     return DiagOptions; //Return the DiagOptions list
  258. }
  259.  
  260. TheBranchingDialogFunction()
  261. {
  262.     //Find where the NextID is being used as the LineID
  263.     integer find;
  264.     integer found = llGetListLength(DiagOptions);
  265.     integer line;
  266.     for (find = 0; find < found; find += 3) //stride of 3
  267.                                             //So, DiagOptions is a list consisting of row, column, length for each instance of the string found
  268.                                             //So, we want to search the list in groups of three
  269.     {
  270.         if (llList2Integer(DiagOptions, 1+find) == 0)   //When we find the entry saying the column is at 0 (the beginning of the line), we've found the line we're looking for
  271.         {
  272.             line = llList2Integer(DiagOptions, find);   //The index of the position of the desired column position in the DiagOptions List
  273.         }
  274.     }
  275.            
  276.     OptionString = llGetNotecardLineSync(notecardName,line);    //Go to the line in the notecard where the NextID is the LineID          
  277.                                                                 //These are the new set of Dialog Options (not to be confused with DiagOptions)
  278.                                                                 //This is a string, at first
  279.     OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
  280.     LineID = llList2String(OptionList, 0);  //The Line ID is the first item in this list
  281.     Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
  282.     numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
  283.     Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
  284.     NextID = llList2String(OptionList, 4);  //The set of next IDs are the fifth item on this list
  285.     menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
  286.     setTask(TouchingAvatar, notecardName, LineID);   //Recording where the Player is at in the dialog
  287. }
  288.  
  289. /////
  290. //Tracking Player Progress in the Dialog
  291. /////
  292.  
  293. string questID (key Player, string Quest)   //Player = Touching Avatar's UUID, Quest = Notecard Player is on
  294. {
  295.     key Creator = llGetInventoryCreator(notecardName);
  296.     return llList2CSV([Player, Creator, Quest]);
  297. }
  298.  
  299. string getQuest (key Player)
  300. {
  301.     return llLinksetDataRead(Player);
  302. }
  303.  
  304. integer setQuest (key Player, string Quest)
  305. {
  306.     return llLinksetDataWrite(Player, Quest);
  307. }
  308.  
  309. string getTask (key Player, string Quest)
  310. {
  311.     return llLinksetDataRead(questID(Player, Quest));
  312. }
  313.  
  314. integer setTask(key Player, string Quest, string Place)    //Place = LineID that Player is on
  315. {
  316.     return llLinksetDataWrite(questID(Player, Quest), Place);
  317. }
  318.  
  319. /////
  320. //The Main Script
  321. /////
  322.  
  323. default
  324. {
  325.     //If the inventory or owner changes, reset the script    
  326.     changed(integer change)
  327.     {
  328.         if (change & (CHANGED_INVENTORY | CHANGED_OWNER))
  329.         {
  330.             llResetScript();
  331.         }
  332.     }
  333.    
  334.     //The initial setup
  335.     state_entry()
  336.     {
  337.         chanBase = Key2Chan(llGetOwner());
  338.         ReadNotecard();
  339.         //llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  340.         PrereqIncoming = llGetNotecardLineSync(notecardName, 0); //The Expected Prereq Quest to have completed
  341.         menuText = llGetNotecardLineSync(notecardName, 1);  //The menu text is the first line of the notecard
  342.         Greeting = llGetNotecardLineSync(notecardName, 2);  //The greeting is the second line of the notecard
  343.         Congrats = llGetNotecardLineSync(notecardName, 3);  //The congratulatory message is the third line of the notecard
  344.         NextQuest = llGetNotecardLineSync(notecardName, 4); //The next quest notice is the fourth line of the notecard
  345.         TaskReminder = llGetNotecardLineSync(notecardName, 5);  //The text used to remind the player of the quest objective
  346.         questChanString = llGetNotecardLineSync(notecardName, 6); //Getting the line in the notecard with the quest channel offset
  347.         questChanList = llParseString2List(questChanString, ["|"], [""]);   //Setting up the string as a list to get the channel offset
  348.         questChanOffset = llList2Integer(questChanList, 0);  //Extracting the channel offset from the list
  349.         menuChan = (integer)(llFrand(999999.0) * -1);  // This just comes up with some big random negative number to use as the channel for the menu to work on
  350.         objectchan = chanBase + objectchanoffset;   //Setting up the object channel
  351.         questChan = chanBase + questChanOffset;   //Setting the quest item channel
  352.         llListenRemove(listen_menu);    //Removing the listener
  353.         llListenRemove(listen_object);  //Removing the listener
  354.         llListenRemove(listen_quest); //Removing the listener
  355.         listen_menu = llListen(menuChan,"","","");  //The Menu Listener
  356.         listen_object = llListen(objectchan,"","",""); //The Object Channel Listener
  357.         listen_quest = llListen(questChan,"","","");
  358.         ThisObject = llGetKey();    //Getting the key of the NPC object, just in case
  359.         llSay(0, Greeting); //The greeting to the Player
  360.     }
  361.  
  362.     //The Branching Dialog
  363.     listen(integer channel, string name, key target, string message)
  364.     {
  365.         if (channel == menuChan)    //Listen for activity on the menu channel
  366.         {
  367.             if (message == Yes || message == No)
  368.             {
  369.                 if (message == Yes)
  370.                 {
  371.                     llRegionSay(objectchan, llList2CSV([QuestResetMessage, QuestNameData]));
  372.                     llResetScript();
  373.                 }
  374.             }
  375.            
  376.             else
  377.             {
  378.  
  379.                 FindingDiagOptions(message);    //Use the message received to find the DiagOptions List
  380.                 TheBranchingDialogFunction();   //Go to the main Branching Dialog Function
  381.                
  382.                 PlayerQuestSpot = getTask(TouchingAvatar, notecardName);
  383.                
  384.                 if (PlayerQuestSpot == LineID)
  385.                 {
  386.                
  387.                     if (Options == MakeRoll)    //MakeRoll and its associated string are a fixed command that the player needs to use in their notecard when writing difficulty checks
  388.                                                 //When the Options is MakeRoll, then we need to send out the DC data to the HUD
  389.                     {
  390.                         DiffNum = numOptions;   //Here, the numOptions slot is being used to declare the Difficulty Number the Player needs to meet
  391.                         DCStat = message;       //Here, the message should be set to the skill the Player chose to use for the DC
  392.                         llRegionSayTo(TouchingAvatar, objectchan, llList2CSV([DiffCheck, DiffNum, DCStat, NextID, menuChan]));  //Speak to the touching avatar's HUD
  393.                                                                                                                                 //We're giving the HUD the expected DC message
  394.                     }
  395.                    
  396.                     else if (LineID == ItemReward)    //Here, ItemReward and its associated string are a fixed command that the player needs to use in order to give the player an item and Fate Points (TSOAT's version of XP)
  397.                     {
  398.                         if (Caption != NoReward)
  399.                         {
  400.                             llGiveInventory(TouchingAvatar, Caption);   //Here, the Caption in this line identifies the object to be delivered to the Player
  401.                         }
  402.                        
  403.                         Stat = Options + ", ";
  404.                         StatAmt = (string)numOptions + ", ";    //Here, the numOptions is acting as the Fate Points number, or XP in generic RPG terms
  405.                         llRegionSayTo(TouchingAvatar, objectchan, (StatItem + Stat + StatAmt + (string)ThisObject));    //Speak to the touching avatar's HUD
  406.                                                                                                                         //We're giving the HUD the expected Alter Stats message
  407.                         llSleep(1.0);   //Sleep for a moment to give the Player time to receive the item
  408.                         llSay(0, Congrats); //Deliver the congratulations message
  409.                         Caption = DiagComp; //Set the Caption the the DiagComp message so the script knows we've come to the end of the dialog chain
  410.                     }
  411.                    
  412.                     else if (Caption == DiagComp)   //If we've come to the end of the dialog chain, congratulate the player
  413.                     {
  414.                         llSay(0, Congrats);
  415.                     }
  416.                    
  417.                     else if (LineID == NextNotecard)    //Here, NextNotecard and its associated string are a fixed command that the player needs to use in order to switch to the next notecard in the inventory; this can be useful for complex storylines, etc.
  418.                     {
  419.                         notecardName = NextID;  //Here, the NextID is the name of the notecard we're switching to
  420.                         llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  421.                         llSay(0, NextQuest);    //Inform the Player to touch the NPC to switch to the next part of the Quest
  422.                     }
  423.                    
  424.                     else if (numOptions == QuestIDNum)
  425.                     {
  426.                         list ParsedLineID = llParseString2List(LineID, ["#"],[""]);
  427.                         QuestID = llList2String(ParsedLineID, 0);
  428.                         llSay(0, Caption);
  429.                         llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
  430.                        
  431.                     }
  432.                    
  433.                     else if (Options == CompleteQuestOption)
  434.                     {
  435.                         string CompletionCheck = llLinksetDataRead(Objective);
  436.                        
  437.                         if (CompletionCheck == QuestComplete)
  438.                         {
  439.                             NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
  440.                             message = llList2String(NextIDList, 1);
  441.                             FindingDiagOptions(message);    //Use the message received to find the DiagOptions List
  442.                             TheBranchingDialogFunction();   //Go to the main Branching Dialog Function
  443.                         }
  444.                        
  445.                         else if (CompletionCheck == QuestFailed)
  446.                         {
  447.                             set(QuestID, QuestStartingNumber);
  448.                             NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
  449.                             message = llList2String(NextIDList, 2);
  450.                             FindingDiagOptions(message);    //Use the message received to find the DiagOptions List
  451.                             TheBranchingDialogFunction();   //Go to the main Branching Dialog Function
  452.                         }
  453.                        
  454.                         else
  455.                         {
  456.                             llSay (0, TaskReminder + " ::: " + QuestID + " ::: " + (string)get(QuestID));
  457.                             NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
  458.                             message = llList2String(NextIDList, 0);
  459.                             FindingDiagOptions(message);    //Use the message received to find the DiagOptions List
  460.                             TheBranchingDialogFunction();   //Go to the main Branching Dialog Function
  461.                         }
  462.                     }
  463.                    
  464.                     else    //Otherwise, start the next set of dialog in the chain
  465.                     {
  466.                        
  467.                         llSay(0, Caption);
  468.                         llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
  469.                     }
  470.                 }
  471.                
  472.                 else
  473.                 {
  474.                     FindingDiagOptions(PlayerQuestSpot);    //Use the message received to find the DiagOptions List
  475.                     TheBranchingDialogFunction();   //Go to the main Branching Dialog Function
  476.                 }
  477.             }
  478.         }
  479.        
  480.         if (channel == questChan)  //Listen for messages from Quest Objects
  481.         {
  482.              list ItemMessage = llCSV2List(message); //Parsing the message into a list
  483.              Objective = llList2String(ItemMessage, 0);   //The first datum in the list is the quest objective
  484.              ObjectiveNumber = llList2Integer(ItemMessage, 1);   //The second datum in the list is the number to decrease the Current Count by
  485.              QuestPassFail = llList2String(ItemMessage, 2);  //The third datum in the list is whether or not the quest passes or fails upon reaching Current Count 0
  486.              QuestStartingNumber = llList2Integer(ItemMessage, 3);   //The fourth datum in the list is the Starting Number of the Quest Objective, in case it gets lost due to Quest Failure
  487.              ItemCollection(Objective, ObjectiveNumber, QuestPassFail); //Go to the Item Collection function in order to figure out Player's Progress
  488.         }
  489.        
  490.         if (channel == objectchan)
  491.         {
  492.             if (message == PrereqIncoming)
  493.             {
  494.                 Prereqs = TRUE;
  495.             }
  496.            
  497.             else
  498.             {
  499.                 list ResetMessageList = llCSV2List(message);
  500.                 string ResetMessageMain = llList2String(ResetMessageList, 0);
  501.                 string NameOfQuest = llList2String(ResetMessageList, 1);
  502.                
  503.                 if (ResetMessageMain == QuestResetMessage)
  504.                 {
  505.                     if (NameOfQuest == QuestNameData)
  506.                     {
  507.                         llResetScript();
  508.                     }
  509.                 }
  510.             }
  511.         }
  512.     }
  513.  
  514.     //Starting the NPC dialog
  515.     touch_start(integer total_number)
  516.     {
  517.         TouchingAvatar = llDetectedKey(0);  //Getting the key of the avatar that touches the NPC object
  518.         setTask(TouchingAvatar, notecardName, LineID);
  519.        
  520.         if (Caption == DiagComp)    //If the dialog comes to the Dialog completion message, display the congrats message
  521.         {
  522.             llSay(0, Congrats + " " + ResetQuest);
  523.             llDialog(TouchingAvatar,menuText,menuResetOptions,menuChan);
  524.         }
  525.        
  526.         else if (Prereqs == TRUE || PrereqIncoming == PrereqsNone)
  527.         {
  528.             llSay(0, Caption);  //Display the next Dialog Caption
  529.             llDialog(TouchingAvatar,menuText,menuButtons,menuChan);   //Open up the dialog menu
  530.         }
  531.        
  532.         else
  533.         {
  534.             llSay(0, PrereqMessage);
  535.         }
  536.     }
  537.  
  538.     //Starting the Dialog Chain
  539.     dataserver(key i, string n)
  540.     {
  541.         if (i == notecardQueryID)
  542.         {
  543.             while (n != EOF && n != NAK)    // Is this the end of file (EOF), or a call without cache (NAK)? (Or just data?) If not, do the following
  544.             {
  545.                 list input = llParseString2List(n, ["|"], [""]);    //Make the notecard line into a list, with the "|" as the separator
  546.                 string Type = llList2String(input, 0);  //The first datum in the list identifies the Type of item it is; we're looking for quest name or quest objective
  547.                 string Name = llList2String(input, 1);  //The second datum in the list identifies the name of the quest or quest objective
  548.                 string Number = llList2String(input, 2);    //The third datum in the list is the number of items that need to be collected for the quest objective; for the quest name, it could be the number it is in the quest chain
  549.                
  550.                 if (Type == QuestName || Type == QuestObjective)    //If the Type is either the quest name or the quest objective, then write the data to LinksetData
  551.                 {
  552.                     llLinksetDataWrite(Name,Number);
  553.                    
  554.                     if (Type == QuestName)
  555.                    
  556.                     {
  557.                         QuestNameData = Name;
  558.                     }
  559.                 }
  560.                
  561.                 n = llGetNotecardLineSync(notecardName, ++notecardLine); // message = new data, or NAK. NAK means quit the while and go slow. We want to slow down if it's a call without a cache
  562.             }
  563.            
  564.             if (n == NAK)    // We got a line, but its not cached, ask for next line slow way.
  565.             {
  566.                 i = llGetNotecardLine(notecardName, notecardLine); // ask for next line, not sync
  567.             }
  568.            
  569.             if (n == EOF) // Card is finished loading
  570.             {
  571.                 i = "read"; // just for checking later
  572.                 llOwnerSay("Notecard read");    //Announce the notecard was read
  573.                 lsdDump();  //Dump the LinksetData into OwnerSay chat to make sure we got it
  574.                 llOwnerSay(QuestNameData);  //Confirm the name of the quest
  575.             }
  576.            
  577.         }
  578.        
  579.         DiagOptions  = llFindNotecardTextSync( notecardName, Start, 0, Results, [] );   //Find the text in the notecard that starts the dialog chain    
  580.         TheBranchingDialogFunction();   //Use the Branching Dialog Function to do the rest
  581.     }
  582.  
  583. }
  584.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement