Advertisement
CardinaleSins

Untitled

May 3rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //    Neckbeard RP Tool Pro, by Tenaar Feiri.
  2. //    Using functions from: Erika Fluffy,
  3. //    Started work: April 2nd, 2014
  4. //    Last Updated: April 9th, 2016
  5. //
  6. /*
  7. Copyright (c) 2016, Martin ร˜verby (Tenaar Feiri)
  8. All rights reserved.
  9.  
  10. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  11.  
  12. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  13.  
  14. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  15.  
  16. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  17.  
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19. */
  20.  
  21. // Global variables listed by category. //
  22.  
  23. // ### Misc. Info Vars. ### //
  24.  
  25. string version = "2.3"; // Our titler version.
  26.  
  27. integer DEBUG = FALSE;
  28.  
  29. string name = "Aetherheim Titler-"; // Titler's name.
  30.  
  31. // ### Functions for online connectivity ### //
  32.  
  33. key verID;
  34.  
  35. // ### Channel variables ### //
  36.  
  37. integer Key2AppChan(key ID, integer App) { // Generates a unique channel per key, with additional app modifier.
  38.     return 0x80000000 | ((integer)("0x"+(string)ID) ^ App);
  39. }
  40. integer saveLoadHandle;
  41. integer saveload;
  42. integer saveorload = 1; // 1 = save, 2 = load
  43. integer titleChan = 1; // The channel through which we give the titler commands. Can be changed!
  44. integer titleChanHandler; // Handles the titleChan!
  45. integer changeTitle; // To keep track of the channel we use for changing titles.
  46. integer changeTitleHandler; // Handler for the changeTitle channel.
  47. integer changeIt; // FALSE when selecting title/constant, TRUE when changing it.
  48. string selected; // Set when choosing a title/constant to change.
  49. //integer isComma = 0; // 0 = line separation; 1 = comma separation; 2 = merge line 1 & 2 without comma.)
  50.  
  51. // ### Titler data ### //
  52.  
  53. //vector color = <1,1,1>; // Colour for the titler text. Default is white.
  54. float alpha = 1.0; // Titler visibility.
  55. list constants = ["","Class:","Rank:","AP:","Health:","",""]; // List for our constants.
  56. list titles = ["Set me using *Titles*","","","","","","","","", "", "", "255,255,255", "0"]; // List for our titles!
  57.  
  58. /*
  59.  
  60.     List of Title nums & their functions
  61.    
  62.         0-7 -> title1-title8
  63.        
  64.         8 -> Percentage on/off
  65.        
  66.         9 -> Post regen
  67.        
  68.         10 -> Maximum energy (used w/ postregen)
  69.        
  70.         11 -> Text colour,
  71.        
  72.         12 -> Comma
  73.        
  74.  
  75. */
  76.  
  77. string ooc = ""; // What msg to show if we're OOC.
  78. string afk = ""; // What msg to show if we're AFK.
  79. integer out = 0; // 0 = IC, 1 = OOC, 2 = AFK.
  80. integer postRegenLast; // Last time we had a post regen.
  81. integer postRegenThrottle = 120; // How long we have to wait between each post for it to trigger post regen.
  82. integer showCap = TRUE; // Show the post regen cap.
  83.  
  84.  
  85. list colors = [
  86.                 "blue", "0,0,255",
  87.                 "red", "255,0,0",
  88.                 "green", "0,255,0",
  89.                 "white", "255,255,255",
  90.                 "black", "0,0,0",
  91.                 "yellow", "255,255,0",
  92.                 "purple", "128,0,128",
  93.                 "aqua", "0,255,255",
  94.                 "teal", "128,255,255"
  95.                 ];
  96.  
  97.  
  98. // ### Functions for handling titler data ### //
  99.  
  100.  
  101. changeOutTit(integer cOt, integer title, string data)
  102. {
  103.     string tmpN = llList2String(constants, title);
  104.     string tmpD = llList2String(titles, title);
  105.    
  106.     // If cOt == 1, then we're changing a constant.
  107.     if(cOt == 1)
  108.     {
  109.         constants = llListReplaceList(constants, [(string)data], title, title);
  110.         llOwnerSay("Constant \""+tmpN+"\" (title"+(string)(title+1)+") changed to\" "+llList2String(constants, title)+"\"");
  111.     }
  112.     // If cOt == 2, then we're changing a title.
  113.     else if(cOt == 2)
  114.     {
  115.         titles = llListReplaceList(titles, [(string)data], title, title);
  116.         llOwnerSay("Title \""+tmpN+"\" (title"+(string)(title+1)+") changed from \""+tmpD+"\" to\" "+llList2String(titles, title)+"\"");
  117.     }
  118. }
  119.  
  120.  
  121. // Function to show the dialog options for title & constant changing.
  122. showDialog(integer num)
  123. {
  124.     changeIt = FALSE; // Resets changeIt.
  125.     list tmp; // Temporary list.
  126.     string desc; // Description.
  127.     integer i = (llGetListLength(constants) - 1); // How many constants we have. Important note: # of constants == # of parsing titles.
  128.     integer x;
  129.     if(num == 1) // If num == 1, then we're selecting titles.
  130.     {
  131.         for(x=0;x<=i;x++)
  132.         {
  133.             tmp += ["title"+(string)(x+1)]; // Add the title to the list.
  134.             desc += "Title "+(string)(x+1)+": ("+llList2String(constants, x)+") "+llList2String(titles, x); // Add constant values &
  135.             if(x != i)
  136.             {
  137.                 desc += "\n"; // Append linebreak if not last entry.
  138.             }
  139.         }
  140.         // When we're done, double check that the list lengths match.
  141.         if(llGetListLength(tmp) != (i+1))
  142.         {
  143.             llOwnerSay("Cannot show dialog menu; titles not matched.");
  144.             return;
  145.         }
  146.         tmp = paginateList(0, tmp);
  147.         // But if they are equally long, let's roll!
  148.         changeTitle = Key2AppChan(llGetOwner(), 4321); // Define the channel.
  149.         changeTitleHandler = llListen(changeTitle, "", llGetOwner(), ""); // Initiate the listen.
  150.         // Then trigger the dialog.
  151.         llDialog(llGetOwner(), desc, tmp, changeTitle);
  152.     }
  153.     else if(num == 2) // If num == 2, we're changing the constants.
  154.     {
  155.         for(x=0;x<=i;x++)
  156.         {
  157.             tmp += ["const"+(string)(x+1)]; // Add the title to the list.
  158.             desc += "Title "+(string)(x+1)+": ("+llList2String(constants, x)+") "+llList2String(titles, x); // Add constant values &
  159.             if(x != i)
  160.             {
  161.                 desc += "\n"; // Append linebreak if not last entry.
  162.             }
  163.         }
  164.         // When we're done, double check that the list lengths match.
  165.         if(llGetListLength(tmp) != (i+1))
  166.         {
  167.             llOwnerSay("Cannot show dialog menu; titles not matched.");
  168.             return;
  169.         }
  170.         tmp = paginateList(0, tmp);
  171.         // But if they are equally long, let's roll!
  172.         changeTitle = Key2AppChan(llGetOwner(), 4322); // Define the channel.
  173.         changeTitleHandler = llListen(changeTitle, "", llGetOwner(), ""); // Initiate the listen.
  174.         // Then trigger the dialog.
  175.         llDialog(llGetOwner(), desc, tmp, changeTitle);
  176.     }
  177. }
  178.  
  179.  
  180. // Function for handling dice rolls.
  181. integer diceRoll(integer faces)
  182. {
  183.     // This function will use the time of day & sim uptime as a randomized seed.
  184.     // Then it will calculate a dice roll and output the result.
  185.     integer seed = FALSE;
  186.     if(faces < 2) {
  187.         return seed;
  188.     }
  189.    
  190.     string timestamp = llGetTimestamp() + (string)llGetTime();
  191.    
  192.     integer length = (llStringLength(timestamp) - 1);
  193.     integer x;
  194.     for(x = 0; x<=length; x++) {
  195.         if(!IsInteger(llGetSubString(timestamp, x, x))) {
  196.             timestamp = llDeleteSubString(timestamp, x, x);
  197.         }
  198.     }
  199.    
  200.     list tmp;
  201.    
  202.     length = (llStringLength(timestamp) - 1);
  203.     for(x = 0; x<=length; x++) {
  204.         tmp += [llGetSubString(timestamp, x, x)];
  205.     }
  206.      
  207.    
  208.     length = (llGetListLength(tmp) - 1);
  209.     for(x=0;x<=length;x++) {
  210.         tmp = llListRandomize(tmp, 0);
  211.     }
  212.     seed = 1;
  213.     for(x=0;x<=length;x++) {
  214.         if(x < 0) {
  215.             if((integer)llList2String(tmp, x) != 0) {
  216.                 seed += (integer)llList2String(tmp, x);
  217.             }
  218.         }
  219.         else if((integer)llList2String(tmp, x) != 0) {
  220.             seed += llList2Integer(tmp, x);
  221.         }
  222.     }
  223.     seed = 1 + (seed % faces);
  224.    
  225.     if(seed > faces) {
  226.         seed = faces;
  227.     }
  228.     else if(seed < 1) {
  229.         seed = 1;
  230.     }
  231.    
  232.     //llOwnerSay((string)seed);
  233.    
  234.     return seed;
  235. }
  236.  
  237.  
  238. funcUpdTitle(integer const, integer loc, string data) // Update either constant or title.
  239. {
  240.     if(const) // If we're updating a constant...
  241.     {
  242.         if(out)
  243.         {
  244.             changeOutTit(1, loc, data);
  245.         }
  246.         else
  247.         {
  248.             constants = llListReplaceList(constants, [(string)data], loc, loc); // Update the relevant constant value.
  249.         }
  250.     }
  251.     else // If we're updating a title...
  252.     {
  253.         if(out)
  254.         {
  255.             changeOutTit(2, loc, data);
  256.         }
  257.         else
  258.         {
  259.             titles = llListReplaceList(titles, [(string)data], loc, loc);
  260.         }
  261.     }
  262.     funcParseTitle();
  263.     // Then if we've updated the name & not the constant...
  264.     if(loc == 0 && !const)
  265.     {
  266.          if (llGetSubString(llList2String(titles, 0), -1, -1) == llUnescapeURL("%0A") )
  267.         {
  268.             llListReplaceList(titles,[(string)llGetSubString(llList2String(titles, 0), 0, -2)], 0, 0);
  269.         }
  270.         // Inform chatter.
  271.         llMessageLinked(LINK_THIS, 1337, llList2String(titles, 0), ""); // Informs chatter of name change.
  272.  
  273.     }
  274. }
  275.  
  276. string funcFindTag(string data)
  277. {
  278.     list tmp;
  279.     if(~llSubStringIndex(data, "$p"))
  280.     {
  281.         tmp = llParseString2List(data, ["$p"], []);
  282.         data = llDumpList2String(tmp, "\n");
  283.     }
  284.     else if(~llSubStringIndex(data, "$n"))
  285.     {
  286.         // Filter out $n from the name so it doesn't show in the titler.
  287.         tmp = llParseString2List(data, ["$n"], []);
  288.         data = llDumpList2String(tmp, "");
  289.     }
  290.    
  291.     return data;
  292. }
  293.  
  294. funcParseTitle() // Parse the title.
  295. {
  296.     string tmp; // Temporary string.
  297.     string nameVal = funcFindTag(llList2String(titles, 0));
  298.     if(nameVal == "nil")
  299.     {
  300.         nameVal = "";
  301.     }
  302.     if(out == 1) // If ooc...
  303.     {
  304.         tmp = "[OOC]\n"+nameVal+"\n"+ooc+""; // Put the OOC message in the string.
  305.     }
  306.     else if(out == 2) // If afk...
  307.     {
  308.         tmp = "[AFK]\n"+nameVal+"\n"+afk+""; // Put the AFK message in the string.
  309.     }
  310.     else // If IC...
  311.     {
  312.        
  313.         integer i = 7; // How many titles we'll be parsing through.
  314.         integer x; // Counter integer.
  315.         string isComma = llList2String(titles, 12);
  316.         for(x=0;x<=i;x++) // Begin loop!
  317.         {
  318.             string constVal = funcFindTag(llList2String(constants, x));
  319.             string titleVal = funcFindTag(llList2String(titles, x));
  320.             if(constVal == "nil" && titleVal == "nil")
  321.             {
  322.                 jump break;
  323.             }
  324.             else if(constVal == "nil")
  325.             {
  326.                 constVal = "";
  327.             }
  328.             else if(titleVal == "nil")
  329.             {
  330.                 titleVal = "";
  331.             }
  332.             tmp = tmp + constVal + " " + titleVal; // Add the title to the temporary string.
  333.             if(x != i) // If x is not the last entry in the list...
  334.             {
  335.                 if(x == 0 && IsInteger(isComma) && (integer)isComma == 1) // Check to see if x is exactly 0 and that comma is true.
  336.                 {
  337.                     tmp = tmp + ", "; // If comma is true, separate the two top titles by a comma instead of a linebreak.
  338.                 }
  339.                 else if(x == 0 && IsInteger(isComma) && (integer)isComma == 2)
  340.                 {
  341.                         tmp = tmp + " ";
  342.                 }
  343.                 else // If this is not the case...
  344.                 {
  345.                     tmp = tmp + "\n"; // Then we separate by way of linebreak.
  346.                 }
  347.             }
  348.             @break;
  349.         }
  350.         // Then when the loop is over, add the percentage...if it exists.
  351.         if(llList2String(titles, 7) != "nil") // If energy is hidden, or is not integer, do not add %.
  352.         {
  353.             if(IsInteger(llList2String(titles, 7)))
  354.             {
  355.                 if(llList2String(titles, 8) == "on")
  356.                 {
  357.                     tmp = tmp + ""; // Add % if exists & energy is shown.
  358.                 }
  359.                 else if(llList2String(titles, 8) != "on" && showCap && llList2Integer(titles, 9) > 0)
  360.                 {
  361.                     tmp = tmp + " / " + llList2String(titles, 10);
  362.                 }
  363.             }
  364.         }
  365.     }
  366.     if(DEBUG) { llOwnerSay(tmp); }
  367.     // Then when all this is done, display title.
  368.     string tempcol = "<"+llList2String(titles, 11)+">";
  369.     llSetText(tmp, rgb2sl((vector)tempcol), alpha);
  370. }
  371.  
  372. integer IsInteger(string var)
  373. {
  374.     integer i;
  375.     for (i=0;i<llStringLength(var);++i)
  376.     {
  377.         if(!~llListFindList(["1","2","3","4","5","6","7","8","9","0"],[llGetSubString(var,i,i)]))
  378.         {
  379.             return FALSE;
  380.         }
  381.     }
  382.     return TRUE;
  383. }
  384.  
  385. vector rgb2sl( vector rgb )
  386. {
  387.     return rgb / 255;        
  388. }
  389.  
  390. integer strIsVector(string str)
  391. {
  392.     str = llStringTrim(str, STRING_TRIM);
  393.  
  394.     if(llGetSubString(str, 0, 0) != "<" || llGetSubString(str, -1, -1) != ">")
  395.         return FALSE;
  396.  
  397.     integer commaIndex = llSubStringIndex(str, ",");
  398.  
  399.     if(commaIndex == -1 || commaIndex == 1)
  400.         return FALSE;
  401.  
  402.     if( !strIsDecimal(llGetSubString(str, 1, commaIndex - 1)) || llGetSubString(str, commaIndex - 1, commaIndex - 1) == " " )
  403.         return FALSE;
  404.  
  405.     str = llDeleteSubString(str, 1, commaIndex);
  406.  
  407.     commaIndex = llSubStringIndex(str, ",");
  408.  
  409.     if(commaIndex == -1 || commaIndex == 1 || commaIndex == llStringLength(str) - 2 ||
  410.        
  411.         !strIsDecimal(llGetSubString(str, 1, commaIndex - 1)) || llGetSubString(str, commaIndex - 1, commaIndex - 1) == " " ||
  412.        
  413.         !strIsDecimal(llGetSubString(str, commaIndex + 1, -2)) ||  llGetSubString(str, -2, -2) == " ")
  414.            
  415.             return FALSE;
  416.  
  417.     return TRUE;
  418. }
  419.  
  420. // Returns TRUE if the string is a decimal
  421. integer strIsDecimal(string str)
  422. {
  423.     str = llStringTrim(str, STRING_TRIM);
  424.  
  425.     integer strLen = llStringLength(str);
  426.     if(!strLen){return FALSE;}
  427.  
  428.     integer i;
  429.     if(llGetSubString(str,0,0) == "-" && strLen > 1)
  430.         i = 1;
  431.     else
  432.         i = 0;
  433.  
  434.     integer decimalPointFlag = FALSE;
  435.  
  436.     for(; i < strLen; i++)
  437.     {
  438.         string currentChar = llGetSubString(str, i, i);
  439.  
  440.         if(currentChar == ".")
  441.             if(decimalPointFlag)
  442.                 return FALSE;
  443.         else
  444.             decimalPointFlag = TRUE;
  445.         else if(currentChar != "3" && currentChar != "6" && currentChar != "9" &&
  446.             currentChar != "2" && currentChar != "5" && currentChar != "8" && // the order dosen't matter
  447.                 currentChar != "1" && currentChar != "4" && currentChar != "7" && currentChar != "0")
  448.                     return FALSE;
  449.     }
  450.  
  451.     return TRUE;
  452. }
  453.  
  454. // Function for handling post regens!
  455. funcPostRegen()
  456. {
  457.     if(llList2String(titles, 7) == "nil" || !IsInteger(llList2String(titles, 7)) || llList2Integer(titles, 9) == 0) // Do not update the energy if it's hidden, or is not an integer, or if regen is disabled.
  458.     {
  459.         return;
  460.     }
  461.  
  462.     // If it's appropriate to update energy, and we actually are using postregen...
  463.     if(llGetUnixTime() > (postRegenLast + postRegenThrottle))
  464.     {
  465.  
  466.        
  467.        
  468.         // Do the regen!
  469.         integer regeneration = (llList2Integer(titles, 7) + llList2Integer(titles, 9)); // Calculate next regen value!
  470.  
  471.         // If regeneration result is bigger than the max limit...
  472.         if(regeneration > llList2Integer(titles, 10))
  473.         {
  474.             // Set regeneration to the max limit.
  475.             regeneration = llList2Integer(titles, 10);
  476.         }
  477.         // Then update the energy value.
  478.         titles = llListReplaceList(titles, [(string)regeneration], 7, 7);
  479.  
  480.         // Then make a note of when this completed.
  481.         postRegenLast = llGetUnixTime();
  482.        
  483.         // Then reparse titles.
  484.         funcParseTitle();
  485.     }
  486. }
  487.  
  488.  
  489. // ### Variables and/or functions dealing with save files! ### //
  490.  
  491. // Separator for constants: c~c
  492. // Separator for titles: t~t
  493. // Separator between the constants and titles: @|@
  494. // Separator for option params: |**|
  495.  
  496. // This funciton handles the saving and loading.
  497. funcSaveLoadChar(string data)
  498. {
  499.     // Since we don't save the character data in this script, we need to format it properly.
  500.     if(llGetSubString(data, 0, 4) == "save:")
  501.     {
  502.         // Now, if we're saving then we only have two variables to worry about: "save:" and "slot#".
  503.         // Let's put them in a temporary list for now. Since data looks like "save:slot#", this is easy.
  504.         list tmp = llParseStringKeepNulls(data, [":"], []);
  505.  
  506.         // Now that we have those two variables in our list, we can use the data string without having to define a new one.
  507.         // This could be done by way of loop, but luckily LL has provided us with much better ways to dump lists!
  508.         // So we'll just do this fast.
  509.         data = llDumpList2String(constants, "c~c")+"@|@"+llDumpList2String(titles, "t~t");
  510.         // Then let's add our options to the string.
  511.         // First we add in "save" and at the end we've got the slot it will save to.
  512.         data = llList2String(tmp, 0) + "|**|" + data + "|**|" + llList2String(tmp, 1);
  513.  
  514.         // With this done, we can now send a linked message with our data to the character save script!
  515.         // The 2nd option in the function below, the integer after LINK_THIS, identifies what we're doing.
  516.         // 1 means we're saving. 2 would mean we're loading.
  517.         llMessageLinked(LINK_THIS, 1, data, "");
  518.  
  519.         // And that's it. Now the character handler will take care of the rest.
  520.     }
  521.     // If we're loading then we've got our data in place already!
  522.     else if(llGetSubString(data, 0, 4) == "load:")
  523.     {
  524.         data = llDeleteSubString(data, 0, 4);
  525.         list tmp = llParseStringKeepNulls(data, ["@|@"], []);
  526.  
  527.         // We can do this the easy way.
  528.         // Just replace the list with the data. We already got our separators, and we can do this in one fell swoop!
  529.         list tmpD =  llParseStringKeepNulls(llList2String(tmp, 0),
  530.             ["c~c"],
  531.             []
  532.                 );
  533.         constants = llListReplaceList(constants,
  534.             tmpD,
  535.             0, (llGetListLength(tmpD) - 1));
  536.  
  537.         // Constants should be up to date now. Rinse and repeat with titles.
  538.        
  539.         tmpD = llParseStringKeepNulls(llList2String(tmp, 1),
  540.             ["t~t"],
  541.             []
  542.                 );
  543.         titles = llListReplaceList(titles,
  544.             tmpD,
  545.             0, (llGetListLength(tmpD) - 1));
  546.  
  547.         // Then with that done, all we need to do is re-parse the titles!
  548.         funcParseTitle();
  549.         llOwnerSay("Character "+llList2String(titles, 0)+" has been successfully loaded.");
  550.         llMessageLinked(LINK_THIS, 1337, llList2String(titles, 0), ""); // Informs chatter of name change.
  551.         // This will also remember post regen rates.
  552.     }
  553. }
  554.  
  555. list paginateList( integer vIdxPag, list cards ){ // Handles listing of paginated lists.
  556.     list vLstRtn;
  557.     if ((cards != []) > 12){ //-- we have more than one possible page
  558.         integer vIntTtl = -~((~([] != cards)) / 10);                                 //-- Total possible pages
  559.         integer vIdxBgn = (vIdxPag = (vIntTtl + vIdxPag) % vIntTtl) * 10;              //-- first menu index
  560.         string  vStrPag = llGetSubString( "                     ", 21 - vIdxPag, 21 ); //-- encode page number as spaces
  561.         //-- get ten (or less for the last page) entries from the list and insert back/fwd buttons
  562.         vLstRtn = llListInsertList( llList2List( cards, vIdxBgn, vIdxBgn + 9 ), (list)(" <" + vStrPag), 0xFFFFFFFF ) +(list)(" >" + vStrPag);
  563.     }else{ //-- we only have 1 page
  564.             vLstRtn = cards; //-- just use the list as is
  565.     }
  566.     return //-- fix the order for [L2R,T2B] and send it out
  567.         llList2List( vLstRtn, -3, -1 ) + llList2List( vLstRtn, -6, -4 ) +
  568.         llList2List( vLstRtn, -9, -7 ) + llList2List( vLstRtn, -12, -10 );
  569. }
  570.  
  571. //////////////////////////////
  572. // Execute code. //
  573. default
  574. {
  575.     state_entry()
  576.     {
  577.         // ### SETUP ### //
  578.         llSetObjectName(name+version);
  579.         saveload = Key2AppChan(llGetOwner(), 112);
  580.         titleChanHandler = llListen(titleChan, "", "", "");
  581.         // ############# //
  582.         funcParseTitle();
  583.         llOwnerSay((string)llGetUsedMemory()+" bytes used.");
  584.         llMessageLinked(LINK_THIS, 1337, llList2String(titles, 0), ""); // Informs chatter of name.
  585.         llOwnerSay(" The Chat Channel is on /4 for IC name use.");
  586.     }
  587.  
  588.     // Handles incoming link messages.
  589.     link_message(integer sender, integer num, string data, key id)
  590.     {
  591.  
  592.         // If num == 2, then we're loading a character.
  593.         if(num == 2)
  594.         {
  595.             //llOwnerSay(data);
  596.             // Run the function to load the data.
  597.             funcSaveLoadChar(data);
  598.         }
  599.         else if(num == 5)
  600.         {
  601.             if(llToLower(data) == "save" || llToLower(data) == "load")
  602.             {
  603.             }
  604.             else
  605.             {
  606.                 funcSaveLoadChar(data);
  607.             }
  608.         }
  609.         else if(num == 4)
  610.         {
  611.             saveLoadHandle = llListen(saveload, "", llGetOwner(), "");
  612.             //llSetTimerEvent(120);
  613.             list tmp = llParseString2List(data, ["@@@"], []);
  614.             llDialog(llGetOwner(), "Please select your slot:\n"+llList2String(tmp, 0), llParseString2List(llList2String(tmp, 1), [","], []) , saveload);
  615.         }
  616.         else if(num == 1331)
  617.         {
  618.             // If 1331, we're getting a regen message.
  619.             if(data == "regen")
  620.             {
  621.                 funcPostRegen(); // Execute regen.
  622.                 if(changeTitleHandler) // If changeTitleHandler is set when we get a regen message...
  623.                 { // Reset those stats.
  624.                     changeIt = FALSE;
  625.                     llListenRemove(changeTitleHandler);
  626.                     changeTitleHandler = FALSE;
  627.                     changeTitle = FALSE;
  628.                     selected = "";
  629.                 }
  630.             }
  631.         }
  632.  
  633.     }
  634.  
  635.     changed(integer change)
  636.     {
  637.         if(change & CHANGED_OWNER)
  638.         {
  639.             llResetScript();
  640.         }
  641.     }
  642.  
  643.     on_rez(integer start_param)
  644.     {
  645.         llListenRemove(saveLoadHandle);
  646.         llMessageLinked(LINK_THIS, 1337, llList2String(titles, 0), ""); // Informs chatter of name.
  647.     }
  648.  
  649.     listen(integer c, string n, key id, string m) // Listen to commands!
  650.     {
  651.         //llOwnerSay("Heard you on chan " + (string)c + ", msg: "+m);
  652.         // Check to see if we are actually hearing the commands of our owner & their HUD!
  653.         if(llGetOwner() == id || (llGetOwnerKey(id) == llGetOwner() && llList2String(llGetObjectDetails(id, [OBJECT_DESC]), 0) == "RP-Tool-HUD"))
  654.         {
  655.                 // If all is well, let's start checking to see what happens.
  656.        
  657.                 if(c == saveload)
  658.                 {
  659.                     // If we're saving, just do function.
  660.                     if(saveorload == 1)
  661.                     {
  662.                         m = "save:slot"+m;
  663.                         funcSaveLoadChar(m);
  664.                     }
  665.                     // If not, perform loading operation!
  666.                     else if(saveorload == 2)
  667.                     {
  668.                         m = "load|**|"+m;
  669.                         llMessageLinked(LINK_THIS, 1, m, "");
  670.                     }
  671.                 }
  672.                 else if(c == titleChan) // If the communicating channel is channe titleChan, then we're receiving a command!
  673.                 {
  674.                     integer tmp; // We're probably gonna need this!
  675.                     string command = "/"+(string)titleChan+" "+m; // Just in case we experience an error.
  676.                     // If m has "title" in it and the number following it is a number...
  677.                     if(llGetSubString(llToLower(m), 0, 4) == "title" && (string)((integer)llGetSubString(llToLower(m), 5, 5)) == llGetSubString(llToLower(m), 5, 5))
  678.                     {
  679.                         // Then we're going to update a title. So let's update!
  680.                         tmp = ((integer)llGetSubString(m, 5, 5) - 1); // Add the title number to the temporary integer. Reduce by 1 for zero-indexed list.
  681.                         if(tmp > 7) // If tmp is bigger than 7...
  682.                         {
  683.                             llOwnerSay("Could not update title. Title number not valid. Your command: "+command);
  684.                             return;
  685.                         }
  686.        
  687.                         m = llDeleteSubString(m, 0, 5); // Then delete "title#" from the string.
  688.                         m = llStringTrim(m, STRING_TRIM); // Trim the string for leading and trailing spaces.
  689.                         if(llToLower(m) == "hide" || llToLower(m) == "none")
  690.                         {
  691.                             m = "nil";
  692.                         }
  693.                        
  694.        
  695.                         funcUpdTitle(FALSE, tmp, m); // Then update the title!
  696.                     } // End title.
  697.                     // If not title, we're updating the constant. Same thing applies!
  698.                     else if(llGetSubString(llToLower(m), 0, 4) == "const" && (string)((integer)llGetSubString(llToLower(m), 5, 5)) == llGetSubString(llToLower(m), 5, 5))
  699.                     {
  700.                         // Then we're going to update a constant. So let's update!
  701.                         tmp = ((integer)llGetSubString(m, 5, 5) - 1); // Add the const number to the temporary integer. Reduce by 1 for zero-indexed list.
  702.                         if(tmp > 7) // If tmp is bigger than 7...
  703.                         {
  704.                             llOwnerSay("Could not update constant. Constant number not valid. Your command: "+command);
  705.                             return;
  706.                         }
  707.                         m = llDeleteSubString(m, 0, 5); // Then delete "const" from the string.
  708.                         m = llStringTrim(m, STRING_TRIM); // Trim the string for leading and trailing spaces.
  709.                         if(llToLower(m) == "hide" || llToLower(m) == "none")
  710.                         {
  711.                             m = "nil";
  712.                         }
  713.                         funcUpdTitle(TRUE, tmp, m); // Then update the constant!
  714.                     } // End update.
  715.        
  716.                     // Are we updating the percent perhaps?
  717.                     else if(llGetSubString(llToLower(m), 0, 6) == "percent")
  718.                     {
  719.                         m = llDeleteSubString(m, 0, 6);
  720.                         m = llStringTrim(llToLower(m), STRING_TRIM);
  721.                         if(m == "on") // If we're adding the percent onto the thing...
  722.                         {
  723.                             titles = llListReplaceList(titles, ["on"], 8, 8); // Add it to the list.
  724.                         }
  725.                         else if(m == "off") // Or if we're removing it...
  726.                         {
  727.                             titles = llListReplaceList(titles, ["off"], 8, 8); // Take it away!
  728.                         }
  729.                         funcParseTitle(); // Then parse the new title.
  730.                     }
  731.                     // We could be updating colours as well! Colour presets no longer exist to save memory.
  732.                     else if(llGetSubString(llToLower(m), 0, 4) == "color")
  733.                     {
  734.                         m = llDeleteSubString(m, 0, 4);
  735.                         m = llStringTrim(m, STRING_TRIM);
  736.                         string mTemp = m;
  737.                         mTemp = llDumpList2String(llParseStringKeepNulls(mTemp, [" "], []), ",");
  738.                         if(strIsVector("<"+mTemp+">")) // If the colour value is indeed a vector...
  739.                         {
  740.                             titles = llListReplaceList(titles, [mTemp], 11, 11); // Set the value.
  741.                             funcParseTitle(); // Reparse the title.
  742.                         }
  743.                         else if(~llListFindList(colors, [m]))
  744.                         {
  745.                             titles = llListReplaceList(titles, [llList2String(colors, (llListFindList(colors, [m])+1))], 11, 11); // Set the value.
  746.                             funcParseTitle(); // Reparse the title.
  747.                         }
  748.                         else if(llToLower(m) == "random")
  749.                         {
  750.                             titles = llListReplaceList(titles, [(string)llFrand(255.0)+","+(string)llFrand(255.0)+","+(string)llFrand(255.0)], 11, 11); // Set the value.
  751.                             funcParseTitle(); // Reparse the title.
  752.                         }
  753.                         else
  754.                         {
  755.                             llOwnerSay("Colour changing failed. Invalid vector, or colour preset doesn't exist. Your command: "+command);
  756.                         }
  757.                     }
  758.                     // Let's do regens.
  759.                     else if(llGetSubString(llToLower(m), 0, 8) == "postregen") // If we're using a postregen command...
  760.                     {
  761.                         list temp; // Prepare temporary list.
  762.                         m = llDeleteSubString(m, 0, 8); // Clean the string.
  763.                         m = llStringTrim(m, STRING_TRIM_HEAD); // Trim leading and trailing spaces.
  764.                         temp = llParseStringKeepNulls(m, [" "], []); // Parse the postregen values to a list.
  765.                         if(llGetListLength(temp) < 2 || llGetListLength(temp) > 2) // If the list length is smaller or higher than 2, something went wrong.
  766.                         {
  767.                             llOwnerSay("Failed to set the post regen. Too many or too few values in command. Your command: "+command);
  768.                             return;
  769.                         }
  770.                         titles = llListReplaceList(titles, [llList2String(temp, 0),llList2String(temp, 1)], 9, 10); // Update the titles list with the correct values.
  771.        
  772.                         if(showCap && llList2String(titles, 8) == "off")
  773.                         {
  774.                             funcParseTitle(); // Reparse the title if showCal is on and percent is off.
  775.                         }
  776.                     }
  777.                     // What version are we on?
  778.                     else if(llToLower(m) == "version")
  779.                     {
  780.                         llOwnerSay(name+version);
  781.                     }
  782.                     // For changing which channel we listen to!
  783.                     else if(llGetSubString(llToLower(m), 0, 12) == "changechannel")
  784.                     {
  785.                         m = llDeleteSubString(m, 0, 12);
  786.                         m = llStringTrim(m, STRING_TRIM);
  787.                         if(IsInteger(m)) // If valid integer...
  788.                         {
  789.                             if(m != "4" && m != "3" && m != "22" && m != "44")
  790.                             {
  791.                                 llListenRemove(titleChanHandler); // Remove this listen.
  792.                                 titleChanHandler = FALSE;
  793.                                
  794.                                 titleChan = (integer)m; // Update the titleChan value.
  795.                                
  796.                                
  797.                                 titleChanHandler = llListen(titleChan, "", "", ""); // Set a new listen.
  798.                                 llOwnerSay("Successfully changed operating channel to: "+(string)titleChan+"\nRemember to update this in your HUD to reflect this change if you use it."); // And announce!
  799.                                 llMessageLinked(LINK_THIS, 1330, (string)titleChan, "");
  800.                             }
  801.                             else
  802.                             {
  803.                                 llOwnerSay("You cannot use chatter channels as titler channels.");
  804.                             }
  805.                         }
  806.                         else
  807.                         {
  808.                             llOwnerSay("Couldn't change RP tool option channel - invalid integer. Your command: "+command);
  809.                         }
  810.                     }
  811.                     // Toggle comma parsing!
  812.                     else if(llToLower(m) == "comma")
  813.                     {
  814.                         string isComma = llList2String(titles, 12);
  815.                        
  816.                         if(IsInteger(isComma))
  817.                         {
  818.                             if(isComma == "0")
  819.                             {
  820.                                 isComma = "1";
  821.                             }
  822.                             else if(isComma == "1")
  823.                             {
  824.                                 isComma = "2";
  825.                             }
  826.                             else if((integer)isComma >= 2)
  827.                             {
  828.                                 isComma = "0";
  829.                             }
  830.                            
  831.                             titles = llListReplaceList(titles, [(string)isComma], 12, 12);                            
  832.                             funcParseTitle();
  833.                         }
  834.                     }
  835.                     else if(llGetSubString(llToLower(m), 0, 2) == "ooc")
  836.                     {
  837.                         out = 1;
  838.                         m = llDeleteSubString(m, 0, 2);
  839.                         m = llStringTrim(m, STRING_TRIM);
  840.                         if(llToLower(m) == "none" || llToLower(m) == "hide")
  841.                         {
  842.                             ooc = "";
  843.                         }
  844.                         else if(m != "")
  845.                         {
  846.                             ooc = "["+m+"]";
  847.                         }
  848.                         funcParseTitle();
  849.                     }
  850.                     else if(llGetSubString(llToLower(m), 0, 2) == "afk")
  851.                     {
  852.                         out = 2;
  853.                         m = llDeleteSubString(m, 0, 2);
  854.                         m = llStringTrim(m, STRING_TRIM);
  855.                         if(llToLower(m) == "none" || llToLower(m) == "hide")
  856.                         {
  857.                             afk = "";
  858.                         }
  859.                         else if(m != "")
  860.                         {
  861.                             afk = "["+m+"]";
  862.                         }
  863.                         funcParseTitle();
  864.                     }
  865.                     else if(llGetSubString(llToLower(m), 0, 3) == "back" || llGetSubString(llToLower(m), 0, 1) == "ic")
  866.                     {
  867.                         out = 0;
  868.                         funcParseTitle();
  869.                     }
  870.        
  871.                     else if(llToLower(m) == "save")
  872.                     {
  873.                         saveorload = 1;
  874.                         llMessageLinked(LINK_THIS, 3, m, "");
  875.                     }
  876.                     else if(llToLower(m) == "load")
  877.                     {
  878.                         saveorload = 2;
  879.                         llMessageLinked(LINK_THIS, 3, m, "");
  880.                     }
  881.                     // Rolling commands!
  882.                     else if(llGetSubString(llToLower(m), 0, 3) == "roll")
  883.                     {
  884.                         integer faces = 20;
  885.                         m = llDeleteSubString(m, 0, 3);
  886.                         m = llStringTrim(m, STRING_TRIM);
  887.                         list tmp = llParseStringKeepNulls(m, [" "], []);
  888.                         if(IsInteger(llList2String(tmp, 0)) && (integer)llList2String(tmp, 0) > 1)
  889.                         {
  890.                             faces = (integer)llList2String(tmp, 0);
  891.                         }
  892.                         llSetObjectName(llList2String(titles, 0)+"'s Dice Roll (D"+(string)faces+")");
  893.                         integer result = diceRoll(faces);
  894.                         if (result == 20)
  895.                         {
  896.                             llSay(0, "" +  llSetObjectName(llList2String(titles, 0)) + "has rolled a [" + (string)result + "]. (Critical Strike!)");
  897.                         }
  898.                         if (result == 1)
  899.                         {
  900.                             llSay(0, "" +  llSetObjectName(llList2String(titles, 0)) + "has rolled a [" + (string)result + "]. (Critical Fail!)");
  901.                         }
  902.                         else if(result > 1 & result < 20)
  903.                         {
  904.                             llSay(0, "" +  llSetObjectName(llList2String(titles, 0)) + "has rolled a [" + (string)result) + "].");
  905.                         }
  906.                         else
  907.                         {
  908.                             llOwnerSay("You need to specify at least 2 sides!");
  909.                         }
  910.                         llSetObjectName(name+version);
  911.                     }
  912.                     else if(llGetSubString(llToLower(m), 0, 9) == "silentroll")
  913.                     {
  914.                         integer faces = 20;
  915.                         m = llDeleteSubString(m, 0, 9);
  916.                         m = llStringTrim(m, STRING_TRIM);
  917.                         list tmp = llParseStringKeepNulls(m, [" "], []);
  918.                         if(IsInteger(llList2String(tmp, 0)) && (integer)llList2String(tmp, 0) > 1)
  919.                         {
  920.                             faces = (integer)llList2String(tmp, 0);
  921.                         }
  922.                         llSetObjectName(llList2String(titles, 0)+"'s Private Dice Roll (D"+(string)faces+")");
  923.                         integer result = diceRoll(faces);
  924.                         if(result > 0)
  925.                         {
  926.                             llOwnerSay((string)result);
  927.                         }
  928.                         else
  929.                         {
  930.                             llOwnerSay("You need to specify at least 2 sides!");
  931.                         }
  932.                         llSetObjectName(name+version);
  933.                     }
  934.                     // To give the help notecard.
  935.                     else if(llToLower(m) == "help")
  936.                     {
  937.                         llGiveInventory(llGetOwner(), "Simple Hud Instructions");    
  938.                     }
  939.                     else if(llToLower(m) == "changetitle")
  940.                     {
  941.                         showDialog(1);
  942.                     }
  943.                     else if(llToLower(m) == "changeconstant")
  944.                     {
  945.                         showDialog(2);
  946.                     }
  947.                     else if(llToLower(m) == "showcap")
  948.                     {
  949.                         if(showCap)
  950.                         {
  951.                             showCap = FALSE;
  952.                         }
  953.                         else
  954.                         {
  955.                             showCap = TRUE;
  956.                         }
  957.                         funcParseTitle();
  958.                     }
  959.                     else if(llToLower(llGetSubString(m, 0, 4)) == "alpha")
  960.                     {
  961.                         list tmp = llParseString2List(llToLower(m), [" "], []); // Parses the lowercased string into a list separated by whitespace.
  962.                         if(llList2String(tmp, 1) == "hide") // Obvious.
  963.                         {
  964.                             alpha = -1.0;
  965.                         }
  966.                         else if(llList2String(tmp, 1) == "show") // Obvious.
  967.                         {
  968.                             alpha = 1.0;
  969.                         }
  970.                         else if((integer)((string)((integer)llList2String(tmp, 1)))) // If the value is an integer, apply it.
  971.                         {
  972.                             alpha = (float)llList2Integer(tmp, 1)/100;
  973.                         }
  974.                         else // If none of the above are true, error and exit.
  975.                         {
  976.                             llOwnerSay("Sorry, couldn't recognize float value. Your input: "+ command);
  977.                             return;
  978.                         }
  979.                         funcParseTitle(); // And parse the title.
  980.                     }
  981.                     else // If none of the above match then we're probably updating titles...
  982.                     {
  983.                         // First let's just parse the entire string to a list, and then take the first value of that from it...
  984.                         list msg = llList2List(llParseString2List(m, [" "], []), 0, 0); // What's our value here...
  985.                         integer i = (llGetListLength(constants) - 1); // Get the length of our constants list.
  986.                         integer x; // Our counting integer!
  987.                         integer location = -1; // Where in the list we are...
  988.                         string cnst; // Temporary string for constants.
  989.                         if(~llSubStringIndex(llList2String(msg, 0), "_"))
  990.                         {
  991.                             // If there is underscore, treat as whitewspace.
  992.                             msg = llListReplaceList(msg, [llDumpList2String(llParseString2List(llList2String(msg, 0), ["_"], []), " ")], 0, 0);
  993.                         }
  994.                         for(x=0;x<=i;x++) // Begin the loop...
  995.                         {
  996.                             // Now we're going to find which location our title's at...
  997.                             cnst = llToLower(llList2String(constants, x)); // Parse to string.
  998.                             if(llGetSubString(cnst, -1, -1) == ":" && llGetSubString(llList2String(msg, 0), -1, -1) != ":") // If there's a colon there and it's not present in the command, we'll remove it.
  999.                             {
  1000.                                 cnst = llDeleteSubString(cnst, -1, -1);
  1001.                             }
  1002.                             if(cnst == llToLower(llList2String(msg, 0))) // If the constants match up exactly, we have our title!
  1003.                             {
  1004.                                 location = x;
  1005.                                 jump break;
  1006.                             }
  1007.                         }
  1008.                         @break;
  1009.                         if(location < 0) // If after the loop is done, we have no location...
  1010.                         {
  1011.                             //llOwnerSay("Couldn't find your title. Your command: "+command); // Error away!
  1012.                             return; // And exit.
  1013.                         }
  1014.                         // But if all went as planned...
  1015.                         // Then we're going to update a title. So let's update!
  1016.        
  1017.                         if(location > 7) // If tmp is bigger than 7...
  1018.                         {
  1019.                             llOwnerSay("Could not update title. Title number not valid. Your command: "+command);
  1020.                             return;
  1021.                         }
  1022.        
  1023.                         m = llDeleteSubString(m, 0, (llStringLength(llList2String(msg, 0))-1)); // Then delete "title#" from the string.
  1024.                         m = llStringTrim(m, STRING_TRIM); // Trim the string for leading and trailing spaces.
  1025.                         if(location == 7 && (string)((integer)m) != m) // If we're updating our energy, and M is not an integer...
  1026.                         {
  1027.                             if(llToLower(m) == "hide" || llToLower(m) == "none")
  1028.                             {
  1029.                                 m = "";
  1030.                             }
  1031.                             else
  1032.                             {
  1033.        
  1034.                                 //llOwnerSay("Couldn't update title: "+llList2String(constants, location)+". Your value is not an integer! Your command: "+command);
  1035.                                 //return;
  1036.                             }
  1037.                         }
  1038.                         else if(llToLower(m) == "hide" || llToLower(m) == "none")
  1039.                         {
  1040.                             m = "";
  1041.                         }
  1042.                         funcUpdTitle(FALSE, location, m); // Then update the title!
  1043.                     }
  1044.        
  1045.                 } // End c == 1
  1046.                 else if(c == Key2AppChan(llGetOwner(), 4321)) // Let's select titles.
  1047.                 {
  1048.                     if(!changeIt)
  1049.                     {
  1050.                         selected = m;
  1051.                         integer i = ((integer)llGetSubString(selected, -1, -1) - 1); // Get the number.
  1052.                         llTextBox(llGetOwner(), "Title "+(string)(i+1)+": ("+llList2String(constants, i)+") "+llList2String(titles, i), changeTitle);
  1053.                         changeIt = TRUE;
  1054.                     }
  1055.                     else
  1056.                     {
  1057.                         integer i = ((integer)llGetSubString(selected, -1, -1) - 1); // Get the number.
  1058.                         if(llToLower(m) == "none" || llToLower(m) == "hide")
  1059.                         {
  1060.                             m = "";
  1061.                         }
  1062.                         //titles = llListReplaceList(titles, [m], i, i);
  1063.                         funcUpdTitle(FALSE, i, m); // Then update the title!
  1064.                         changeIt = FALSE;
  1065.                         llListenRemove(changeTitleHandler);
  1066.                         changeTitleHandler = FALSE;
  1067.                         changeTitle = FALSE;
  1068.                         selected = "";
  1069.                         //funcParseTitle();
  1070.                     }
  1071.                 } // End
  1072.                 else if(c == Key2AppChan(llGetOwner(), 4322)) // Let's select constants.
  1073.                 {
  1074.                     if(!changeIt)
  1075.                     {
  1076.                         selected = m;
  1077.                         integer i = ((integer)llGetSubString(selected, -1, -1) - 1); // Get the number.
  1078.                         llTextBox(llGetOwner(), "Title "+(string)(i+1)+": ("+llList2String(constants, i)+") "+llList2String(titles, i), changeTitle);
  1079.                         changeIt = TRUE;
  1080.                     }
  1081.                     else
  1082.                     {
  1083.                         integer i = ((integer)llGetSubString(selected, -1, -1) - 1); // Get the number.
  1084.                         if(llToLower(m) == "none" || llToLower(m) == "hide")
  1085.                         {
  1086.                             m = "";
  1087.                         }
  1088.                         //constants = llListReplaceList(constants, [m], i, i);
  1089.                         funcUpdTitle(TRUE, i, m); // Then update the title!
  1090.                         changeIt = FALSE;
  1091.                         llListenRemove(changeTitleHandler);
  1092.                         changeTitleHandler = FALSE;
  1093.                         changeTitle = FALSE;
  1094.                         selected = "";
  1095.                         //funcParseTitle();
  1096.                     }
  1097.                }
  1098.             }
  1099.     }
  1100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement