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"; //Message to HUD: This is a Difficulty Check message
- integer DiffNum; //Message to HUD: The difficulty number
- string DCStat; //Message to HUD: the stat to use for the Difficulty Roll
- string MakeRoll = "Make Roll";
- /////
- //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"; //The LineID called ItemReward
- string NextNotecard = "#NextNotecard"; //The LineID called NextNotecard
- 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; //The greeting the NPC object gives the Player
- string Congrats; //The congratulations message the NPC object gives the Player upong completing the quest
- string NextQuest; //The message informming the Player that the NPC object needs to be touched again due to a new line in the quest
- /////
- //The Branching Dialog Function
- /////
- list FindingDiagOptions (string messagereceived)
- {
- NextIDList = llParseString2List(NextID, [","], [""]); //Make the string of next IDs into a list we can work with
- index = llListFindList(menuButtons, [messagereceived]); //The index is set to be the index of the menu button selected
- //The message is the menu button the Player selected
- if (!~index) //The index = -1 when the menuButtons = "Make Roll"; here, we're looking for the Pass/Fail message
- {
- index = llListFindList(NextIDList, [messagereceived]); //Adjusting for the Pass/Fail message to get the proper index
- }
- 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
- //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
- DiagOptions = llFindNotecardTextSync( notecardName, FindID, 0, Results, [] ); //Search the notecard for the text of the Next ID
- return DiagOptions; //Return the DiagOptions list
- }
- TheBranchingDialogFunction()
- {
- //Find where the NextID is being used as the LineID
- integer find;
- integer found = llGetListLength(DiagOptions);
- integer line;
- for (find = 0; find < found; find += 3) //stride of 3
- //So, DiagOptions is a list consisting of row, column, length for each instance of the string found
- //So, we want to search the list in groups of three
- {
- 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
- {
- line = llList2Integer(DiagOptions, find); //The index of the position of the desired column position in the DiagOptions List
- }
- }
- OptionString = llGetNotecardLineSync(notecardName,line); //Go to the line in the notecard where the NextID is the LineID
- //These are the new set of Dialog Options (not to be confused with DiagOptions)
- //This is a string, at first
- 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
- }
- /////
- //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); //The menu text is the first line of the notecard
- Greeting = llGetNotecardLineSync(notecardName, 1); //The greeting is the second line of the notecard
- Congrats = llGetNotecardLineSync(notecardName, 2); //The congratulatory message is the third line of the notecard
- NextQuest = llGetNotecardLineSync(notecardName, 3); //The next quest notice is the fourth line of the notecard
- 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); //Getting the key of the avatar that touches the NPC object
- ThisObject = llGetKey(); //Getting the key of the NPC object, just in case
- 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 dialog menu
- }
- }
- //The Branching Dialog
- listen(integer channel, string name, key target, string message)
- {
- if (channel == menuChan) //Listen for activity on the menu channel
- {
- FindingDiagOptions(message); //Use the message received to find the DiagOptions List
- TheBranchingDialogFunction(); //Go to the main Branching Dialog Function
- 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
- //When the Options is MakeRoll, then we need to send out the DC data to the HUD
- {
- DiffNum = numOptions; //Here, the numOptions slot is being used to declare the Difficulty Number the Player needs to meet
- DCStat = message; //Here, the message should be set to the skill the Player chose to use for the DC
- llRegionSayTo(TouchingAvatar, objectchan, llList2CSV([DiffCheck, DiffNum, DCStat, NextID, menuChan])); //Speak to the touching avatar's HUD
- //We're giving the HUD the expected DC message
- }
- 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)
- {
- llGiveInventory(TouchingAvatar, Caption); //Here, the Caption in this line identifies the object to be delivered to the Player
- StatAmt = (string)numOptions + ", "; //Here, the numOptions is acting as the Fate Points number, or XP in generic RPG terms
- llRegionSayTo(TouchingAvatar, objectchan, (StatItem + Stat + StatAmt + (string)ThisObject)); //Speak to the touching avatar's HUD
- //We're giving the HUD the expected Alter Stats message
- llSleep(1.0); //Sleep for a moment to give the Player time to receive the item
- llSay(0, Congrats); //Deliver the congratulations message
- Caption = DiagComp; //Set the Caption the the DiagComp message so the script knows we've come to the end of the dialog chain
- }
- 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) //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.
- {
- notecardName = NextID; //Here, the NextID is the name of the notecard we're switching to
- llGetNumberOfNotecardLines(notecardName); //Put the notecard into the cache
- llSay(0, NextQuest); //Inform the Player to touch the NPC to switch to the next part of the Quest
- }
- else //Otherwise, start the next set of dialog in the chain
- {
- llSay(0, Caption);
- llDialog(TouchingAvatar,menuText,menuButtons,menuChan);
- }
- }
- }
- //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
- TheBranchingDialogFunction(); //Use the Branching Dialog Function to do the rest
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement