Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Permission Rights to Use a Script in an Object

Pablicious Pessoa
Registered User
Join date: 27 Jun 2007
Posts: 64
08-06-2007 07:31
Hello all,

I have created a script that allows anyone to resize a prim using a dialog menu. However, I would like only the owner of the object to be able to rez the dialog menu and a non-owner will receive an IM stating that they are unable to access menu.

I am extremely new to LSL and programming. I have been dabbling around mostly modifying scripts. The script I made was basically modified from another script that would change a prim's position. So, I'm not totally clueless and I know this has something to do with llGetOwner and probably an IF statement. In my mind, I am thinking:

llGetOwner

If llGetOwner is owner, open dialog box
If llGetOwner is not owner, send llInstantMessage or llSay, "You do not have permission."

and then llResetScript so that it checks the owner when the object is touched again....

Is that right? Can somebody help? I'll give you free original art (with this working script), t-shirts, and even a THiNC art book in SL if you can help me! :D :D
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
08-06-2007 07:36
Yeah GetOwner is the way to go.

You probably don't need to call resetscript every time, though it probably won't hurt.

But you might want to put one in:

on_rez(integer param)
{
llResetScript();
}

So it will recognized a new owner of the object.
Kidd Krasner
Registered User
Join date: 1 Jan 2007
Posts: 1,938
08-06-2007 09:07
From: Pablicious Pessoa

llGetOwner

If llGetOwner is owner, open dialog box

llGetOwner is always the owner, that's the definition. What you need is llDetectedKey, to see who actually touched the object.
From: someone

If llGetOwner is not owner, send llInstantMessage or llSay, "You do not have permission."

Use llSay. It's annoying to get instant messages from objects unexpectedly like this.

From: someone

and then llResetScript so that it checks the owner when the object is touched again....

The llResetScript is only needed for this if you cache the owner (i.e. get it once and save it in a variable). Strictly speaking, it's not even necessary for that; you could just always reset the owner variable in the on_rez event.

The simplest way to do what you want is:

CODE

touch_start(integer num_detected) {
if (llDetectedKey(0) == llGetOwner()) {
llDialog ....
} else {
llSay(0, ...
}
}

This doesn't require a reset, and is probably best if the script a) doesn't get used a lot; and b) doesn't get any more complicated than this.

I don't know what the performance penalty is for llGetOwner, so I don't know whether it's worth saving the owner if this does get called a lot. But it's not too much harder:

CODE

key owner;
...
on_rez(integer start_param) {
owner = llGetOwner();
}

touch_start(integer num_detected) {
if (llDetectedKey(0) == owner) {
...
Pablicious Pessoa
Registered User
Join date: 27 Jun 2007
Posts: 64
08-06-2007 10:31
Thank you kindly, Kidd and RJ!!! I was finally able to get what I needed done thanks to your help. I am a gallery owner and just wanted a simple script that allowed for owner resizing only. It works perfectly! :)

Here is the script. Like I said, I patched it together so if there's anything outright wrong or could be changed/removed, please feel free to enlighten me! Besides, I didn't see a script like this in the script library and I think it might be a good addition. I made some comments while others were added from the pieces I used to put this together.

CODE

integer dialog_channel= 405; // set a dialog channel - use a different channel per script if resizing multiple objects separately.
list menu = [ "Width -10", "Height +10", "Height -10", "Width +10" ];
vector startScale;


default
{
state_entry()
{
// arrange to listen for dialog answers (from multiple users)
llListen( dialog_channel, "", NULL_KEY, "");

startScale = llGetScale();

}

touch_start(integer num_detected)
{
// detect for owner rights and edit greetings
{if (llDetectedKey(0) == llGetOwner()) {
llDialog( llDetectedKey( 0 ), "Use these buttons to resize your art. If you are having a problem, please IM Pablicious Pessoa!", menu,
dialog_channel );
}
else {
llSay(0, "You are not the owner of this beautiful piece of art.");
}
}
}
listen(integer channel, string name, key id, string choice )
{
vector position = llGetScale();

// if a valid choice was made, implement that choice if possible.
// (llListFindList returns -1 if choice is not in the menu list.)
if ( llListFindList( menu, [ choice ]) != -1 )
{
if ( choice == "Width +10" )
llSetScale( llGetScale() + < 0, 1.0, 0 > );
if ( choice == "Width -10" )
llSetScale( llGetScale() - < 0, 1.0, 0 > );
if ( choice == "Height +10" )
llSetScale( llGetScale() + < 0, 0, 1.0 > );
if ( choice == "Height -10" )
llSetScale( llGetScale() - < 0, 0, 1.0 > );


}
else
{
llSay( 0, "Invalid choice: " + choice );
}
}
}