Owner or Group Scripts in LSL

This is just a quick post on an issue that is easy to overlook in making touch scripts work only for the owner or a group. If for example, you set an object to no group, that should include everybody – but it doesn’t! If, for example, you want a door that can be switched to owner or group only on certain occasions by altering its group, but at other times all people (no group) should be able to open that door simply by altering its group back to none, anybody who has a group selected will not be able to open the door as expected.

Try this:

default
{
    touch_start(integer touched)
    {
        if (llDetectedKey(0) == llGetOwner() || llSameGroup(llDetectedKey(0)) == TRUE )
        {
            llSay(0,"This works if you are the owner or in the same group. However, if you the object is in no group and you activate one of your groups, it will react counter-intuitively as though you are not in the same group as it.");
        }
    }
}

Here is a script that enables you to run the relevant tests:

default
{ 
    touch_start(integer n)
    {
        if (llDetectedKey(0) == llGetOwner()) llSay(0,"Owner");
        if (llDetectedGroup(0) == TRUE) llSay(0,"Same group - test one");
        if (llSameGroup(llDetectedKey(0)) == TRUE) llSay(0, "Same group - test two");
        if (llSameGroup(NULL_KEY) == TRUE) llSay(0,"No group");
    }
}

Here is the solution:

default
{
    touch_start(integer touched)
    {
        if (llDetectedKey(0) == llGetOwner() || llSameGroup(llDetectedKey(0)) == TRUE || llSameGroup(NULL_KEY) == TRUE) )        {
            llSay(0,"This works if you are the owner or in the same group. If the group has no valid key i.e. the object is in no group, you can now operate the script even if you have a group enabled.");
        }
    }
}

Sometimes simple things are worth documenting too 🙂

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: