Advertisement
TheKeeper81

Untitled

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