Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Group Handling

Wesley Spengler
Never Enough L$
Join date: 8 Feb 2006
Posts: 26
04-09-2006 21:08
I'd like to have an object be able to respond to touch only by its owner, or group members -- and then, only if a group has been set on the object.

Reading the scripting wiki sort of makes this seem somewhat impossible. Is it? And are there sample code snippets available that might demonstate how to make it work?
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-10-2006 01:31
This snippet should work if I've understood your request properly. (I've written it straight in here, so there may be silly typos and things)

CODE

touch_start(integer num)
{
key toucher=llDetectedKey(0);
if(toucher==llGetOwner() || llSameGroup(toucher))
{
//do stuff
}
}
Wesley Spengler
Never Enough L$
Join date: 8 Feb 2006
Posts: 26
04-11-2006 06:48
From: Eloise Pasteur
This snippet should work if I've understood your request properly.


The only issue here is this (from my original request): and then, only if a group has been set on the object.

My understanding is that llSameGroup() returns true if the object has no group set, and neither does the avatar, which makes it pretty useless for limiting access to a group since that's going to apply in (perhaps) the majority of cases.

I still think what I really want here is impossible, although I'd like to confirm it absolutely.
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-11-2006 09:29
Passing NULL_KEY to llSameGroup will tell you whether the object has a group set or not.

CODE

touch_start(integer total_number)
{
key toucher = llDetectedKey(0);
if (toucher != llGetOwner()){ //toucher isn't the owner
if (llSameGroup(toucher)){ //toucher IS in the same group
if (llSameGroup(NULL_KEY)){
jump out; //but the group is "blank" so skip to the end
}
}
}

//do stuff here

@out;
}


I'm sure there's a more effecient way to do this... but it's not coming to me right now.
_____________________
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-11-2006 11:44
Passing NULL_KEY to llSameGroup will tell you whether the object has a group set or not.

CODE

touch_start(integer num_detected){
key toucher = llDetectedKey(0);
if (toucher != llGetOwner()){ //toucher isn't the owner
if (llSameGroup(toucher)){ //toucher IS in the same group
if (llSameGroup(NULL_KEY)){ //the group is "blank"
jump out; //skip to end
}
} else { //toucher wasn't even in the same group
jump out; //skip to end
}
}

//do stuff here

@out;
}


There... I think I finally got it right. :p There's probably a more effecient way to do it though.
_____________________
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-11-2006 15:45
This is a bit cleaner...

CODE

touch(integer num_detected){
key toucher = llDetectedKey(0);
//toucher is the owner or in the same group
if (toucher == llGetOwner() || llSameGroup(toucher)){
//group is "blank" and toucher wasn't the owner
if (toucher != llGetOwner() && llSameGroup(NULL_KEY)) return;

//do stuff here
}
}
_____________________
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-11-2006 16:49
I love threads where I can nitpick really tiny issues :) So here's my gripe with your second solution - it calls llGetOwner twice, and it's a little confusing because you have "toucher != llGetOwner" inside "toucher == llGetOwner". Here's how I would write it, and I think this improves readibility a bit, at the expense of introducing an extra variable.

CODE

touch_start(integer num_detected)
{
key toucher = llDetectedKey(0);
integer allow = FALSE; // Guilty until proven innocent

if (toucher == llGetOwner())
{
// It's the owner
allow = TRUE;
}
else if (llSameGroup(toucher) && !llSameGroup(NULL_KEY))
{
// Object has a group set, and it matches the toucher's group
allow = TRUE;
}

if (allow)
{
// Do stuff here
}
}


:)
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-11-2006 19:02
Yet shorter... :p

CODE

touch_start(integer num_detected){
key toucher = llDetectedKey(0);
if (toucher != llGetOwner() && llSameGroup(NULL_KEY)) return;
if (!llSameGroup(toucher)) return;

//do stuff here

}
_____________________
SteveR Whiplash
teh Monkeh
Join date: 24 Sep 2004
Posts: 173
04-11-2006 19:32
:p

CODE

touch_start(integer num_detected){
key toucher = llDetectedKey(0);
if (toucher != llGetOwner()){
if (!llSameGroup(toucher) || llSameGroup(NULL_KEY)) return;
}
//do stuff here
}
_____________________
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-12-2006 08:18
LOL. Yep, that's better :) But it's a very... negative approach to life ;)
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-12-2006 13:08
I love playing "I Can Write That Code". :)
From: SteveR Whiplash
:p

CODE

touch_start(integer num_detected){
key toucher = llDetectedKey(0);
if (toucher != llGetOwner()){
if (!llSameGroup(toucher) || llSameGroup(NULL_KEY)) return;
}
//do stuff here
}
Put "isInMyGroup(key agent)" in your toolbox:
CODE
integer isInMyGroup(key agent)
{
if(agent == llGetOwner()) return TRUE;
if(llSameGroup(NULL_KEY)) return FALSE;
if(llSameGroup(agent)) return TRUE;
return FALSE;
}
//...

touch start(integer n)
{
if(isInMyGroup(llDetectedKey(0))
{
doTheCoolStuff();
}
}