Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // on prim database
- //*********************************************************
- // User Defined
- //*********************************************************
- float fl_timeout = 60.0;// menu timer - how long to wait for an answer
- //*********************************************************
- // Global Variables
- //*********************************************************
- integer mmhandler; // listen handler
- integer aanhandler; // listen handler for add a name
- integer i_chan;// negative channel for menus generated randomly at start
- key k_touched;// key of the avatar that touched the prim/hud
- string s_header;// Message at the top of the main menu
- list l_buttons;// button text for main menu
- string s_TextHeader;// Text box message for add and delete names
- string s_ConfirmMessage;
- list l_ConfirmButtons;
- //*********************************************************
- // Functions
- //*********************************************************
- f_Configure()
- {
- // set up a random channel
- i_chan = -1 - (integer)("0x" + llGetSubString( (string) llGetKey(), -7, -1) );
- // Main Menu set up
- s_header = " 1 - Add a name" + "\n" +
- " 2 - Delete a name" + "\n" +
- " 3 - List Names" + "\n" +
- " 4 - Reset (does not erase names)";
- l_buttons = ["1","2","3","4"];
- s_TextHeader = "Preferred Method: Enter the UUID of the person to add\n" +
- "Alternate Method: enter the legacy name (not display name) of the person.\n" +
- "Either first.last for older names or firstlast for newer ones.\n" +
- "the last name Resident is NOT needed and will cause an error.\n" +
- "If the key is not found try adding it at http://w-hat.com/#name2key\n" +
- "then entering the name again. You have 1 minute.\n" +
- "TO CANCEL WIHTOUT ENTERING A NAME TYPE cancel";
- s_ConfirmMessage = "Is this name correct? ";
- l_ConfirmButtons = ["YES", "NO", "Cancel"];
- }
- f_MainMenu(key k_id)
- {// use in touch start event
- // i_chan set in f_Configure
- string s_name; // filter for specific prim name or legacy avatar name
- //key k_id;// filter for UUID of group, avatar or prim
- string s_msg; // filter for specific message
- // open listener and apply to handle
- mmhandler = llListen(i_chan, s_name, k_id, s_msg);
- // set timer to close listener if no response
- llSetTimerEvent(fl_timeout);
- // send Dialog menu to chose from
- llDialog(k_id, s_header, l_buttons, i_chan);
- // back to state running for listen event
- }
- //*********************************************************
- f_AddAName(key k_id)
- {
- string s_name;// filter for specific prim name or legacy avatar name
- //key k_id;// filter for UUID of group, avatar or prim
- string s_msg; // filter for specific message
- // open the listener
- aanhandler = llListen(i_chan, s_name, k_id, s_msg);
- // set timer to close listener if no response
- llSetTimerEvent(fl_timeout);
- // Send the textbox
- llTextBox(k_id, s_TextHeader, i_chan);
- // returns to state addname listen
- }
- //*********************************************************
- string f_ProcessName(string message)
- {
- message = llStringTrim(llToLower(message), STRING_TRIM);
- // The trim string ensures that the first position is NOT a space
- // so if there is a space it will be in location 1+
- // -1 is a TRUE response so must compare to get a false
- if (llSubStringIndex(message, " ") != -1)
- {
- llSay(0, message + " 4");
- llInstantMessage(k_touched,"Invalid format. Do not use spaces");
- return message = "";
- }
- // Resident could start in position 0 which would return a false
- // if you don't add one to the result - on the other hand if it is
- // NOT there it returns -1 which still equals 0 and is correct
- else if (llSubStringIndex(message, "resident") + 1)
- {
- llInstantMessage(k_touched,"Invalid format. Do not use Resident");
- return message = "";
- }
- // The . to be accurate must be in at least the 4th position returning a result
- // of 3 as a minimum so no addition is necessary.
- else if (llSubStringIndex(message, ".") == -1)
- {
- message = message + ".Resident";
- return message;
- }
- else
- return message;
- // returning to state addname listen
- }
- f_ConfirmAdd(string message)
- {
- // Confirm the name is right
- string s_name;// filter for specific prim name or legacy avatar name
- //key k_id;// filter for UUID of group, avatar or prim
- string s_msg; // filter for specific message
- // open the listener
- aanhandler = llListen(i_chan, s_name, k_touched, s_msg);
- // set timer to close listener if no response
- llSetTimerEvent(fl_timeout);
- llDialog(k_touched, s_ConfirmMessage + message, l_ConfirmButtons, i_chan);
- }
- //*********************************************************
- //*********************************************************
- default
- {
- state_entry()
- {
- // configure and set up
- f_Configure();
- state running;
- }
- }
- state running
- {// normal running state - no need to redo setup
- touch_start(integer num_det)
- {
- k_touched = llDetectedKey(0);
- f_MainMenu(k_touched);
- }
- listen(integer channel, string name, key id, string message)
- {
- llListenRemove(mmhandler);
- llSetTimerEvent(0.0);
- if ("1" == message)
- state addname;
- else if ("2" == message)
- llOwnerSay("Two");
- else if ("3" == message)
- llOwnerSay("Three");
- else if ("4" == message)
- llOwnerSay("Four");
- else
- {
- llInstantMessage(k_touched, "Invalid Option please try again");
- f_MainMenu(k_touched);
- }
- }
- timer()
- {
- llSetTimerEvent(0.0);
- llListenRemove(mmhandler);
- llInstantMessage(k_touched, "Main Menu timed out. Touch to try again.");
- }
- }
- state addname
- {
- state_entry()
- {
- f_AddAName(k_touched);
- }
- listen(integer channel, string name, key id, string message)
- {
- llListenRemove(aanhandler);
- llSetTimerEvent(0.0);
- llSay(0, message + " 5");
- // Confirm Name and add yes
- if ("YES" == message)
- {
- llSleep(0.01); //f_SaveMessage();
- llSay(0, "Saved");
- }
- // Confirm and add no - have them enter it again
- else if ("NO" == message) f_AddAName(k_touched);
- // Confirm and add cancel - return to normal state
- else if ("Cancel" == message) state running;
- // Confirmation Message not sent yet this is processing the name
- // If they didn't enter anything give error and resend
- else if (message)
- {
- llSay(0, message + " 1");
- message = llStringTrim(llToLower(message), STRING_TRIM);
- llSay(0, message + " 2");
- if ("cancel" == message)
- return;
- else
- {
- llSay(0, message + " 3");
- message = f_ProcessName(message);
- f_ConfirmAdd(message);
- }
- }
- else
- f_AddAName(k_touched);
- state running;
- }
- timer()
- {
- llSetTimerEvent(0.0);
- llListenRemove(mmhandler);
- llInstantMessage(k_touched, "Menu timed out. Touch to try again.");
- state running;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement