Jump to content

Scripting A Key To Open Doors/Chests...


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

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

Recommended Posts

Don't know if this is the right place for this or not.... But I've been trying to find the scripts but no luck so far.... I did find a freebie on marketplace but it's no perms so can't see how it's done... I wan't to be able to script a treasure chest or any door that requires you to wear the key to open the door. I'm wondering how complicated it might be or if anyone has a script/s I could use/have for it already...

Link to comment
Share on other sites

Simply put, the key needs to listen on a specific channel. The door needs to send a request to the key, and the key needs to respond with a passphrase the door recognizes. Now that there's llRegionSayTo() it's actually fairly trivial.

Step by step:
1. Avi touches door/chest
2. Door/chest sends llRegionSayTo(llDetectedKey(0),...)
3. Worn key gets the message and replies directly to the prim with llRegionSayTo(kDoor,...)

If you need it more secure, you'll need a password/passkey scheme.

Link to comment
Share on other sites

There are many ways to do that. Possibly the easiest is to make the door and the key communicate on the same hidden channel.  If the door only unlocks on a command on that channel, you have to have the key to do it. 

If you actually want to require the key holder to wear the key, you can do something like this....

attach( key id){    if (id != NULL_KEY)    {        llSensorRepeat("Treasure_chest","",ACTIVE|PASSIVE,10.0,PI,5.0);    }}sensor (integer num){    llRegionSayTo(llDetectedKey(0),CHAN,"Open Sesame!"); //Where CHAN is your secret channel}

 ETA:  Obviously, have the door listen for "Open Sesame" on channel CHAN.  I'd put a timer in the door to lock it again in, say, 5.5 seconds.  The key will continue to send an unlock signal every 5.0 seconds while it is being worn within range but the door will lock again once the keyholder either detaches the key or walks out of sensor range.

Link to comment
Share on other sites

because it's a neat application and simple, you're in luck... here's how I'd do it...

/*( Simple Lock )*/string gStrLockName = "Uber-Secret Name";default{    state_entry(){        llListen( -1, "Key", "", gStrLockName );    }        touch_end( integer vIntTch ){        llWhisper( 0, llDetectedName( 0 ) + " tries to open the lock..." );        string vStrTemp = llGetObjectName();        llSetObjectName( "Lock" );        llRegionSayTo( llDetectedKey( 0 ), -1, "Keys Please" );        llSetObjectName( "key" );        llSetTimerEvent( 2.0 );    }        listen( integer vIntChn, string vStrNom, key vKeySrc, string vStrMsg ){        llSetTimerEvent( 0.0 );        llWhisper( 0, llKey2Name( llGetOwnerKey( vKeySrc ) ) + " has the right key!" );        //-- do whatever you need to do to open/unlock the item here    }        timer(){        llWhisper( 0, "... but doesn't seem to have the right key (must be worn)" );        llSetTimerEvent( 0.0 );    }}

 and

/*( Simple Key )*/string gStrLockName = "Uber-Secret Name";default{    state_entry(){        llListen( -1, "Lock", "", "Keys Please" );    }        listen( integer vIntChn, string vStrNom, key vKeySrc, string vStrMsg ){        string vStrTmp = llGetObjectName();        llSetObjectName( "Key" );        llRegionSayTo( vKeySrc, -1, gStrLockName );        llSetObjectName( vStrTmp );    }}

 I encluded name swapping so that the keys and locks can be named anything and still use good filters... llRegionSayTo will only be heard by the targeted prim, or the attachments of a targeted avatar (when not using channel zero, otherwise the avatar only hears it)

ETA:
currently will break if the avatar is sitting on something, but that little bug should be gone after tuesdays restart (already gone on at least on of the release channels.

ETA2:
fixed typos

Link to comment
Share on other sites

Void must have been tired - just some typos - it should work now

/*( Simple Lock )*/string gStrLockName = "Uber-Secret Name";default{    state_entry(){        llListen( -1, "Key", "", gStrLockName );    }touch_end( integer vIntTch ){        llWhisper( 0, llDetectedName( 0 ) + " tries to open the lock..." );        string vStrTemp = llGetObjectName();        llSetObjectName( "Lock" );        llRegionSayTo( llDetectedKey( 0 ), -1, "Keys Please" );        llSetObjectName( "key" );        llSetTimerEvent( 2.0 );    }    listen( integer vIntChn, string vStrNom, key vKeySrc, string vStrMsg ){        llSetTimerEvent( 0.0 );        llWhisper(0, llKey2Name( llGetOwnerKey( vKeySrc )) + " has the right key!" );        //-- do whatever you need to do to open/unlock the item here    }        timer(){        llWhisper( 0, "... but doesn't seem to have the right key (must be worn)" );        llSetTimerEvent( 0.0 );    }

 Rotation or size or position don't really matter here - apart from the limitations that communication functions used define.

Link to comment
Share on other sites

fixed typos above (this is what I get for posting code on the fly, sorry)

any actions you want the lock item to take would go where the comment "//-- do whatever you need to do to open/unlock the item here" is in the lock script.

unfortunately whatever action is going to specific to the object that it's in, so I don't have a good way to guess.

I can say that llGiveInventory is the simple to use, and you should have no trouble figureing out how to insert just there =)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4815 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...