Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // on prim database
  2. //*********************************************************
  3. // User Defined
  4. //*********************************************************
  5. float fl_timeout = 60.0;// menu timer - how long to wait for an answer
  6.  
  7. //*********************************************************
  8. // Global Variables
  9. //*********************************************************
  10.  
  11. integer mmhandler; // listen handler
  12. integer aanhandler; // listen handler for add a name
  13. integer i_chan;// negative channel for menus generated randomly at start
  14. key k_touched;// key of the avatar that touched the prim/hud
  15. string s_header;// Message at the top of the main menu
  16. list l_buttons;// button text for main menu
  17. string s_TextHeader;// Text box message for add and delete names
  18. string s_ConfirmMessage;
  19. list l_ConfirmButtons;
  20.  
  21. //*********************************************************
  22. // Functions
  23. //*********************************************************
  24.  
  25. f_Configure()
  26. {
  27.     // set up a random channel
  28.     i_chan = -1 - (integer)("0x" + llGetSubString( (string) llGetKey(), -7, -1) );
  29.     // Main Menu set up
  30.     s_header =  " 1 - Add a name" + "\n" +
  31.                 " 2 - Delete a name" + "\n" +
  32.                 " 3 - List Names" + "\n" +
  33.                 " 4 - Reset (does not erase names)";
  34.     l_buttons = ["1","2","3","4"];
  35.     s_TextHeader = "Preferred Method: Enter the UUID of the person to add\n" +
  36.     "Alternate Method: enter the legacy name (not display name) of the person.\n" +
  37.     "Either first.last for older names or firstlast for newer ones.\n" +
  38.     "the last name Resident is NOT needed and will cause an error.\n" +
  39.     "If the key is not found try adding it at http://w-hat.com/#name2key\n" +
  40.     "then entering the name again. You have 1 minute.\n" +
  41.     "TO CANCEL WIHTOUT ENTERING A NAME TYPE cancel";
  42.     s_ConfirmMessage = "Is this name correct? ";
  43.     l_ConfirmButtons = ["YES", "NO", "Cancel"];
  44. }
  45.  
  46. f_MainMenu(key k_id)
  47. {// use in touch start event
  48.     // i_chan set in f_Configure
  49.     string s_name; // filter for specific prim name or legacy avatar name
  50.     //key k_id;// filter for UUID of group, avatar or prim
  51.     string s_msg; // filter for specific message
  52.     // open listener and apply to handle
  53.     mmhandler = llListen(i_chan, s_name, k_id, s_msg);
  54.     // set timer to close listener if no response
  55.     llSetTimerEvent(fl_timeout);
  56.     // send Dialog menu to chose from
  57.     llDialog(k_id, s_header, l_buttons, i_chan);
  58.     // back to state running for listen event
  59.    
  60. }
  61. //*********************************************************    
  62. f_AddAName(key k_id)
  63. {
  64.     string s_name;// filter for specific prim name or legacy avatar name
  65.     //key k_id;// filter for UUID of group, avatar or prim
  66.     string s_msg; // filter for specific message
  67.     // open the listener
  68.     aanhandler = llListen(i_chan, s_name, k_id, s_msg);
  69.     // set timer to close listener if no response
  70.     llSetTimerEvent(fl_timeout);
  71.     // Send the textbox
  72.     llTextBox(k_id, s_TextHeader, i_chan);
  73.     // returns to state addname listen
  74. }
  75.  
  76. //*********************************************************
  77. string f_ProcessName(string message)
  78. {
  79.     message = llStringTrim(llToLower(message), STRING_TRIM);
  80.     // The trim string ensures that the first position is NOT a space
  81.     // so if there is a space it will be in location 1+
  82.     // -1 is a TRUE response so must compare to get a false
  83.     if (llSubStringIndex(message, " ") != -1)
  84.     {
  85.         llSay(0, message + " 4");
  86.         llInstantMessage(k_touched,"Invalid format. Do not use spaces");
  87.         return message = "";
  88.     }
  89.     // Resident could start in position 0 which would return a false
  90.     // if you don't add one to the result - on the other hand if it is
  91.     // NOT there it returns -1 which still equals 0 and is correct
  92.     else if (llSubStringIndex(message, "resident") + 1)
  93.     {
  94.         llInstantMessage(k_touched,"Invalid format. Do not use Resident");
  95.         return message = "";
  96.     }
  97.     // The . to be accurate must be in at least the 4th position returning a result
  98.     // of 3 as a minimum so no addition is necessary.
  99.     else if (llSubStringIndex(message, ".") == -1)
  100.     {
  101.         message = message + ".Resident";
  102.         return message;
  103.     }
  104.     else
  105.         return message;
  106.         // returning to state addname listen
  107.        
  108. }
  109.  
  110. f_ConfirmAdd(string message)
  111. {
  112.        
  113.     // Confirm the name is right
  114.     string s_name;// filter for specific prim name or legacy avatar name
  115.     //key k_id;// filter for UUID of group, avatar or prim
  116.     string s_msg; // filter for specific message
  117.     // open the listener
  118.     aanhandler = llListen(i_chan, s_name, k_touched, s_msg);
  119.     // set timer to close listener if no response
  120.     llSetTimerEvent(fl_timeout);
  121.     llDialog(k_touched, s_ConfirmMessage + message, l_ConfirmButtons, i_chan);
  122. }
  123.    
  124.  
  125.    
  126. //*********************************************************
  127. //*********************************************************
  128. default
  129. {
  130.     state_entry()
  131.     {
  132.         // configure and set up
  133.         f_Configure();
  134.         state running;
  135.     }
  136. }
  137.  
  138. state running
  139. {// normal running state - no need to redo setup
  140.     touch_start(integer num_det)
  141.     {
  142.         k_touched = llDetectedKey(0);
  143.         f_MainMenu(k_touched);
  144.     }
  145.     listen(integer channel, string name, key id, string message)
  146.     {
  147.         llListenRemove(mmhandler);
  148.         llSetTimerEvent(0.0);
  149.         if ("1" == message)
  150.             state addname;
  151.         else if ("2" == message)
  152.             llOwnerSay("Two");
  153.         else if ("3" == message)
  154.             llOwnerSay("Three");
  155.         else if ("4" == message)
  156.             llOwnerSay("Four");
  157.         else
  158.         {
  159.             llInstantMessage(k_touched, "Invalid Option please try again");
  160.             f_MainMenu(k_touched);
  161.         }
  162.     }
  163.     timer()
  164.     {
  165.         llSetTimerEvent(0.0);
  166.         llListenRemove(mmhandler);
  167.         llInstantMessage(k_touched, "Main Menu timed out. Touch to try again.");
  168.     }
  169. }
  170.        
  171.        
  172. state addname
  173. {
  174.     state_entry()
  175.     {
  176.         f_AddAName(k_touched);
  177.     }
  178.     listen(integer channel, string name, key id, string message)
  179.     {
  180.         llListenRemove(aanhandler);
  181.         llSetTimerEvent(0.0);
  182.         llSay(0, message + " 5");
  183.         // Confirm Name and add yes
  184.         if ("YES" == message)
  185.         {
  186.             llSleep(0.01); //f_SaveMessage();
  187.             llSay(0, "Saved");
  188.         }
  189.         // Confirm and add no - have them enter it again
  190.         else if ("NO" == message) f_AddAName(k_touched);
  191.         // Confirm and add cancel - return to normal state
  192.         else if ("Cancel" == message) state running;
  193.         // Confirmation Message not sent yet this is processing the name
  194.         // If they didn't enter anything give error and resend
  195.         else if (message)
  196.         {
  197.             llSay(0, message + " 1");
  198.             message = llStringTrim(llToLower(message), STRING_TRIM);
  199.             llSay(0, message + " 2");
  200.             if ("cancel" == message)
  201.                 return;
  202.             else
  203.             {
  204.                 llSay(0, message + " 3");
  205.                 message = f_ProcessName(message);
  206.                 f_ConfirmAdd(message);
  207.             }
  208.                
  209.         }
  210.         else
  211.             f_AddAName(k_touched);
  212.        
  213.         state running;
  214.     }
  215.     timer()
  216.     {
  217.         llSetTimerEvent(0.0);
  218.         llListenRemove(mmhandler);
  219.         llInstantMessage(k_touched, "Menu timed out. Touch to try again.");
  220.         state running;
  221.     }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement