FILE
	basic_lock.c - basic lock functions

INHERITS
	/std/stationary.c	see stationary.doc for further details

SETUP FUNCTIONS
	set_lock
	set_opened
	set_unlocked

QUERY_FUNCTIONS
	query_opened
	query_unlocked
	query_code
	query_type

REMOTE FUNCTIONS
	remote_prevent_command
	remote_prevent_open
	remote_prevent_unlock
	remote_do_open
	remote_do_unlock

SPECIAL FUNCTION
	replace_vars

PROPERTIES
	open_mess
	unlock_mess
	lock_desc
	pick_level
	unlocker
	won't_close
	won't_lock
	not_lock_when_open
	(code)

DESCRIPTION
	This file contains basic functions and commands for
	opening/closing and locking/unlocking objects.

==========================================================================
NAME
	set_lock - set the lock code of the object

SYNTAX
	void set_lock(string code [, string type [, string desc]]);

DESCRIPTION
	This function sets the lock code for the object and also locks
	the object. It can then be unlocked with a key (or any object)
	that has a function query_code() or a property "code" that
	returns the same code. The code is a simple string that acts
	like a password to the object. The code string will be run
	through eval() everytime it is used.
	The optional argument 'type' sets the type of the lock, which
	is seen in the long description of the object. This usually
	corresponds to the type of key needed to unlock. The optional
	'desc' argument is a description of the lock.

	How to make a simple key? Look at /examples/doors1.c in function
	make_key(). A key is a /std/basic_thing with the alias "key" and
	the property "code".

EXAMPLES
	set_lock("xyzzy");
	set_lock("foobar","bronze","The lock is made of bronze.\n");

==========================================================================
NAME
	set_opened - open/close the object

SYNTAX
	void set_opened(int n)

DESCRIPTION
	If n is 0 it sets the status of the object to closed and
	if n is 1 opens the object.

==========================================================================
NAME
	set_unlocked - unlocks/lock the object

SYNTAX
	void set_unlocked(int n)

DESCRIPTION
	If n is 0 it sets the status of the object to locked and
	if n is 1 unlocks the object.

==========================================================================
NAME
	query_opened - returns open/closed status

SYNTAX
	int query_opened()

DESCRIPTION
	Returns the open/closed status of the object, 0 for closed and
	1 for opened.

==========================================================================
NAME
	query_unlocked - returns unlocked/locked status

SYNTAX
	int query_unlocked()

DESCRIPTION
	Returns the unlocked/locked status of the object, 0 for locked
	and 1 for unlocked.

==========================================================================
NAME
	query_code - returns lock code

SYNTAX
	string query_code()

DESCRIPTION
	Returns the code of the lock. The code string will be run
	through eval() first.

==========================================================================
NAME
	query_type - returns the type of the object

SYNTAX
	string query_type()

DESCRIPTION
	Returns the type of the object. It is normally the name set
	with set_name, but can give other results with inherited objects,
	like doors which gives the type "door" if no name is set. This
	is mainly an internal function.

==========================================================================
NAME
	remote_prevent_command - do extra checks before open/close/unlock/lock

SYNTAX
	int remote_prevent_command(object obj)

DESCRIPTION
	This function is called when someone tries to do anything with
	the object. If 1 is returned the command doesn't work.

EXAMPLE
	remote_prevent_command(object obj) {
	  if (present("guard",environment(obj)) {
	    write("Guard says: Hey! Don't touch that door.\n");
	    return 1;
          }
        }

==========================================================================
NAME
	remote_prevent_open - do extra checks before opening/closing

SYNTAX
	int remote_prevent_open(object obj)

DESCRIPTION
	This function is called when someone tries to open the object.
	If 1 is returned the object doesn't open.

EXAMPLE
	remote_prevent_open() {
	  if (this_player()->query_str()<15) {
	    write("You are too weak to open this heavy door.\n");
	    return 1;
          }
        }

==========================================================================
NAME
	remote_prevent_unlock - do extra checks before unlocking/locking

SYNTAX
	int remote_prevent_unlock(object obj, object key)

DESCRIPTION
	This function is called when someone tries to unlock the object.
	If 1 is returned the object doesn't unlock.

==========================================================================
NAME
	remote_do_open - do extra effects on open/close

SYNTAX
	int remote_do_open(object obj)

DESCRIPTION
	This function is called when someone opens or closes the object.
	Use query_verb() to check if it was "open" or "close" command.

==========================================================================
NAME
	remote_do_unlock - do extra effects on unlock/lock

SYNTAX
	int remote_do_unlock(object obj, object key)

DESCRIPTION
	This function is called when someone unlocks the object

EXAMPLE
	remote_do_unlock(object o, object key) {
	  write("The "+key->query_name()+" disappears.\n");
	  destruct(key);
	}

==========================================================================
NAME
	replace_vars - replace special variables in a string

SYNTAX
	varargs string replace_vars(mixed mess, string extra)

DESCRIPTION
	This internal function replaces all occurences of certain
	strings with data about the object. The strings are replaced
	like this:
	  $V  -  the verb that was used to do this action, query_verb()
	  $S  -  the opened status of the object, "open" or "closed"
	  $N  -  the name of the object, query_name()
	  $T  -  the type of the object, query_type()
	  $X  -  the "extra" string that is sent to this function

EXAMPLE
	The string "You $V the $S $N" can be replaced to "You open the
	closed small door".

==========================================================================
SPECIAL PROPERTIES

	open_mess   - The message that is written when the object
		      opens or closes.
	unlock_mess - The message that is written when the object
		      becomes unlocked or locked.
	lock_desc   - The description of the lock. It is normally
		      set by the set_lock() function.
	pick_level  - If another object returns a code that is an integer
		      it is compared to the pick_level, and if the code
		      is greater than the pick_level the object becomes
		      unlocked. An object without this property cannot
		      be picked.
	unlocker    - This property contains the name of the unlocker
		      object if it isn't a key.
	won't_close - If this property is set, the object won't close
		      automatically at reset.
	won't_lock  - If this property is set, the object won't lock
		      itself automatically at reset.
	not_lock_when_open - 
	              It is not possible to lock this object when it's open.
	(code)      - It gives another object a code for unlocking.
		      This is not a property in the basic_lock object. 

Help topics available:
basic.doc basic_lock.doc basic_thing.doc stationary.doc

[START|BACK ]




[ NannyMuds main page | FAQ | Contact us ]

You are guest number 55 since April 2020.
This file was last modified: June 2000.