Jump to content

Recommended Posts

I need to create a door that opens only if the avatar holds the key. I have a regular door script, but what to do next?

Please, do not bother to answer if you are not a scripter.

Edited by ainst Composer

Share this post


Link to post
Share on other sites

Script the key part.  😉

There are many ways to meet the challenge.  The common ways are to script the door to respond only to members of the group that the door is set to, or only to people on a specific whitelist (as in this script, for example).   A more difficult approach might be to create an attachment ( a piece of jewelry or a badge, maybe) that is scriipted to respond to a query from your door.  So, the flow of logic would be:

1. User touches the door.

2. The door script pings the user (with llRegionSayTo on a secret channel): "Are you one of us?"

3. The user's attachment hears the message on the secret channel and responds, "Yessir, I am!"

4.  The door unlocks and opens.

 

, for example).

Edited by Rolig Loon
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
37 minutes ago, Rolig Loon said:

Script the key part.  😉

There are many ways to meet the challenge.  The common ways are to script the door to respond only to members of the group that the door is set to, or only to people on a specific whitelist (as in this script, for example).   A more difficult approach might be to create an attachment ( a piece of jewelry or a badge, maybe) that is scriipted to respond to a query from your door.  So, the flow of logic would be:

1. User touches the door.

2. The door script pings the user (with llRegionSayTo on a secret channel): "Are you one of us?"

3. The user's attachment hears the message on the secret channel and responds, "Yessir, I am!"

4.  The door unlocks and opens.

 

, for example).

Thank you very much!

What if to make a sensor door? won't it simplify the task? Can I configure the sensor not on an avatar but on an object?

Share this post


Link to post
Share on other sites

Here's a method using the creation time of the object. The key can't be cheated, and the worn object won't need to have a script in it for the door to check it. This snippet can be used in any script that will detect an avatar (touch, collision, sensor) in order to check they are wearing the key

rez/create the key object you want to use, and paste this script into it.

default
{
    state_entry()
    {
        list details = llGetObjectDetails(llGetKey(),[OBJECT_CREATION_TIME]);     
        llOwnerSay(llList2CSV(details));
        llOwnerSay("Paste the above string into the door script where appropriate");
        llRemoveInventory(llGetScriptName());
    }
}

the "key" object will spit out a creation time string.

then in the door script, to authenticate

paste the above string where it says keycode

string keycode = "PASTE KEY CREATION TIME HERE";

integer checkforkey(key id)
{
    list attachments = llGetAttachedList(id);//gets the list of attachments the avatar is holding
    integer len = llGetListLength(attachments);
    integer i;
    for(i = 0; i < len; i++)//checks each attachment one by one and compares their creation time to the one pasted above
    {
        key attachment = llList2String(attachments,i);
        list details = llGetObjectDetails(attachment,[OBJECT_CREATION_TIME]);
        string time = llList2String(details,0);
        if(time == keycode)return TRUE;
    }
    return FALSE;
}

default
{
    touch_start(integer total_number)
    {
        key id = llDetectedKey(0);
        string name = llGetDisplayName(id);
        integer haskey = checkforkey(id);
        if(haskey)
        {
            llSay(0,"Welcome " + name + "!");
            //do door opening stuff
        }
        else
        {
            llSay(0, "Sorry " + name + ", but you need to holding (wearing) the key to open this door");
        }
    }
}

 

Edited by Ruthven Willenov
  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites
3 minutes ago, Ruthven Willenov said:

Here's a method using the creation time of the object. The key can't be cheated, and the worn object won't need to have a script in it for the door to check it.

rez/create the key object you want to use, and paste this script into it.


default
{
    state_entry()
    {
        list details = llGetObjectDetails(llGetKey(),[OBJECT_CREATION_TIME]);     
        llOwnerSay(llList2CSV(details));
        llOwnerSay("Paste the above string into the door script where appropriate");
        llRemoveInventory(llGetScriptName());
    }
}

the "key" object will spit out a creation time string.

then in the door script, to authenticate (can be easily entered into any touch/collision door script)

paste the above string where it says keycode


string keycode = "PASTE KEY CREATION TIME HERE";

integer checkforkey(key id)
{
    list attachments = llGetAttachedList(id);//gets the list of attachments the avatar is holding
    integer len = llGetListLength(attachments);
    integer i;
    for(i = 0; i < len; i++)//checks each attachment one by one and compares their creation time to the one pasted above
    {
        key attachment = llList2String(attachments,i);
        list details = llGetObjectDetails(attachment,[OBJECT_CREATION_TIME]);
        string time = llList2String(details,0);
        if(time == keycode)return TRUE;
    }
    return FALSE;
}

default
{
    touch_start(integer total_number)
    {
        key id = llDetectedKey(0);
        string name = llGetDisplayName(id);
        integer haskey = checkforkey(id);
        if(haskey)
        {
            llSay(0,"Welcome " + name + "!");
            //do door opening stuff
        }
        else
        {
            llSay(0, "Sorry " + name + ", but you need to holding (wearing) the key to open this door");
        }
    }
}

 

Thank you very much!

Share this post


Link to post
Share on other sites
2 minutes ago, ainst Composer said:

What if to make a sensor door? won't it simplify the task? Can I configure the sensor not on an avatar but on an object?

Not an attached object, but if you really want to go that route, you can use your sensor ( or, even better, llGetAgentList ) to detect nearby avatars and then check out each one with llGetAttachedList to see what they are wearing.  The drawbacks to that approach are

1. llGetAttachedList will not tell you about attached HUDs, so you can't make your key object a HUD

2. A smart bad guy might simply wear a prim named the same as your key.

If you really want to use a variation of the approach you suggested, a smarter way to do it would be to use the script that Ruthven just posted and put it in a piece of jewelry.  The creation time is a hard one to fake.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
3 minutes ago, Rolig Loon said:

Not an attached object, but if you really want to go that route, you can use your sensor ( or, even better, llGetAgentList ) to detect nearby avatars and then check out each one with llGetAttachedList to see what they are wearing.  The drawbacks to that approach are

1. llGetAttachedList will not tell you about attached HUDs, so you can't make your key object a HUD

2. A smart bad guy might simply wear a prim named the same as your key.

If you really want to use a variation of the approach you suggested, a smarter way to do it would be to use the script that Ruthven just posted and put it in a piece of jewelry.  The creation time is a hard one to fake.

And I suppose you could also add the creator's key to the code, because even if you were to manage to find an object with the exact same creation time, it would be impossible to have the same creator

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, Ruthven Willenov said:

And I suppose you could also add the creator's key to the code, because even if you were to manage to find an object with the exact same creation time, it would be impossible to have the same creator

And of course you can encrypt it with a hash key and do all sorts of other things, depending on how concerned you are.  In the end, though, remember that any one-day newbie can get past a locked door in SL.  Locks are fun but cosmetic.

Edited by Rolig Loon
  • Thanks 1

Share this post


Link to post
Share on other sites

There might be a simpler way to do this, which doesn't need sensors, only whispers and listens.

A key is created which is an object with a specific name, such as "front door key", or "master key".

The key is scripted so that when it is attached it whispers it's name on a specific channel. If rezzed but not attached it stays silent.

The door is scripted to listen on that channel. It is programmed to respond to the key name by allowing the door to be opened only when it is hearing the particular name on that channel, so it might allow both "front door key" and "master key" but it would not allow "back door key".

Assuming the channel is chosen so that it is a large negative number the chances of a snooper eavesdropping and learning the door key names are small, so there is some security. 

Whispering will limit the range to 10 metres.

  • Thanks 1

Share this post


Link to post
Share on other sites
11 minutes ago, Profaitchikenz Haiku said:

There might be a simpler way to do this, which doesn't need sensors, only whispers and listens.

Definitely.  Just so you understand, @ainst Composer , neither Ruthven nor I were recommending a sensor in the methods we suggested. You can get the information you want from the user's key object either by using a simple ping/response or by using llGetAgentList, which doesn't require a sensor.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

I agree with @Profaitchikenz Haiku about chat messages being the most basic idea. And based on that concept, if the door script was something like...

// door stuff

default
{
    state_entry()
    {
        // script setup
    }

    touch_start(integer total_number)
    {
        // code to open door, maybe starts a timer
    }
}

You make some changes, like beginning to listen on a secret channel, reacting to messages in the listen event to open the door and only sending a message on touch instead...

// door stuff

default
{
    state_entry()
    {
        // script setup
        llListen(-777, "", "", "");
    }

    touch_start(integer total_number)
    {
        llSay(-777, "ping");
    }

    listen(integer channel, string name, key id, string message)
    {
        if(message == "pong")
        {
            // code to open door, maybe starts a timer
        }
    }
}

Then your door key, listening on that same secret channel, would send a message when it hears the door asking for a key.

default
{
    state_entry()
    {
        llListen(-777, "", "", "");
    }

    listen(integer channel, string name, key id, string message)
    {
        if(message == "ping")
        {
            llSay(-777, "pong");
        }
    }
}

 

Edited by Wulfie Reanimator
  • Thanks 1

Share this post


Link to post
Share on other sites

I like the approach of checking the key with creator + creation date, given that this combo can't be forged in any way.

Obviously it won't work if you intent on selling it.

  • Thanks 1

Share this post


Link to post
Share on other sites
4 hours ago, Kyrah Abattoir said:

I like the approach of checking the key with creator + creation date, given that this combo can't be forged in any way.

Obviously it won't work if you intent on selling it.

oh, why?

Share this post


Link to post
Share on other sites
1 hour ago, ainst Composer said:

oh, why?

Because the same key will fit all the doors you sell, and presumably you'll need to make the key copy/trans so people other than the owner can use the door.

I think the workaround would be to combine the test to see if the person attempting to enter has a key with a test to see if the person with the key is on an access list.   The key, after all, is simply a prop -- you  don't need keys to lock and unlock SL doors, since there are no locks and locking mechanisms.    The test is whether someone is on an access list, not whether they have a key. 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
8 hours ago, Innula Zenovka said:

Because the same key will fit all the doors you sell, and presumably you'll need to make the key copy/trans so people other than the owner can use the door.

I think the workaround would be to combine the test to see if the person attempting to enter has a key with a test to see if the person with the key is on an access list.   The key, after all, is simply a prop -- you  don't need keys to lock and unlock SL doors, since there are no locks and locking mechanisms.    The test is whether someone is on an access list, not whether they have a key. 

Could filter the listen to an object name and the object passes the owners key which the door records on the access list. Could i guess trigger a query message which the key pings back.

Share this post


Link to post
Share on other sites

Well the advantage of fingerprinting the key by creation date+creator was that the key could be a completely inert object. Which is what I thought was interesting.

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.


×
×
  • Create New...