Jump to content

"Allowed to use" list / Menu script


Sunbleached
 Share

You are about to reply to a thread that has been inactive for 1349 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello! How to add an option to the menu script to add people to the list of those who are allowed to use this menu?

This is for the wearable object, so that I can choose who else can call the menu besides me.

Please help!

list MENU_MAIN = ["BUT1", "BUT2" , "Add Person" , "Remove Person"]; //up to 12 in list

integer menu_handler;
integer menu_channel;
menu(key user,string title,list buttons)
{
    llListenRemove(menu_handler); //BugFix 5/2008
    menu_channel = (integer)(llFrand(99999.0) * -1);
    menu_handler = llListen(menu_channel,"","","");
    llDialog(user,title,buttons,menu_channel);
    llSetTimerEvent(30.0); //how long to wait for user to press a button before giving up and closing listen
}

default
{
    state_entry()
    {
        //nada
    }

    touch_start(integer total_number)
    {
        menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN);
    }
    
    listen(integer channel,string name,key id,string message)
    {
        if (channel == menu_channel) 
        {
            llListenRemove(menu_handler); //close listen
            llSetTimerEvent(0); //stop timeout timer
            if (message == "BUT1")
            {
// DO SOMETHING
            }
            else if (message == "BUT2")
            {
// DO SOMETHING
            }
            else if (message == "Add Person")
            {
// WHAT TO DO HERE???..
            }
            else if (message == "Remove Person")
            {
// AND WHAT TO DO HERE???
            }
            //else if (message == "Button")
            //{
// DO SOMETHING
            //}
        }
    }
    
    timer() //VERY IMPORTANT menu timeout
    {
        llListenRemove(menu_handler); //close listen
        llSetTimerEvent(0); //stop timeout timer
    }
}

 

Edited by Sunbleached
Link to comment
Share on other sites

It's mildly complicated but, as with each of the other topics you have asked about, I'm sure that you can work through the logic.  Here's the basic challenge:

You want to create a list of people who are allowed to do stuff with your script (open doors, teleport, get gifts,... whatever your script does... ).  So, you need to create a global list variable to put the names (or UUIDs) in.  Then you need a way to add names.  For that, you need to have a way for the user to open a Text Box (with llTextBox), so use one of your dialog buttons to open it.  Then tell your listen event what to do with whatever the user types in the text box  >>> add it to your global list.  That's all there is to it, except ....

What if the user wants to remove a name from the list?  What if the user tries to add the same name twice?  What if the user types a name that does not exist or is not a username?  Again, I'm sure that you can work through the logic of questions like this, but here are some things to think about:

1. You can easily set a flag during the action that opens a text box, and then use that flag to tell the listen event whether it's hearing a name that is supposed to be added or one that is supposed to be removed.  If it's a name to remove, you'll need to find it in the list and then use llDeleteSubList.

2. You can use llListFindList to see whether any particular entry is already in a list you have created.

3. You can use llRequestUserKey to see whether the UUID associated with a name is a real avatar UUID or is NULL_KEY.

And so on.  The basic business of creating the list isn't the hard part.  It's the tests that you have to include to detect when the user has tried to do something impossible or unexpected.

Then once you have the list, all you need to do is look to see if llDetectedName(0) is on it.  If so, the user is allowed to proceed.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

15 hours ago, Rolig Loon said:

It's mildly complicated but, as with each of the other topics you have asked about, I'm sure that you can work through the logic.  Here's the basic challenge:

You want to create a list of people who are allowed to do stuff with your script (open doors, teleport, get gifts,... whatever your script does... ).  So, you need to create a global list variable to put the names (or UUIDs) in.  Then you need a way to add names.  For that, you need to have a way for the user to open a Text Box (with llTextBox), so use one of your dialog buttons to open it.  Then tell your listen event what to do with whatever the user types in the text box  >>> add it to your global list.  That's all there is to it, except ....

What if the user wants to remove a name from the list?  What if the user tries to add the same name twice?  What if the user types a name that does not exist or is not a username?  Again, I'm sure that you can work through the logic of questions like this, but here are some things to think about:

1. You can easily set a flag during the action that opens a text box, and then use that flag to tell the listen event whether it's hearing a name that is supposed to be added or one that is supposed to be removed.  If it's a name to remove, you'll need to find it in the list and then use llDeleteSubList.

2. You can use llListFindList to see whether any particular entry is already in a list you have created.

3. You can use llRequestUserKey to see whether the UUID associated with a name is a real avatar UUID or is NULL_KEY.

And so on.  The basic business of creating the list isn't the hard part.  It's the tests that you have to include to detect when the user has tried to do something impossible or unexpected.

Then once you have the list, all you need to do is look to see if llDetectedName(0) is on it.  If so, the user is allowed to proceed.

Thank you very much for such a detailed answer! It really seems very complicated.

But just in case, if I don’t master such a modification, is there an opportunity to just make an option public/owner only by button?  if(llDetectedKey(0)==llGetOwner())?

I am playing with llTextBox now, this is so cool!

Edited by Sunbleached
Link to comment
Share on other sites

On 9/21/2019 at 5:45 PM, Rolig Loon said:

Certainly. Go for it.

Hello again! I decided to try the option with owner/public. believe it or not but I saw this scheme in a dream tonight. I feel very close to it but I can’t turn it into a script.  At this stage I do not understand how to set a = x or y.  Please help!

if button1 pressed check if    a = x    check owner (llDetectedKey(0)==llGetOwner())

                                             if    owner detected do stuff 1
                                            else    don't do anything

 

                                            else do stuff for everyone (do not check owner)
 
if button2 pressed check if    a = x    check owner
(llDetectedKey(0)==llGetOwner())

                                             if    owner detected do stuff 2
                                            else    don't do anything

 

                                            else    do stuff for everyone (do not check owner)

 

if button3 pressed set a = x <<<? Owner

if button4 pressed set a = y <<<? Public

Edited by Sunbleached
Link to comment
Share on other sites

if (  llGetLinkName(llDetectedLinkNumber(0)) == "Button 1" )
{
    iOwner_only_flag = !Owner_only_flag;
}

 

Then when  someone clicks to operate the device, check

if ( (iOwner_only_flag && llDetectedKey(0) == llGetOwner() } || !Owner_only_flag))   // do stuff

Edited by Rolig Loon
typos. as always.
  • Thanks 1
Link to comment
Share on other sites

34 minutes ago, Rolig Loon said:

if (  llGetLinkName(llDetectedLinkNumber(0)) == "Button 1" )
{
    iOwner_only_flag = !Onwner_only_flag;
}

 

Then when  someone clicks to operate the device, check

if ( (iOwner_only_flag && llDetectedKey(0) == llGetOwner() } || !Owner_only_flag))   // do stuff

thank you very much for your answer! I am not sure what am i doing wrong, but it keeps giving me a syntax error... I guess i am doing something terribly wrong...

i added these lines:

integer iOwner_only_flag;
integer Owner_only_flag;

and to touch event:

    touch_start(integer total_number)
    {
        if ( (iOwner_only_flag && llDetectedKey(0) == llGetOwner() } || !Owner_only_flag))   // do stuff
        menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN);
   }

 

and to buttons listener:

else if (message == "Owner")
{

if (  llGetLinkName(llDetectedLinkNumber(0)) == "Button1" )
{
    iOwner_only_flag = !Owner_only_flag;
}
if (  llGetLinkName(llDetectedLinkNumber(0)) == "Button2" )
{
    iOwner_only_flag = !Owner_only_flag;
}
if (  llGetLinkName(llDetectedLinkNumber(0)) == "Owner" )
{
    iOwner_only_flag = !Owner_only_flag;
}
if (  llGetLinkName(llDetectedLinkNumber(0)) == "Public" )
{
    iOwner_only_flag = !Owner_only_flag;
}

}

Edited by Sunbleached
Link to comment
Share on other sites

1 hour ago, Rolig Loon said:

Oh, so you found the typo?

is clearly meant to be 

iOwner_only_flag = !iOwner_only_flag;

A simple toggle switch.  Good catch.

Oh the typo is ok. I worry about this line if ( (iOwner_only_flag && llDetectedKey(0) == llGetOwner() } || !Owner_only_flag))   // do stuff

So my script now looks like this, no errors but is still always public.

edit: i tried like this but not working

    touch_start(integer total_number)
    {
         if ( (iOwner_only_flag && llDetectedKey(0) == llGetOwner() ) || !Owner_only_flag)   // do stuff
        menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN);
    }

 

integer iOwner_only_flag ;
integer Owner_only_flag;
list MENU_MAIN = ["Button1", "Button1" , "public/owner toggle"]; //up to 12 in list

integer menu_handler;
integer menu_channel;
menu(key user,string title,list buttons)
{
    llListenRemove(menu_handler); //BugFix 5/2008
    menu_channel = (integer)(llFrand(99999.0) * -1);
    menu_handler = llListen(menu_channel,"","","");
    llDialog(user,title,buttons,menu_channel);
    llSetTimerEvent(30.0); //how long to wait for user to press a button before giving up and closing listen
}

default
{
    state_entry()
    {
        //nada
    }

    touch_start(integer total_number)
    {
        if ( iOwner_only_flag && llDetectedKey(0) == llGetOwner()  || !Owner_only_flag)   // do stuff
        menu(llDetectedKey(0), "\nText for Menu.", MENU_MAIN);
}
    
    listen(integer channel,string name,key id,string message)
    {
        if (channel == menu_channel) 
        {
            llListenRemove(menu_handler); //close listen
            llSetTimerEvent(0); //stop timeout timer
            if (message == "Button1")
            {

        llSay(0, "Touched1.");

            }
            else if (message == "Button2")
            {

        llSay(0, "Touched2.");

            }


if (  llGetLinkName(llDetectedLinkNumber(0)) == "public/owner toggle" )
{
    iOwner_only_flag = !iOwner_only_flag;
}




        }
    }
    
    timer() //VERY IMPORTANT menu timeout
    {
        llListenRemove(menu_handler); //close listen
        llSetTimerEvent(0); //stop timeout timer
    }
}

 

Edited by Sunbleached
Link to comment
Share on other sites

16 minutes ago, Sunbleached said:

So my script now looks like this, no errors but is still always public.

edit: i tried like this but not working

Think about where you put that switch....

16 minutes ago, Sunbleached said:

if ( iOwner_only_flag && llDetectedKey(0) == llGetOwner() || !Owner_only_flag)

Do you really want it to switch every time you click on any button?

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1349 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...