Jump to content
Sign in to follow this  
Ackley Bing

One avatar at a time touch controller

Recommended Posts

I made a routine that gives touch ownership allowing only one person at a time to access your touch commands.

If a second avatar touches, the first person must give the second person permission before touch control is handed over. Touch control is automatically given to anyone as long as they are the first one to touch it. Add your own code for additional security (listen channel, etc).

key controllerKey = NULL_KEY;
key requesterKey = NULL_KEY;

default
{
    touch_start(integer total_number)
    {
        if (controllerKey != NULL_KEY)
        {
            if (llDetectedKey(0) == controllerKey)
            {
                // YOUR TOUCH COMMANDS GO HERE
            }
            else
            {
                requesterKey = llDetectedKey(0);
                llListen(1, "", controllerKey, "");
                llDialog(controllerKey, llKey2Name(requesterKey) + "wants contol of me.  Hand over controls?", ["Yes","No"], 1);
            }
        }
        else if (controllerKey == NULL_KEY) controllerKey = llDetectedKey(0);
    }

    listen(integer chan, string name, key id, string message)
    {
        if (chan == 1 && id == controllerKey)
        {
            if (message == "Yes")
            {
llListenRemove(1);
llInstantMessage(controllerKey, "You have granted control to " + llKey2Name(requesterKey) + "."); llInstantMessage(requesterKey, llKey2Name(controllerKey) + " has granted control to you."); controllerKey = requesterKey; } else if (message == "No")
{
llListenRemove(1);
llInstantMessage(requesterKey, llKey2Name(controllerKey) + " is already in control.\nYou must wait until they are done.");
} } } }

 

I have no idea what will happen if many people are all trying to touch it at the same time. :smileywink: I didn't test that possibility.

Share this post


Link to post
Share on other sites

The simple thing to do is to check the total_number parameter.
If (total_number > 1) return;
This means that if there are more touches in the same event, they will be ignored.
You could also give all the touchers some kind of warning and ask them to try again later.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...