Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Stop script form running when object is worn

Perl Hallstrom
Registered User
Join date: 12 Jun 2007
Posts: 33
11-19-2009 16:44
I have an object with a script. Now I want to be able to stop people from wearing this object. It should only be possible to rez it on the ground.

Is it possible to set such limitations.

Or is it possibe to stop the script from running when someone is wearing it.

Or can I maybe detect from the script that someone is wearing the object and that the object is not on the ground.


/Perl Hallstrom
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
11-19-2009 16:56
if you get an attach event with id not equal to NULL_KEY the object is worn/attached.
CODE

attach(key id)
{
if (id != NULL_KEY) llOwnerSay("I am very attached");
}
_____________________
From Studio Dora
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-19-2009 17:23
From: Perl Hallstrom
I have an object with a script. Now I want to be able to stop people from wearing this object. It should only be possible to rez it on the ground.

Is it possible to set such limitations.

Yes. Try this or something like it....

CODE

key avAttached = NULL_KEY;
default
{
on_rez (integer start_param)
{
llResetScript();
}

attach (key attached)
{
llRequestPermissions(attached, PERMISSION_ATTACH);
avAttached = attached;
}

run_time_permissions (integer perm)
{
if(perm & PERMISSION_ATTACH)
{
if (avAttached != NULL_KEY)
{
llDetachFromAvatar(); // This will detach the object and send it back to the owner's inventory
}
}
}
}


From: someone
Or is it possibe to stop the script from running when someone is wearing it.

Yes again. but I can't do it without putting a second script in the object to start it running again later. Here's the script itself....

CODE

default
{
on_rez(integer start_param)
{
llSay(0, "Hello, Avatar!"); // This is just to verify that the script has been restarted if it was stopped before.
}

attach (key attached)
{
if (attached !=NULL_KEY)
{
llOwnerSay("Script deactivated");
llSetScriptState(llGetScriptName(),FALSE);
}
}

touch_start (integer num)
{
llSay(0, "This is a test. The script is running."); // This is your test to see if it is running or not.
}
}


Then you have to add this second "restarter" script to the same object....

CODE

default
{
on_rez(integer start_param)
{
llSetScriptState("Main Script",TRUE); // Be sure you type the actual name of the first script here
}

}


From: someone
Or can I maybe detect from the script that someone is wearing the object and that the object is not on the ground.

Nope. Can't do that one. Sorry. ;)

ETA: Ah.... Yes, I can. I took the wrong meaning from your question. As Dora said, all you have to do is ask ...

CODE

if (llGetAttached())
{
Say(0,"I'm attached!");
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
11-21-2009 13:48
While the attach() and on_rez() events should serve your needs for the most part, you should put a slowish timer in their too, as sometimes (fairly rarely) the attach() or on_rez() event will not trigger, most notably if the script was in a loop when it was attached. A timer of two or three seconds ought to be enough to get a decent response time in the event of changes, all it needs to do is compare value of llGetAttached() with what is expected, and behave accordingly, in case the event didn't fire.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)