OOC:Locks

One of the more useful but, unfortunately not at all intuitive, skills for a MUSH user is making a good use of the wide variety and forms of locks. For sake of organization, I'm dividing this into two broad categories: Permanent locks (locks you generally set once then always leave on) and temporary locks (locks you can turn on and off based on need). Thanks are owed to Amy, Phil-chan, Saberwind, and Sparta, all of whom helped me with learning some of the code tricks here for more advanced locks.

Contents

Permanent Locks

Player Locks

These are locks that you set on yourself.

Basic @lock

This lock controls who can pick your character object up and who can use the 'lead' command to force you to follow them. Let's say you wanted to let your girlfriend, Kitty, be able to pick you up and take you home when you were offline. You would type:

@lock me==me|=*Kitty

In this, the '=' sign means 'this character object ONLY, not things they own', and the '*' lets it know to look for a character object by that name that might not be in the same room as you. To add more people, just repeat the '|=*name' portion for each person.

Zone lock

Setting someone on your zone lock is the most basic way to 'share' quota. However, it is a somewhat risky one; it means that the person on your zone lock can control and affect any item that you own! There are two steps to this. You need to do

@set me=SHARED

And then type

@lock/zone me==me|=*Kitty

Keep in mind, that both of you should go through this process for one another for this to work fully.

Zone Locks

These locks are set on an object that is used to act as something of an aggregator and control locus for shared quota. Most commonly, they're used to create a building project shared by more than one person. Rather than go into the full process of how to do so, we'll just touch on the two major locks used to set up one of these objects, the @lock/zone and the @lock/chzone. The @lock/zone is used to list the people who can control and affect objects on the zone. Let's say your dbref object is #123. You would type:

@lock/zone #123==me|=*Kitty

To control who can add objects to a zone, you would use the @lock/chzone. Anyone who is on this lock can use the @chzone command to put new objects on the zone for others to control. To set it, you'd type:

@lock/chzone #123==me|=*Kitty

Permanent Door Locks

Basic

This type of lock will just set a door so only you and the other listed people can go through it. Let's assume the relevant exit has the dbref #111. (This type of lock is set on the exit into a room.)

@lock #111==me|=*Kitty

Key Object

Let's say that instead of locking the door to a particular list of people, you want to make it so that only a person holding a particular object you own can get in. First, you @create an object, say, 'Betty's Key'. Note its dbref; in this case, let us say it's #222. In this case, the lock would be set to:

@lock #111==me|=+#222

This would mean that anyone who had object #222 in their inventory would be able to enter the door.

List Reference

This is not the simplest way of doing things, by far, but it IS very flexible and useful. To be done as presented here, you MUST have a zone object, and the exit MUST be on it. Here, we'll assume that our zone is #123 again, the exit is #111. (Thanks to Amy and Sparta for this bit of code!)

@set #123=!NO_COMMAND
@set #123=VISUAL

&CMD`ADDGUEST #123=$addguest *:&guestlist #123=setunion(get(#123/guestlist),num(*%0));@pemit %#=[name(*%0)]([num(*%0)]) has been added to the Guest List.
&CMD_DELGUEST #123=$delguest *:th [setq(0,switch(pmatch(%0),#-*,num(%0),#$))][attrib_set(%!/guestlist,setdiff(v(guestlist),%q0))][pemit(%@,[name(%q0)]([num(%q0)]) has been removed from the Guest List.)]
&CMD_LISTGUEST #123=$listguest:@pemit %#=ansi(yhX,Your Guests:)%r[itemize(iter(v(guestlist),name(##)(##)))]
&GUEST #123=t(member(v(GuestList),%#))
&GUESTLIST #123=

@lock #123=GUEST/1

This will give you three commands: addguest NAME to add someone to the list, delguest NAME to remove someone from the list, listguest to show you who's on the guest list. Once all of that is done, you can then set your exit lock to:

@lock #111=@#123/basic

After this, anyone who is on the guest list can pass the lock. You can use the command to easily add or remove names, or check who is on the list.

Temporary Locks

Simple Interior Lock

With this lock, anyone in the room can lock it. The room can be unlocked manually, or will unlock on its own as soon as all the people in the room leave or go offline. When anyone enters the room, they get a message about how to work the locks. Room is #100, exit in is #111, exit out is #333. (Thanks owed to Phil-chan and Lyra for bits of this code.)

@set #100=!no_command
@adisconnect #100=@trigger me/Tr`Check
@aleave #100=@trigger me/Tr`Check
&CMD`LOCK-DOOR #100=$lock door:@break v(DATA`LOCK)={@pemit %#=You find the door already locked.};&DATA`LOCK me=1;@lock #111=#0;@lock #333=#0;@emit [ansi(g,%n)] flips the lock on the door with an audible click, locking the door.;@remit #100=The door locks with an audible click.
&CMD`UNLOCK-DOOR #100=$unlock door:@assert v(DATA`LOCK)={@pemit %#=You find the door already unlocked.};&DATA`LOCK me=0;@lock #111;@lock #333;@emit [ansi(g,%n)] unlocks the door with an audible click;@remit #100=The door unlocks with an audible click.
&DATA`LOCK #100=0
&FN`ALIVE #100=and(hastype(%0, Player), gte(conn(%0), 0))
&TR`CHECK #100=@switch words(filter(Fn`Alive, lcon(me)))=0, {@trigger me/CMD`UNLOCK-DOOR; @dolist lcon(here)=@tel ##=home}

@success #100=%t[ansi(c,To lock the door, type)] [ansi(hg,lock door)][ansi(c,. To unlock the door, type)] [ansi(hg,unlock door)][ansi(c,.)]

Saberwind's Method

Rather than try and talk this one out, I'll just link this to the original forum topic: http://www.shoujoai.com/forum/topic_show.pl?tid=1295

Advanced Saberwind's Method

I took this one and ran with it in my house, combining it with the guest list idea above to set up tiered locks - a general one that anyone on a friends list can open, and a shorter one that can bar the door so only they can unlock it. You can put more than one of these on a room (a hallway, for example) so long as each uses a different command key word and variable. (e.g. unlock 1 and VA, unlock 2 and VB, etc.) The example is taken from my main bedroom, thus the reason for the command name and emit choices. This is a complicatedish method and uses code set on both rooms - We'll say here the zone is #123, the hallway is #100, the exit in is #111, the bedroom is #300, and the exit out is #333. As with the one above, setting this up and troubleshooting it does take some code skill, so think carefully about your willingness to learn and challenge yourself before using it. Rooms and exits must be on the zone.

&BOLTIT #100=$bolt main:@switch member(get(#100/boltmain),%#)=1,{@switch get(#100/va)=unlocked,{@va #100=bolted;@lock #111=#0;@lock #333=#0;@remit #100=There is a soft thunking sound audible from the door in the eastern wall as the deadbolt settles into place.;@remit #300=There is a soft thunk sound as the deadbolt slides into place.},bolted,{@pemit %#=The main bedroom is already bolted.},locked,{@va #100=bolted;@lock #111=#0;@lock #333=#0;@remit #100=There is a soft thunking sound audible from the door in the eastern wall as the deadbolt settles into place.;@remit #300=There is a soft thunk sound as the deadbolt slides into place.}},{@switch u(#100/ISAUTH)=1,@pemit %#=You do not have permission to bolt the main bedroom door.},@pemit %#=You do not have permission to do that.
&BOLTMAIN #100=#121

(This is my dbref - You should have yours in this list. :p)

&ISAUTH #100=t(member(get(#123/Guestlist),%#))
&LOCKIT #100=$lock main:@switch u(#100/ISAUTH)=1,{@switch get(#100/va)=unlocked,{@va #100=locked;@lock #111=#0;@lock #333=#0;@remit #100=There is a soft clicking sound audible from the door in the eastern wall as a lock setless into place.;@remit #300=There is a soft clicking sound as the doors lock slides into place.},locked,{@pemit %#=The main bedroom is already locked.},bolted,{@pemit %#=The main bedroom door is already bolted\, there is no need to lock it as well.}},@pemit %#=You do not have permission to do that.
&UNBOLTIT #100=$unbolt main:@switch member(get(#100/boltmain),%#)=1,{@switch get(#100/va)=bolted,{@va #100=unlocked;@lock #111;@lock #333;@remit #100=With a soft thunking sound in the east the deadbolt is pulled free\, unbarring the door to the main bedroom.;@remit #300=There is a soft thunk sound as the deadbolt is pulled back into the wall and frees the door.},unlocked,{@pemit %#=The main bedroom is already unbolted and unlocked.},locked,{@va #100=unlocked;@lock #111;@lock #333;@remit #100=A soft click can be heard at the eastern end of the hall as the lock to the main bedroom is opened.;@remit #300=A soft click can be heard as the door's lock is opened.}},{@switch u(#100/ISAUTH)=1,@pemit %#=You do not have permission to open the door when it's bolted.},@pemit %#=You do not have permission to do that.
&UNLOCKIT #100=$unlock main:@switch u(#100/ISAUTH)=1,{@switch get(#100/va)=unlocked,{@pemit %#=The door is already unlocked.},bolted,{@remit #100=Although the lock clicks softly open the deadbolt remains firmly bolted in place\, barring access to the room.;@remit #300=Although the lock clicks softly open, the deadbolt remains firmly bolted in place\, barring access to the hallway.},locked,{@va #100=unlocked;@lock #111;@lock #333;@remit #100=A soft click can be heard at the eastern end of the hall as the lock to the main bedroom is opened.;@remit #300=A soft click can be heard as the door's lock is opened.}}, @pemit %#=You do not have permission to do that.
@VA #100=unlocked
&BOLTIT #300=$bolt main:@switch member(get(#100/boltmain),%#)=1,{@switch get(#100/va)=unlocked,{@va #100=bolted;@lock #111=#0;@lock #333=#0;@remit #100=There is a soft thinking sound audible from the door in the eastern wall as the deadbolt settles into place.;@remit #300=There is a soft thunk sound as the deadbolt slides into place.},@pemit %#=The main bedroom is already bolted.},locked,{@va #100=bolted;@lock #111=#0;@lock #333=#0;@remit #100=There is a soft thunking sound audible from the door in the eastern wall as the deadbolt settles into place.;@remit #300=There is a soft thunk sound as the deadbolt slides into place.},@pemit %#=The main bedroom is already bolted.},bolted,@pemit %#=The door is already bolted shut.},@pemit %#=You do not have permission to do that.
&BOLTMAIN #300=#121 
&LOCKIT #300=$lock main:@switch u(#100/ISAUTH)=1,{@switch get(#100/va)=unlocked,{@va #100=locked;@lock #111=#0;@lock #333=#0;@remit #100=There is a soft clicking sound audible from the door in the eastern wall as a lock settless into place.;@remit #300=There is a soft clicking sound as the doors lock slides into place.},locked,{@pemit %#=The main bedroom is already locked.},bolted,{@pemit %#=The main bedroom's door is already bolted closed\, a further lock isn't needed.}}, @pemit %#=You do not have permission to do that.
&UNBOLTIT #300=$unbolt main:@switch member(get(#100/boltmain),%#)=1,{@switch get(#100/va)=bolted,{@va #100=unlocked;@lock #111;@lock #333;@remit #100=With a soft thunking sound in the east the deadbolt is pulled free\, unbarring the door to the main bedroom.;@remit #300=There is a soft thunk sound as the deadbolt is pulled back into the wall and frees the door.},unlocked,@pemit %#=The main bedroom is already unbolted and unlocked.},locked,{@va #100=unlocked;@lock #111;@lock #333;@remit #100=With a soft thunking sound in the east the deadbolt is pulled free\, unbarring the door to the main bedroom.;@remit #300=There is a soft thunk sound as the deadbolt is pulled back into the wall and frees the door.}},{@switch u(#100/ISAUTH)=1,@pemit %#=You do not have permission to open the door when it's bolted.},@pemit %#=You do not have permission to do that.
&UNLOCKIT #300=$unlock main:@switch u(#100/ISAUTH)=1,{@switch get(#100/va)=unlocked,@pemit %#=The door is already unlocked.,bolted,{@remit #100=Although the lock clicks softly open the deadbolt remains firmly bolted in place\, barring access to the room.;@remit #300=Although the lock clicks softly open, the deadbolt remains firmly bolted in place\, barring access to the hallway.},{@va #100=unlocked;@lock #333;@lock #111;@remit #100=A soft click can be heard at the eastern end of the hall as the lock to the main bedroom is opened.;@remit #300=A soft click can be heard as the door's lock is opened.}}, @pemit %#=You do not have permission to do that.
@VA #300=unlocked

Additional Lock Related Code

Knock Command

This command will allow you to knock on a door to alert those within. Here #100 is the room the person knocking is standing in while #200 is the room beyond the locked doorway.

&CMD`KNOCK #100=$KNOCK: @pemit %#=You knock on the door.[oemit(%#,[ansi(g,%n)] knocks on the door.)][remit(#200,> [ansi(g,%n)] knocks on the door.)]

Intercom Command

This command will allow you to talk to the occupants of another room. Here #100 is the room you want to talk from while #200 is the room you are talking to. The command will need to be set for either side of the door, swapping the dbrefs as appropriate.

&CMD`INTERCOM #100=$INTERCOM *: @emit To the intercom: [setr(0,[ansi(g,%n)][switch(%0,;*,after(%0,;),:*,%b[after(%0,:)],%bsays%, "%0")])][remit(#200,Intercom> %q0)]
Retrieved from "https://www.yuriba.com/mwiki/index.php?title=OOC:Locks&oldid=9663"