Entity Functions for Mocha


Changing to a more specific type

boolean ent.is_object;
Returns true if the entity ent is an object, false otherwise.

boolean ent.is_person;
Returns true if the entity ent is a person, false otherwise.

boolean ent.is_room;
Returns true if the entity ent is a room, false otherwise.

person ent.get_person;
Returns ent if the entity ent is an object, none otherwise.

object ent.get_object;
Returns ent if the entity ent is a person, none otherwise.

room ent.get_room;
Returns ent if the entity ent is a room, none otherwise.


Finding attributes

integer ent.vnum;
Returns the virtual number associated with the entity ent. Returns nothing if ent refers to a player.

string ent.name;
Returns the name of the entity ent.

string ent.keywords;
Returns the keywords for the entity ent.

boolean is_keyword (entity ent, string word);
Returns true if the word word is one of the keywords of the entity ent, and returns false otherwise.

string ent.appearance;
Returns the appearance of the entity ent in a room.

string ent.description;
Returns the description of the entity ent.


Determining basic location

entity ent.where;
Returns the entity in which or on which ent sits, or none if the entity is a room.

room ent.in_room;
Returns the room holding the entity ent, regardless of how deeply nested within other entities ent might be, or none if ent is a room.

person ent.on_person;
Returns the person holding or bearing the entity ent, regardless of how deeply nested within other entities ent might be, or none if ent is not held by a person.


Finding location details

integer relation (entity ent1, entity ent2);
Returns one of the following values indicating the relationship between ent1 and ent2:
unrelated
inside_of
on_top_of
beneath
contains

entity ent.inside_of;
Returns the entity directly containing the entity ent, which may in turn be contained by other entities, or none if no entity contains ent.

integer ent.stack_height;
Returns the number of entities beneath the entity ent within its container.

entity ent.bottom_of_stack;
Returns the entity at the bottom of the stack of entities on which the entity ent rests within its container. This may, of course, be ent itself.

integer depth (entity ent1, entity ent2);
Returns the number of container relationships between ent1 and ent2. The number is positive if ent2 contains ent1, negative if ent1 contains ent2, or 0 otherwise.

integer stack_height (entity ent1, entity ent2);
Returns the number of entities in the stack of entities at the outermost of ent1 and ent2's layers. As an example, for a sword sitting in a bag on a table, the function returns the following:
stack_height (sword, bag) -> 0
stack_height (sword, table) -> 1
stack_height (bag, table) -> 1
stack_height (table, sword) -> -1

Creating, moving, and destroying entities

When entities are created or moved, their location is subject to certain constraints. Persons must be placed inside of a room, on top of an object, or on top of another person (i.e., riding another person). Objects must be placed inside of an entity (this is inventory for persons) or on top of another object. To move an object into a person's equipment, use the equip function.
person create_mobile (integer vnum, entity relative, integer relation);
Creates a mobile of the specified virtual number and places it the specified relation to the entity relative (inside_of or on_top_of). Returns the new mobile or none if the mobile could not be created.

object create_object (integer vnum, entity relative, integer relation);
Creates an object of the specified virtual number and places it the specified relation to the entity relative (inside_of or on_top_of). Returns the new object or none if the object could not be created.

person insert_mobile (integer vnum, entity sibling);
Creates a mobile of the specified virtual number and places it next to the entity sibling. Returns the new mobile or none if the mobile could not be created.

object insert_object (integer vnum, entity sibling);
Creates an object of the specified virtual number and places it next to the entity sibling. Returns the new object or none if the object could not be created.

person pc.duplicate;
Duplicates a mobile pc in place and returns the new mobile (or none if the mobile could not be created).

object obj.duplicate;
Duplicates an object pc in place and returns the new object (or none if the object could not be created).

void move (entity ent, entity relative, integer relation);
Moves an entity into a new location. If ent is a coin object, the object can be changed in the process of moving: if the destination already contains a coin object of the same coin type, the latter object is merged into the object being moved.

void join (entity ent, entity sibling);
Moves an entity into the location occupied by the entity sibling. If ent is a coin object, the object can be changed in the process of moving: if the destination already contains a coin object of the same coin type, the latter object is merged into the object being moved.

void ent.delete (entity ent);
Destroys the entity ent (a person or an object), leaving any contents in the location previously occupied by ent.

void ent.destroy;
Destroys the entity ent (a person or an object) and all contents, stacked items, inventory, or equipment.

void ent.empty;
Destroys the contents, stacked items, inventory, and equipment of the entity ent.

void pc.rent;
Removes a player pc from the game, storing his equipment safely in rent. Has no effect on mobiles.


Searching for other entities

exit path_exit (entity from, entity to, integer flags, integer disance);
Returns the first exit on the path from the room of from to the room of to, provided that such a path exists and is reasonably short. The function typically searches 150 rooms in a breadth-first fashion. The flags must be 0 or taken from the following list (use bitwise or, |, to pass multiple flags):
nearby_skip_closed -- ignore closed exits
nearby_skip_climb -- ignore exits with a climb flag
nearby_skip_hidden -- ignore hidden exits
nearby_skip_locked -- ignore locked exits
nearby_skip_no_mob -- ignore exits that disallow mob movement
nearby_skip_no_hunt -- ignore rooms that disallow hunt through
nearby_skip_no_new_zone -- ignore exits that don't lead to a new zone
nearby_skip_new_zone -- ignore exits that lead directly to a new zone
Distances are based on movement of a naked mortal.
distance_near -- movement cost of 90
distance_normal -- movement cost of 300
distance_far -- movement cost of 1125
distance_maximum -- movement cost of 15000
path_exit is typically combined with use_exit.


Return to Mocha's Main Page