Advertisement
TheKeeper81

The Quest System

Nov 18th, 2024
37
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";
  16. integer NPCSystem = 0;
  17. string DCPassed = "DC Passed";  //Message to players: DC Passed
  18. string DCFailed = "DC Failed";  //Message to players: DC Failed
  19. string PassFail = "Pass or Fail";
  20. list PassOrFail;
  21. string DCPassFail;
  22. string PassFailCheck;
  23.  
  24. /////
  25. //Setting up the Menu Variables
  26. /////
  27.  
  28. list menuButtons;   //The list containing the menu buttons
  29. integer menuChan;   //The menu channel
  30. integer listen_menu;    //The listener
  31. string menuText;   //The menu text
  32.  
  33. /////
  34. //The Notecard Reading Setup
  35. /////
  36.  
  37. string notecardName = "Dialog"; //The name of the notecard
  38. integer Results = 64; //The number of search results to return
  39. list DiagOptions;   //The Dialog Options List
  40. string Start = "#Start";    //The start of the dialog chain
  41. string End = "#End";    //The end of the dialog chain
  42. string DiagComp = "Dialog Complete";    //Dialog Complete Caption
  43. string ItemReward = "#Item";
  44. string XPReward;
  45. string NextNotecard = "#NextNotecard";
  46. string firstFound;  //First dialog in the chain found
  47. list firstFoundAsList;  //First dialog in the chain found -- as a list
  48. string LineID;  //The line ID
  49. string Caption; //The line Caption
  50. integer numOptions; //The Number of Options
  51. string Options; //The Options
  52. string NextID;  //The next set of line IDs
  53. list NextIDList;    //The list of the next line IDs
  54. integer index;  //The index of the menu button chosen
  55. string FindID; //The next ID to find
  56. integer LineNumber; //The line number of the next ID
  57. string OptionString;    //The dialog options in string format
  58. list OptionList;    //The dialog options in list format
  59.  
  60. /////
  61. //Misc Variables
  62. /////
  63.  
  64. string Greeting;
  65. string Congrats;
  66. string NextQuest;
  67.  
  68.  
  69. /////
  70. //The Main Script
  71. /////
  72.  
  73. default
  74. {
  75.     //If the inventory or owner changes, reset the script    
  76.     changed(integer change)
  77.     {
  78.         if (change & (CHANGED_INVENTORY | CHANGED_OWNER))
  79.         {
  80.             llResetScript();
  81.         }
  82.     }
  83.    
  84.     //The initial setup
  85.     state_entry()
  86.     {
  87.         llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  88.         menuText = llGetNotecardLineSync(notecardName, 0);
  89.         Greeting = llGetNotecardLineSync(notecardName, 1);
  90.         Congrats = llGetNotecardLineSync(notecardName, 2);
  91.         NextQuest = llGetNotecardLineSync(notecardName, 3);
  92.         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
  93.         llListenRemove(listen_menu);    //Removing the listener
  94.         listen_menu = llListen(menuChan,"","","");  //The Menu Listener
  95.         llSay(0, Greeting); //The greeting to the Player
  96.     }
  97.  
  98.     //Starting the NPC dialog
  99.     touch_start(integer total_number)
  100.     {
  101.         TouchingAvatar = llDetectedKey(0);
  102.         ThisObject = llGetKey();
  103.         if (Caption == DiagComp)    //If the dialog comes to the Dialog completion message, display the congrats message
  104.         {
  105.             llSay(0, Congrats);
  106.         }
  107.         else
  108.         {
  109.             llSay(0, Caption);  //Display the next Dialog Caption
  110.             llDialog(TouchingAvatar,menuText,menuButtons,menuChan);   //Open up the menu
  111.         }
  112.     }
  113.    
  114.     //The Branching Dialog
  115.     listen(integer channel, string name, key target, string message)
  116.     {
  117.         if (channel == menuChan)    //Listen for activity on the menu channel
  118.         {
  119.             if (Caption == DiffCheck)
  120.             {
  121.                 llMessageLinked(LINK_THIS, NPCSystem, llList2CSV([Caption, numOptions, message, NextID]), "");
  122.                 //llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
  123.             }
  124.            
  125.             NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
  126.             index = llListFindList(menuButtons, [message]); //The index is set to be the index of the menu button selected
  127.                                                             //The message is the menu button the Player selected
  128.             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
  129.             DiagOptions  = llFindNotecardTextSync( notecardName, FindID, 0, Results, [] );  //Search the notecard for the text of the Next ID
  130.            
  131.             if ((string)DiagOptions == NAK) //If the search results aren't in the cache, put the notecard into the cache
  132.             {
  133.                 llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  134.             }
  135.            
  136.             LineNumber = llList2Integer(DiagOptions, -3);   //This gives the line number that the Next ID is located on
  137.             OptionString = llGetNotecardLineSync(notecardName, LineNumber); //Go to the Line Number found and make that line into a string
  138.                                                                             //These are the new set of Dialog Options
  139.             OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
  140.             LineID = llList2String(OptionList, 0);  //The Line ID is the first item in this list
  141.             Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
  142.             numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
  143.             Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
  144.             NextID = llList2String(OptionList, 4);  //The set of next IDs are the fifth item on this list
  145.             menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
  146.            
  147.             if (LineID == ItemReward)    //If we've come to the end of the dialog chain, congratulate the player
  148.             {
  149.                 llGiveInventory(TouchingAvatar, Caption);
  150.                 StatAmt = (string)numOptions + ", ";
  151.                 llRegionSayTo(TouchingAvatar, objectchan, (StatItem + Stat + StatAmt + (string)ThisObject));  //Speak to the touching avatar's HUD
  152.                 llSleep(1.0);
  153.                 llSay(0, Congrats);
  154.                 Caption = DiagComp;
  155.                
  156.             }
  157.            
  158.             else if (Caption == DiagComp)    //If we've come to the end of the dialog chain, congratulate the player
  159.             {
  160.                 llSay(0, Congrats);
  161.             }
  162.            
  163.             else if (LineID == NextNotecard)
  164.             {
  165.                 notecardName = NextID;
  166.                 llRequestInventoryData(notecardName);  //Put the notecard into the cache
  167.                 llSay(0, NextQuest);
  168.             }
  169.            
  170.             else    //Otherwise, start the next set of dialog in the chain
  171.             {
  172.                 llSay(0, Caption);
  173.                 llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
  174.             }
  175.         }
  176.     }
  177.  
  178.     link_message( integer sender_num, integer num, string str, key id )
  179.     {
  180.         if (sender_num == NPCSystem)
  181.         {
  182.             PassOrFail = llParseString2List(str, [", "], [""]);
  183.             DCPassFail = llList2String(PassOrFail, 0);
  184.             PassFailCheck = llList2String(PassOrFail, 1);
  185.             llOwnerSay(str);
  186.             llOwnerSay(DCPassFail);
  187.             llOwnerSay(PassFailCheck);
  188.            
  189.             if (DCPassFail == DCPassed)
  190.             {
  191.                 DiagOptions  = llFindNotecardTextSync( notecardName, PassFailCheck, 0, Results, [] );  //Search the notecard for the text of the Next ID                
  192.                 LineNumber = llList2Integer(DiagOptions, -3);   //This gives the line number that the Next ID is located on
  193.                 OptionString = llGetNotecardLineSync(notecardName, LineNumber); //Go to the Line Number found and make that line into a string
  194.                                                                                 //These are the new set of Dialog Options
  195.                 OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
  196.                 LineID = PassFailCheck;  //The Line ID is the first item in this list
  197.                 Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
  198.                 numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
  199.                 Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
  200.                 NextID = llList2String(OptionList, 4);  //The set of next IDs are the fifth item on this list
  201.                 menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
  202.                 llSay(0, Caption);
  203.                 llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
  204.             }
  205.            
  206.             else if (DCPassFail == DCFailed)
  207.             {
  208.                 DiagOptions  = llFindNotecardTextSync( notecardName, PassFailCheck, 0, Results, [] );  //Search the notecard for the text of the Next ID
  209.            
  210.                 if ((string)DiagOptions == NAK) //If the search results aren't in the cache, put the notecard into the cache
  211.                 {
  212.                     llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  213.                 }
  214.                
  215.                 LineNumber = llList2Integer(DiagOptions, -3);   //This gives the line number that the Next ID is located on
  216.                 OptionString = llGetNotecardLineSync(notecardName, LineNumber); //Go to the Line Number found and make that line into a string
  217.                                                                                 //These are the new set of Dialog Options
  218.                 OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
  219.                 LineID = llList2String(OptionList, 0);  //The Line ID is the first item in this list
  220.                 Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
  221.                 numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
  222.                 Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
  223.                 NextID = llList2String(OptionList, 4);  //The set of next IDs are the fifth item on this list
  224.                 menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
  225.                
  226.             }
  227.            
  228.         }
  229.     }
  230.  
  231.     //Starting the Dialog Chain
  232.     dataserver(key i, string n)
  233.     {
  234.         DiagOptions  = llFindNotecardTextSync( notecardName, Start, 0, Results, [] );   //Find the text in the notecard that starts the dialog chain
  235.        
  236.         if ((string)DiagOptions == NAK) //If the search results aren't in the cache, put the notecard into the cache
  237.         {
  238.             llGetNumberOfNotecardLines(notecardName);   //Put the notecard into the cache
  239.         }
  240.        
  241.         firstFound = llGetNotecardLineSync(notecardName, llList2Integer(DiagOptions,0));    //Go to the line of the first dialog found in the chain
  242.         firstFoundAsList = llParseString2List(firstFound, ["|"], [""]); //Make this string into a list
  243.         LineID = llList2String(firstFoundAsList, 0);    //The Line ID is the first item in this list
  244.         Caption = llList2String(firstFoundAsList, 1);   //The Dialog Caption is the second item on this list
  245.         numOptions = llList2Integer(firstFoundAsList, 2);   //The number of options is the third item on this lsit
  246.         Options = llList2String(firstFoundAsList, 3);   //The actual options are the fourth item on this list
  247.         NextID = llList2String(firstFoundAsList, 4);    //The set of next IDs are the fifth item on this list
  248.         menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
  249.     }
  250.  
  251. }
  252.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement