Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
5.1 kB
3
Indexable
Never
integer totalPats = 0;
string lastPatter = "None";
integer hoverTextEnabled = TRUE;
integer holdTime = 2; // Time in seconds to trigger the menu
key toucher;
integer isLongPress = FALSE;
vector hoverTextColor = <1.0, 1.0, 1.0>; // Default to white

default
{
    state_entry()
    {
        llSetText("Total Pats: 0\nLast Patter: None", hoverTextColor, 1.0);
        llListen(12345, "", NULL_KEY, ""); // Start listening for menu responses
    }

    touch_start(integer total_number)
    {
        toucher = llDetectedKey(0); // Store the key of the toucher
        llSetTimerEvent(holdTime); // Start a timer for the hold time
        isLongPress = FALSE; // Reset the long press flag
    }

    touch_end(integer total_number)
    {
        llSetTimerEvent(0); // Stop the timer on release

        if (!isLongPress) // Check if it was a short touch
        {
            // Register patting action
            totalPats++;
            string patterName = llDetectedName(0); // Get the name of the person who patted
            lastPatter = patterName; // Update the last patter's name

            // Update the text above the object to show total pats and last patter
            string displayText = "Total Pats: " + (string)totalPats + "\nLast Patter: " + lastPatter;
            llSetText(displayText, hoverTextColor, 1.0);

            // Send a message to local chat with total pats and last patter's name
            llOwnerSay("Total Pats: " + (string)totalPats + "\nLast Patter: " + lastPatter);
        }
    }

    timer()
    {
        llSetTimerEvent(0); // Stop the timer
        isLongPress = TRUE; // Set the flag for long press
        // Show the main menu if the object was held for the designated time
        llDialog(toucher, "Main Menu:\n1. HOVER TEXT\n2. Close", ["HOVER TEXT", "Close"], 12345);
    }

    listen(integer channel, string name, key id, string message)
    {
        if (channel == 12345) // Main Menu Channel
        {
            if (message == "HOVER TEXT")
            {
                // Show the Hover Text submenu with options
                llDialog(id, "Hover Text Menu:\n1. Text On/Off\n2. Change Color\n3. Back", ["Text On/Off", "Change Color", "Back"], 12346);
            }
            else if (message == "Close")
            {
                llListenRemove(channel); // Stop listening when the menu is closed
            }
            else if (message == "Text On/Off")
            {
                // Toggle hover text
                hoverTextEnabled = !hoverTextEnabled;

                if (hoverTextEnabled)
                {
                    // Show hover text
                    string displayText = "Total Pats: " + (string)totalPats + "\nLast Patter: " + lastPatter;
                    llSetText(displayText, hoverTextColor, 1.0); // Show hover text
                    llOwnerSay("Hover text is now ON.");
                }
                else
                {
                    // Clear hover text
                    llSetText("", hoverTextColor, 1.0); // Clear the hover text
                    llOwnerSay("Hover text is now OFF.");
                }
            }
            else if (message == "Change Color")
            {
                // Show color options
                llDialog(id, "Change Color:\n1. Pink\n2. White\n3. Green\n4. Custom\n5. Back", ["Pink", "White", "Green", "Custom", "Back"], 12347);
            }
            else if (message == "Back")
            {
                // Go back to the main menu
                llDialog(id, "Main Menu:\n1. HOVER TEXT\n2. Close", ["HOVER TEXT", "Close"], 12345);
            }
            else if (message == "Pink")
            {
                hoverTextColor = <1.0, 0.0, 0.5>; // Set color to pink
                llOwnerSay("Hover text color changed to Pink.");
            }
            else if (message == "White")
            {
                hoverTextColor = <1.0, 1.0, 1.0>; // Set color to white
                llOwnerSay("Hover text color changed to White.");
            }
            else if (message == "Green")
            {
                hoverTextColor = <0.0, 1.0, 0.0>; // Set color to green
                llOwnerSay("Hover text color changed to Green.");
            }
            else if (message == "Custom")
            {
                llOwnerSay("Custom color option is not implemented. Please specify in chat.");
            }
            else if (message == "Back")
            {
                // Go back to the Hover Text submenu
                llDialog(id, "Hover Text Menu:\n1. Text On/Off\n2. Change Color\n3. Back", ["Text On/Off", "Change Color", "Back"], 12346);
            }

            // Update hover text with the new color if enabled
            if (hoverTextEnabled)
            {
                string displayText = "Total Pats: " + (string)totalPats + "\nLast Patter: " + lastPatter;
                llSetText(displayText, hoverTextColor, 1.0);
            }
        }
    }

    on_rez(integer start_param)
    {
        llResetScript(); // Reset the script when the object is rezzed
    }
}
Leave a Comment