Advertisement
TheKeeper81

The Quest System R1

Nov 19th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /////
  2. //Setting Up The XP Giver
  3. /////
  4. integer objectchan = -1234555;  //The channel this object sends to and receives from
  5. string StatItem = "Stat Item, ";    //Message to HUD: This is a Stat Aletering message
  6. string Stat = "Fate Points, "; //Message to HUD: The stat to alter
  7. string StatAmt;   //Message to HUD: The amount to alter the stat by
  8. key TouchingAvatar; //The UUID of the avatar touching this object
  9. key ThisObject; //They UUID of this object, in case it's needed
  10.  
  11. /////
  12. //Setting up the Difficulty Checker
  13. /////
  14.  
  15. string DiffCheck = "Difficulty Check";  //Message to HUD: This is a Difficulty Check message
  16. integer DiffNum;    //Message to HUD: The difficulty number
  17. string DCStat;  //Message to HUD: the stat to use for the Difficulty Roll
  18. string MakeRoll = "Make Roll";
  19.  
  20. /////
  21. //Setting up the Menu Variables
  22. /////
  23.  
  24. list menuButtons;   //The list containing the menu buttons
  25. integer menuChan;   //The menu channel
  26. integer listen_menu;    //The listener
  27. string menuText;   //The menu text
  28.  
  29. /////
  30. //The Notecard Reading Setup
  31. /////
  32.  
  33. string notecardName = "Dialog"; //The name of the notecard
  34. integer Results = 64; //The number of search results to return
  35. list DiagOptions;   //The Dialog Options List
  36. string Start = "#Start";    //The start of the dialog chain
  37. string End = "#End";    //The end of the dialog chain
  38. string DiagComp = "Dialog Complete";    //Dialog Complete Caption
  39. string ItemReward = "#Item";    //The LineID called ItemReward
  40. string NextNotecard = "#NextNotecard";  //The LineID called NextNotecard
  41. string LineID;  //The line ID
  42. string Caption; //The line Caption
  43. integer numOptions; //The Number of Options
  44. string Options; //The Options
  45. string NextID;  //The next set of line IDs
  46. list NextIDList;    //The list of the next line IDs
  47. integer index;  //The index of the menu button chosen
  48. string FindID; //The next ID to find
  49. integer LineNumber; //The line number of the next ID
  50. string OptionString;    //The dialog options in string format
  51. list OptionList;    //The dialog options in list format
  52.  
  53. /////
  54. //Misc Variables
  55. /////
  56.  
  57. string Greeting;    //The greeting the NPC object gives the Player
  58. string Congrats;    //The congratulations message the NPC object gives the Player upong completing the quest
  59. string NextQuest;   //The message informming the Player that the NPC object needs to be touched again due to a new line in the quest
  60.  
  61.  
  62. /////
  63. //The Branching Dialog Function
  64. /////
  65.  
  66. list FindingDiagOptions (string messagereceived)
  67. {
  68.     NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
  69.     index = llListFindList(menuButtons, [messagereceived]); //The index is set to be the index of the menu button selected
  70.                                                             //The message is the menu button the Player selected
  71.     if (!~index)    //The index = -1 when the menuButtons = "Make Roll"; here, we're looking for the Pass/Fail message
  72.     {
  73.         index = llListFindList(NextIDList, [messagereceived]);  //Adjusting for the Pass/Fail message to get the proper index
  74.     }
  75.            
  76.     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
  77.                                                     //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
  78.     DiagOptions  = llFindNotecardTextSync( notecardName, FindID, 0, Results, [] );  //Search the notecard for the text of the Next ID
  79.    
  80.     return DiagOptions; //Return the DiagOptions list
  81. }
  82.  
  83. TheBranchingDialogFunction()
  84. {
  85.     //Find where the NextID is being used as the LineID
  86.     integer find;
  87.     integer found = llGetListLength(DiagOptions);
  88.     integer line;
  89.     for (find = 0; find < found; find += 3) //stride of 3
  90.                                             //So, DiagOptions is a list consisting of row, column, length for each instance of the string found
  91.                                             //So, we want to search the list in groups of three
  92.     {
  93.         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
  94.         {
  95.             line = llList2Integer(DiagOptions, find);   //The index of the position of the desired column position in the DiagOptions List
  96.         }
  97.     }
  98.            
  99.     OptionString = llGetNotecardLineSync(notecardName,line);    //Go to the line in the notecard where the NextID is the LineID          
  100.                                                                 //These are the new set of Dialog Options (not to be confused with DiagOptions)
  101.                                                                 //This is a string, at first
  102.     OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
  103.     LineID = llList2String(OptionList, 0);  //The Line ID is the first item in this list
  104.     Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
  105.     numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
  106.     Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
  107.     NextID = llList2String(OptionList, 4);  //The set of next IDs are the fifth item on this list
  108.     menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
  109. }
  110.  
  111.  
  112. /////
  113. //The Main Script
  114. /////
  115.  
  116. default
  117. {
  118.     //If the inventory or owner changes, reset the script    
  119.     changed(integer change)
  120.     {
  121.         if (change & (CHANGED_INVENTORY | CHANGED_OWNER))
  122.         {
  123.             llResetScript();
  124.         }
  125.     }
  126.    
  127.     //The initial setup
  128.     state_entry()
  129.     {
  130.         llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  131.         menuText = llGetNotecardLineSync(notecardName, 0);  //The menu text is the first line of the notecard
  132.         Greeting = llGetNotecardLineSync(notecardName, 1);  //The greeting is the second line of the notecard
  133.         Congrats = llGetNotecardLineSync(notecardName, 2);  //The congratulatory message is the third line of the notecard
  134.         NextQuest = llGetNotecardLineSync(notecardName, 3); //The next quest notice is the fourth line of the notecard
  135.         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
  136.         llListenRemove(listen_menu);    //Removing the listener
  137.         listen_menu = llListen(menuChan,"","","");  //The Menu Listener
  138.         llSay(0, Greeting); //The greeting to the Player
  139.     }
  140.  
  141.     //Starting the NPC dialog
  142.     touch_start(integer total_number)
  143.     {
  144.         TouchingAvatar = llDetectedKey(0);  //Getting the key of the avatar that touches the NPC object
  145.         ThisObject = llGetKey();    //Getting the key of the NPC object, just in case
  146.         if (Caption == DiagComp)    //If the dialog comes to the Dialog completion message, display the congrats message
  147.         {
  148.             llSay(0, Congrats);
  149.         }
  150.         else
  151.         {
  152.             llSay(0, Caption);  //Display the next Dialog Caption
  153.             llDialog(TouchingAvatar,menuText,menuButtons,menuChan);   //Open up the dialog menu
  154.         }
  155.     }
  156.    
  157.     //The Branching Dialog
  158.     listen(integer channel, string name, key target, string message)
  159.     {
  160.         if (channel == menuChan)    //Listen for activity on the menu channel
  161.         {
  162.             FindingDiagOptions(message);    //Use the message received to find the DiagOptions List
  163.             TheBranchingDialogFunction();   //Go to the main Branching Dialog Function
  164.            
  165.             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
  166.                                         //When the Options is MakeRoll, then we need to send out the DC data to the HUD
  167.             {
  168.                 DiffNum = numOptions;   //Here, the numOptions slot is being used to declare the Difficulty Number the Player needs to meet
  169.                 DCStat = message;       //Here, the message should be set to the skill the Player chose to use for the DC
  170.                 llRegionSayTo(TouchingAvatar, objectchan, llList2CSV([DiffCheck, DiffNum, DCStat, NextID, menuChan]));  //Speak to the touching avatar's HUD
  171.                                                                                                                         //We're giving the HUD the expected DC message
  172.             }
  173.            
  174.             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)
  175.             {
  176.                 llGiveInventory(TouchingAvatar, Caption);   //Here, the Caption in this line identifies the object to be delivered to the Player
  177.                 StatAmt = (string)numOptions + ", ";    //Here, the numOptions is acting as the Fate Points number, or XP in generic RPG terms
  178.                 llRegionSayTo(TouchingAvatar, objectchan, (StatItem + Stat + StatAmt + (string)ThisObject));    //Speak to the touching avatar's HUD
  179.                                                                                                                 //We're giving the HUD the expected Alter Stats message
  180.                 llSleep(1.0);   //Sleep for a moment to give the Player time to receive the item
  181.                 llSay(0, Congrats); //Deliver the congratulations message
  182.                 Caption = DiagComp; //Set the Caption the the DiagComp message so the script knows we've come to the end of the dialog chain
  183.             }
  184.            
  185.             else if (Caption == DiagComp)   //If we've come to the end of the dialog chain, congratulate the player
  186.             {
  187.                 llSay(0, Congrats);
  188.             }
  189.            
  190.             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.
  191.             {
  192.                 notecardName = NextID;  //Here, the NextID is the name of the notecard we're switching to
  193.                 llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  194.                 llSay(0, NextQuest);    //Inform the Player to touch the NPC to switch to the next part of the Quest
  195.             }
  196.            
  197.             else    //Otherwise, start the next set of dialog in the chain
  198.             {
  199.                 llSay(0, Caption);
  200.                 llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
  201.             }
  202.         }
  203.     }
  204.  
  205.     //Starting the Dialog Chain
  206.     dataserver(key i, string n)
  207.     {
  208.         DiagOptions  = llFindNotecardTextSync( notecardName, Start, 0, Results, [] );   //Find the text in the notecard that starts the dialog chain    
  209.         TheBranchingDialogFunction();   //Use the Branching Dialog Function to do the rest
  210.     }
  211.  
  212. }
  213.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement