Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////
- //Setting Up The XP Giver
- /////
- integer objectchan = -1234555; //The channel this object sends to and receives from
- string StatItem = "Stat Item, "; //Message to HUD: This is a Stat Aletering message
- string Stat = "Fate Points, "; //Message to HUD: The stat to alter
- string StatAmt; //Message to HUD: The amount to alter the stat by
- key TouchingAvatar; //The UUID of the avatar touching this object
- key ThisObject; //They UUID of this object, in case it's needed
- /////
- //Setting up the Difficulty Checker
- /////
- string DiffCheck = "Difficulty Check";
- integer NPCSystem = 0;
- string DCPassed = "DC Passed"; //Message to players: DC Passed
- string DCFailed = "DC Failed"; //Message to players: DC Failed
- string PassFail = "Pass or Fail";
- list PassOrFail;
- string DCPassFail;
- string PassFailCheck;
- /////
- //Setting up the Menu Variables
- /////
- list menuButtons; //The list containing the menu buttons
- integer menuChan; //The menu channel
- integer listen_menu; //The listener
- string menuText; //The menu text
- /////
- //The Notecard Reading Setup
- /////
- string notecardName = "Dialog"; //The name of the notecard
- integer Results = 64; //The number of search results to return
- list DiagOptions; //The Dialog Options List
- string Start = "#Start"; //The start of the dialog chain
- string End = "#End"; //The end of the dialog chain
- string DiagComp = "Dialog Complete"; //Dialog Complete Caption
- string ItemReward = "#Item";
- string XPReward;
- string NextNotecard = "#NextNotecard";
- string firstFound; //First dialog in the chain found
- list firstFoundAsList; //First dialog in the chain found -- as a list
- string LineID; //The line ID
- string Caption; //The line Caption
- integer numOptions; //The Number of Options
- string Options; //The Options
- string NextID; //The next set of line IDs
- list NextIDList; //The list of the next line IDs
- integer index; //The index of the menu button chosen
- string FindID; //The next ID to find
- integer LineNumber; //The line number of the next ID
- string OptionString; //The dialog options in string format
- list OptionList; //The dialog options in list format
- /////
- //Misc Variables
- /////
- string Greeting;
- string Congrats;
- string NextQuest;
- /////
- //The Main Script
- /////
- default
- {
- //If the inventory or owner changes, reset the script
- changed(integer change)
- {
- if (change & (CHANGED_INVENTORY | CHANGED_OWNER))
- {
- llResetScript();
- }
- }
- //The initial setup
- state_entry()
- {
- llGetNumberOfNotecardLines(notecardName); //Put the notecard into the cache
- menuText = llGetNotecardLineSync(notecardName, 0);
- Greeting = llGetNotecardLineSync(notecardName, 1);
- Congrats = llGetNotecardLineSync(notecardName, 2);
- NextQuest = llGetNotecardLineSync(notecardName, 3);
- 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
- llListenRemove(listen_menu); //Removing the listener
- listen_menu = llListen(menuChan,"","",""); //The Menu Listener
- llSay(0, Greeting); //The greeting to the Player
- }
- //Starting the NPC dialog
- touch_start(integer total_number)
- {
- TouchingAvatar = llDetectedKey(0);
- ThisObject = llGetKey();
- if (Caption == DiagComp) //If the dialog comes to the Dialog completion message, display the congrats message
- {
- llSay(0, Congrats);
- }
- else
- {
- llSay(0, Caption); //Display the next Dialog Caption
- llDialog(TouchingAvatar,menuText,menuButtons,menuChan); //Open up the menu
- }
- }
- //The Branching Dialog
- listen(integer channel, string name, key target, string message)
- {
- if (channel == menuChan) //Listen for activity on the menu channel
- {
- if (Caption == DiffCheck)
- {
- llMessageLinked(LINK_THIS, NPCSystem, llList2CSV([Caption, numOptions, message, NextID]), "");
- //llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
- }
- NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
- index = llListFindList(menuButtons, [message]); //The index is set to be the index of the menu button selected
- //The message is the menu button the Player selected
- 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
- DiagOptions = llFindNotecardTextSync( notecardName, FindID, 0, Results, [] ); //Search the notecard for the text of the Next ID
- if ((string)DiagOptions == NAK) //If the search results aren't in the cache, put the notecard into the cache
- {
- llGetNumberOfNotecardLines(notecardName); //Put the notecard into the cache
- }
- LineNumber = llList2Integer(DiagOptions, -3); //This gives the line number that the Next ID is located on
- OptionString = llGetNotecardLineSync(notecardName, LineNumber); //Go to the Line Number found and make that line into a string
- //These are the new set of Dialog Options
- OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
- LineID = llList2String(OptionList, 0); //The Line ID is the first item in this list
- Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
- numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
- Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
- NextID = llList2String(OptionList, 4); //The set of next IDs are the fifth item on this list
- menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
- if (LineID == ItemReward) //If we've come to the end of the dialog chain, congratulate the player
- {
- llGiveInventory(TouchingAvatar, Caption);
- StatAmt = (string)numOptions + ", ";
- llRegionSayTo(TouchingAvatar, objectchan, (StatItem + Stat + StatAmt + (string)ThisObject)); //Speak to the touching avatar's HUD
- llSleep(1.0);
- llSay(0, Congrats);
- Caption = DiagComp;
- }
- else if (Caption == DiagComp) //If we've come to the end of the dialog chain, congratulate the player
- {
- llSay(0, Congrats);
- }
- else if (LineID == NextNotecard)
- {
- notecardName = NextID;
- llRequestInventoryData(notecardName); //Put the notecard into the cache
- llSay(0, NextQuest);
- }
- else //Otherwise, start the next set of dialog in the chain
- {
- llSay(0, Caption);
- llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
- }
- }
- }
- link_message( integer sender_num, integer num, string str, key id )
- {
- if (sender_num == NPCSystem)
- {
- PassOrFail = llParseString2List(str, [", "], [""]);
- DCPassFail = llList2String(PassOrFail, 0);
- PassFailCheck = llList2String(PassOrFail, 1);
- llOwnerSay(str);
- llOwnerSay(DCPassFail);
- llOwnerSay(PassFailCheck);
- if (DCPassFail == DCPassed)
- {
- DiagOptions = llFindNotecardTextSync( notecardName, PassFailCheck, 0, Results, [] ); //Search the notecard for the text of the Next ID
- LineNumber = llList2Integer(DiagOptions, -3); //This gives the line number that the Next ID is located on
- OptionString = llGetNotecardLineSync(notecardName, LineNumber); //Go to the Line Number found and make that line into a string
- //These are the new set of Dialog Options
- OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
- LineID = PassFailCheck; //The Line ID is the first item in this list
- Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
- numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
- Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
- NextID = llList2String(OptionList, 4); //The set of next IDs are the fifth item on this list
- menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
- llSay(0, Caption);
- llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
- }
- else if (DCPassFail == DCFailed)
- {
- DiagOptions = llFindNotecardTextSync( notecardName, PassFailCheck, 0, Results, [] ); //Search the notecard for the text of the Next ID
- if ((string)DiagOptions == NAK) //If the search results aren't in the cache, put the notecard into the cache
- {
- llGetNumberOfNotecardLines(notecardName); //Put the notecard into the cache
- }
- LineNumber = llList2Integer(DiagOptions, -3); //This gives the line number that the Next ID is located on
- OptionString = llGetNotecardLineSync(notecardName, LineNumber); //Go to the Line Number found and make that line into a string
- //These are the new set of Dialog Options
- OptionList = llParseString2List(OptionString, ["|"], [""]); //The Dialog Options are parsed into a list, with "|" as the separator
- LineID = llList2String(OptionList, 0); //The Line ID is the first item in this list
- Caption = llList2String(OptionList, 1); //The Dialog Caption is the second item on this list
- numOptions = llList2Integer(OptionList, 2); //The number of options is the third item on this lsit
- Options = llList2String(OptionList, 3); //The actual options are the fourth item on this list
- NextID = llList2String(OptionList, 4); //The set of next IDs are the fifth item on this list
- menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
- }
- }
- }
- //Starting the Dialog Chain
- dataserver(key i, string n)
- {
- DiagOptions = llFindNotecardTextSync( notecardName, Start, 0, Results, [] ); //Find the text in the notecard that starts the dialog chain
- if ((string)DiagOptions == NAK) //If the search results aren't in the cache, put the notecard into the cache
- {
- llGetNumberOfNotecardLines(notecardName); //Put the notecard into the cache
- }
- firstFound = llGetNotecardLineSync(notecardName, llList2Integer(DiagOptions,0)); //Go to the line of the first dialog found in the chain
- firstFoundAsList = llParseString2List(firstFound, ["|"], [""]); //Make this string into a list
- LineID = llList2String(firstFoundAsList, 0); //The Line ID is the first item in this list
- Caption = llList2String(firstFoundAsList, 1); //The Dialog Caption is the second item on this list
- numOptions = llList2Integer(firstFoundAsList, 2); //The number of options is the third item on this lsit
- Options = llList2String(firstFoundAsList, 3); //The actual options are the fourth item on this list
- NextID = llList2String(firstFoundAsList, 4); //The set of next IDs are the fifth item on this list
- menuButtons = llParseString2List(Options, [","], [""]); //The Options are parsed into a list used for the Dialog Menu Buttons
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement