Jump to content

I broke something on this hover titler script that can be adjusted with a touching the object to get a menu


Recommended Posts

So I am just wanting to create a menu for my friend as she runs some PVE combat. It takes forever for her to set it up.
I wanted to have it where she can use the script touch each one and change some numbers. then when damage is taken, she can touch it and reduce the HP by the damage without having to worry much. I am note very good of a coder but i really thought this would be a nice thing for her.

 

// Constants for menu options
integer MENU_OPTION_ADD_NAME = 1;
integer MENU_OPTION_ADD_HP = 2;
integer MENU_OPTION_ADD_SOAK = 3;
integer MENU_OPTION_ADD_CHASE_DODGE = 4;
integer MENU_OPTION_ADD_PERCEPTION = 5;
integer MENU_OPTION_ADD_RESISTANCE = 6;
integer MENU_OPTION_ADD_WILLPOWER = 7;
integer MENU_OPTION_CHANGE_COLOR = 8;
integer MENU_OPTION_ADD_SOAKABLE_DAMAGE = 9;
integer MENU_OPTION_ADD_NON_SOAK_DAMAGE = 10;

// Default hover text
string defaultHoverText = "Name: Default\nHealth: 12\nSoak: 2\nChase/Dodge: 15\nPerception: 13\nResistance: 15\nWillpower: 4";
vector defaultColor = <1.0, 1.0, 1.0>; // Default text color is white

// Variables to store current values
string currentName = "Default";
integer currentHP = 12;
integer currentSoak = 2;
integer currentChaseDodge = 15;
integer currentPerception = 13;
integer currentResistance = 15;
integer currentWillpower = 4;
vector currentColor = defaultColor;

// Main script
default
{
    state_entry()
    {
        // Set initial hover text and color
        llSetText(defaultHoverText, defaultColor, 1.0);
        
        // Generate unique menu channel based on object UUID
        menuChannel = (integer)("0x" + llGetSubString((string)llGetKey(), 0, 6));
        
        // Set up menu
        llListen(menuChannel, "", NULL_KEY, "");
    }

    touch_start(integer total_number)
    {
        // Open menu when touched
        llDialog(llDetectedKey(0), "Select an option:", ["Add Name", "Add HP", "Add Soak", "Add Chase/Dodge", "Add Perception", "Add Resistance", "Add Willpower", "Change Color", "Add Soakable Damage", "Add Non-Soak Damage"], menuChannel);
    }

    // Listen for menu choices
    listen(integer channel, string name, key id, string message)
    {
        if (channel != menuChannel) return;

        if (message == "Add Name")
        {
            llOwnerSay("Please type the name you want to add:");
        }
        else if (message == "Add HP")
        {
            llOwnerSay("Please type the HP value you want to add:");
        }
        else if (message == "Add Soak")
        {
            llOwnerSay("Please type the Soak value you want to add:");
        }
        else if (message == "Add Chase/Dodge")
        {
            llOwnerSay("Please type the Chase/Dodge value you want to add:");
        }
        else if (message == "Add Perception")
        {
            llOwnerSay("Please type the Perception value you want to add:");
        }
        else if (message == "Add Resistance")
        {
            llOwnerSay("Please type the Resistance value you want to add:");
        }
        else if (message == "Add Willpower")
        {
            llOwnerSay("Please type the Willpower value you want to add:");
        }
        else if (message == "Change Color")
        {
            llDialog(llDetectedKey(0), "Select a color:", ["Red", "Yellow", "Green"], menuChannel);
        }
        else if (message == "Add Soakable Damage")
        {
            llOwnerSay("Please type the amount of soakable damage:");
        }
        else if (message == "Add Non-Soak Damage")
        {
            llOwnerSay("Please type the amount of non-soak damage:");
        }
    }

    // Listen for typed responses
    changed(integer change)
    {
        if (change & CHANGED_OWNER)
        {
            string response = llGetOwnerSay();
            
            if (llSubStringIndex(response, "Please type the name") != -1)
            {
                currentName = llStringTrim(llGetSubString(response, 7, -1), STRING_TRIM);
            }
            else if (llSubStringIndex(response, "Please type the HP") != -1)
            {
                currentHP += (integer)response;
            }
            else if (llSubStringIndex(response, "Please type the Soak") != -1)
            {
                currentSoak += (integer)response;
            }
            else if (llSubStringIndex(response, "Please type the Chase/Dodge") != -1)
            {
                currentChaseDodge += (integer)response;
            }
            else if (llSubStringIndex(response, "Please type the Perception") != -1)
            {
                currentPerception += (integer)response;
            }
            else if (llSubStringIndex(response, "Please type the Resistance") != -1)
            {
                currentResistance += (integer)response;
            }
            else if (llSubStringIndex(response, "Please type the Willpower") != -1)
            {
                currentWillpower += (integer)response;
            }
            else if (response == "Red")
            {
                currentColor = <1.0, 0.0, 0.0>; // Red color
            }
            else if (response == "Yellow")
            {
                currentColor = <1.0, 1.0, 0.0>; // Yellow color
            }
            else if (response == "Green")
            {
                currentColor = <0.0, 1.0, 0.0>; // Green color
            }
            else if (llSubStringIndex(response, "Please type the amount of soakable damage") != -1)
            {
                integer damage = (integer)response;
                currentHP -= llMax(0, damage - currentSoak);
            }
            else if (llSubStringIndex(response, "Please type the amount of non-soak damage") != -1)
            {
                currentHP -= llMax(0, (integer)response);
            }
            
            // Update hover text
            string hoverText = llDumpList2String([llDumpList2String(["Name: ", currentName]), llDumpList2String(["Health: ", (string)currentHP]), llDumpList2String(["Soak: ", (string)currentSoak]), llDumpList2String(["Chase/Dodge: ", (string)currentChaseDodge]), llDumpList2String(["Perception: ", (string)currentPerception]), llDumpList2String(["Resistance: ", (string)currentResistance]), llDumpList2String(["Willpower: ", (string)currentWillpower])], "\n");
            llSetText(hoverText, currentColor, 1.0);
        }
    }
}

 

 

Link to comment
Share on other sites

menuChannel wasn't declared as a global variable. Easy enough to fix by adding the line

integer menuChannel;

near the top of the script.

The fundamental issue though is that llGetOwnerSay(); isn't a real function. There are different ways to handle arbitrary text input, but my first choice would be to use llTextBox() on a different channel for each type of expected input. i.e. instead of:

llOwnerSay("Please type the name you want to add:");

maybe

llListenControl(someHandlerForTheChannel,TRUE);
llTextBox(llGetOwner(),"Please type the name you want to add",menuChannel+1);

Your changed event is non-sensical, that logic should be part of the listen event.

 

  • Thanks 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...