Jump to content

Linking / unlinking primitives while asking for permission only once


Mircea Lobo
 Share

You are about to reply to a thread that has been inactive for 4366 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I've scripted for years in Second Life, yet I find myself confused by something new I wanna do. I got what I wanted working I think, but I still wanted to ask in order to know if what I'm doing is the right way.

I want to script an object that spawns another object from inventory then links it to itself. I got this working with llCreateLink, using the excellent example available on its LSL page. However, this function must ask for permission in order to activate. For what I'm doing, this is an interactive process (eg: happens whenever you click something) so I don't want the person using it to be asked for permission whenever he clicks a button to spawn + link (this would be annoying and unusable). I don't mind if the owner of the object is asked for permission only once (when the object is rezzed), but after that everything happens automatically.

Like I said I got this working. What I did was changing that example script into this:

// Create a new object and link it as a child prim.
string ObjectName = "Primitive";
// NOTE: must be a name of an object in this object's inventory.

integer works;
default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);
    }
    touch_start(integer count)
    {
        // When the object is touched, make sure we can do this before trying.
        if (works)
            llRezObject(ObjectName, llGetPos() + <0,0,0.5>, ZERO_VECTOR, llGetRot(), 0);
        else
            llOwnerSay("Sorry, we can't link.");
    }
    run_time_permissions(integer perm)
    {
        // Only bother rezzing the object if will be able to link it.
        if (perm & PERMISSION_CHANGE_LINKS)
            works = TRUE;
        else
            works = FALSE;
    }
    object_rez(key id)
    {
        // NOTE: under some conditions, this could fail to work.
        // This is the parent object.  Create a link to the newly-created child.
        llCreateLink(id, TRUE);
    }
}

My curiosity is if this is the right way to have the object only requesting permission once after it's spawned, then allowing spawning / unspawning objects from itself automatically. Does it work for everyone also, or only for the owner?

Link to comment
Share on other sites

In the example you quote is a line in the caveats that explains all

 

 If PERMISSION_CHANGE_LINKS is granted by anyone other than the owner, then when the function is called an error will be shouted on DEBUG_CHANNEL.

Only the owner can grant that perm, I make things that delink, the only way for them to use it is for the owner to grant perms first, would be nice if others could but that is not to be.

 

Link to comment
Share on other sites

Your script should work just fine in respect to asking link permission only once. There is however another thing there. When the object is rezzed, it will ask for permission and when owner grant same it will set works = TRUE. So what happens then if an agent other than the owner touches?  As works = TRUE, an auxiliary object will be rezzed and this will raise object_rez event where a link will be attempted. But the touching agent doesn't have permission to link, they are not the owner. So the link will fail with an error on debug channel.

To avoid this, you may want to modify your touch event as follows:

    touch_start(integer count)
    {

        if(llDetectedKey(0) != llGetOwner()) return;
        // When the object is touched, make sure we can do this before trying.
        if (works)
            llRezObject(ObjectName, llGetPos() + <0,0,0.5>, ZERO_VECTOR, llGetRot(), 0);
        else
            llOwnerSay("Sorry, we can't link.");
    }
 

Link to comment
Share on other sites

Thanks for pointing that out. I mostly just need the owner to be able to use it, so I guess that's ok. I didn't know each avatar needs permission, but thought the object needs it once globally. Maybe I can find a workaround for that later.

Link to comment
Share on other sites


Mircea Lobo wrote:

 I didn't know each avatar needs permission, but thought the object needs it once globally.

That´s right. Ela got it wrong.

I tried your script with an alt and it works fine.

Only problem was after I gave the object to my alt, and rezzed it, the permissions were not reset and thus the linking failed. 

Link to comment
Share on other sites

Yes, only the owner can give permission or needs to give permission.  If you only want the owner to be able to USE the thing, check who's trying to do it in the touch_*() event-handler.

For things like this it is sometimes a lot easier to keep things straight if you use states.

 

string ObjectName = "Primitive";default{	run_time_permissions(integer Perms){		if(PERMISSION_CHANGE_LINKS & Perms){			state Permitted;		}	}	state_entry(){		llOwnerSay("Need permission to relink prims");		llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);	}	touch_end(integer HowMany){		llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);	}}state Permitted{	changed(integer Change){		if(Change & CHANGED_OWNER){			llResetScript();		}	}	object_rez(key ID){		llCreateLink(ID, TRUE);	}	touch_end(integer HowMany){		llRezObject(ObjectName, llGetPos() + <0,0,0.5>, ZERO_VECTOR, llGetRot(), 0);	}}

 [Edited: old permission was not automatically revoked]

Another, more compact, way is:

 

string ObjectName = "Primitive";RezIt(){	llRezObject(ObjectName, llGetPos() + <0,0,0.5>, ZERO_VECTOR, llGetRot(), 0);}default{	object_rez(key ID){		llCreateLink(ID, TRUE);	}	run_time_permissions(integer Perms){		if(PERMISSION_CHANGE_LINKS & Perms){			RezIt();		}	}	touch_end(integer HowMany){		if((llGetPermissions() & PERMISSION_CHANGE_LINKS) && (llGetPermissionsKey() == llGetOwner()){			RezIt();		}else{			llOwnerSay("Need permission to relink prims");			llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);		}	}}

 [second edit: same thing in this script - permissions check also checks owner]

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4366 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...