Lock Types and Key Expressions
Lock Types and Key Expressions
Locks are boolean expressions that control who can interact with an object and how. Every lock evaluates to either true (pass) or false (fail) for a given actor. Locks are one of the most powerful building tools in MUSH.
Setting Locks
@lock thing = me -- Only I can pick it up
@lock/enter room = flag^wizard -- Only wizards can enter
@lock/use button = +key_card -- Must carry key_card
The general form is @lock[/type] object = key-expression. Without a type, the default lock is set.
Lock Types
Each lock type controls a different kind of interaction:
| Lock Type | Controls |
|---|---|
| default | Taking objects, going through exits, using the use command |
| /enter | Entering an object or room (via teleport or enter command) |
| /leave | Leaving an object |
| /use | Using an object (the use command) |
| /drop | Dropping an object |
| /give | Giving an object to someone |
| /receive | Receiving an object from someone |
| /page | Paging the object’s owner |
| /teleport | Teleporting to a location |
| Sending @mail to the object’s owner | |
| /speech | Speaking in a room (controls who can talk) |
| /command | Using $-commands on an object |
| /parent | Setting this object as a parent |
| /link | Linking an exit to this location |
| /control | Controlling this object (beyond normal ownership) |
| /zone | Zone-based control |
| /destroy | Destroying this object |
| /chown | Changing ownership of this object |
Key Expression Grammar
Lock keys are boolean expressions built from these primitives:
Object Reference
A bare object name or dbref. Passes if the actor is that object.
@lock door = #1234 -- Only object #1234 passes
@lock door = Bob -- Only the player named Bob passes
Identity Test (=)
Passes if the actor is exactly the specified object. Similar to a bare reference but syntactically explicit.
@lock door = =me
Carry Test (+)
Passes if the actor is carrying the specified object.
@lock door = +gold_key -- Must have gold_key in inventory
Owner Test ($)
Passes if the actor is owned by the same player as the specified object.
@lock zone_obj = $admin_char -- Must be owned by admin_char's owner
Indirect Lock (@)
Evaluates another object’s lock instead.
@lock exit = @master_lock -- Use master_lock's default lock
Attribute Lock (:)
Tests an attribute value on the actor.
@lock door = faction:rebel -- Actor's FACTION attr must equal "rebel"
@lock door = class:warrior|mage -- Must be "warrior" or "mage"
Evaluation Lock (/)
Like an attribute lock, but the value is evaluated as softcode. The result must match.
@lock door = level/[gte(%0,10)] -- Actor's LEVEL attr must be >= 10
Here, %0 is replaced with the actor’s value of the attribute being tested.
Boolean Constants
@lock obj = #true -- Always passes
@lock obj = #false -- Always fails
Combining Keys
Keys can be combined with boolean operators:
| Operator | Meaning |
|---|---|
& | AND—both sides must pass |
| | OR—either side must pass |
! | NOT—inverts the result |
Parentheses group expressions:
@lock vault = (+master_key & faction:guild) | =Treasurer
This lock passes if the actor carries master_key AND has faction “guild”, OR if the actor is the Treasurer.
Lock Nesting
Locks can reference other locks via indirection (@), and lock evaluation can trigger further lock checks. To prevent infinite loops, the server enforces a lock nesting limit. If exceeded, the lock fails.
Unlocking
@unlock[/type] object removes a lock, which means the lock is always considered passed (open).