Skip to content
arendjr edited this page Jan 28, 2013 · 13 revisions

Every object in the game is a so-called "game object". This includes characters, room, items, etc.. Here is an overview of all the game objects that are currently defined.

Object Type Derives from Description
Area GameObject An Area represents a larger area consisting of multiple (typically many) rooms.
Character StatsItem Characters are in-game characters. There are two major types of characters: players and non-playing characters (NPCs). The former are controlled by human players, the latter aren't.
Class GameObject A Class defines the class of a character. For example, "knight", "soldier", "mage".
Container Item Containers are items that may contain other items.
Event GameObject Event is a template object from which visual, sound, or other Game Events may be generated.
GameObject GameObject is the basic type that all game objects adhere to. It defines many useful properties and methods applicable to all other objects. GameObject is not an independent type, so you cannot instantiate objects of it.
Group GameObject A group is not a physical or tangible entity. Instead, it simply defines which characters form a group or party together.
Item GameObject Every item you may see or collect (weapons, potions, decorative items in rooms, etc..) is an Item. When talking about items we typically don't include characters even though technically, characters are also items. This make them share common properties and methods with items.
Player Character Players are player-controlled characters.
Portal GameObject Portals are connections between two rooms. A typical portal represents a two-way exit, but portals can also be created to be one-way, or act as a portal only to sounds and visuals.
Race GameObject A Race defines the race of a character. For example, "human", "animal", "elf".
Realm GameObject The Realm encompasses the entire game world. There is only one Realm, and it used for tracking things that affect the entire game world, no, realm.
Room GameObject Rooms are locations where characters can be. They may be actual physical rooms, but really any place where you can go to counts.
Shield StatsItem Shields are items that can be used for defensive purposes.
StatsItem Item Stats items are items which have associated character stats. They may have modifiers attached that modify the current effective stats. StatsItem is not an independent type, so you cannot instantiate objects of it.
Weapon StatsItem Weapons are items that can be used for attacking characters.

Useful Commands

Get an overview of all methods defined on a game object:

list-methods #<object-id>

Get an overview of all properties defined on a game object:

list-props #<object-id>

Extending Game Objects

You may wish to extend game objects by adding properties or methods to them, or you may wish to create a new type of GameObject altogether.

Adding Properties

To add a property to an object in JavaScript, there's really nothing special you need to do. Just assign the property, and it will be there. Typically, you will want to assign a default value in the oninit or onspawn trigger of an object. Use the onspawn trigger if the object is a character and you want the property to reset every time the character (re)spawns, otherwise use oninit. For example, if you want characters to remember their enemies (but forget them when they die), you can use an onspawn trigger like this:

function() {
    this.enemies = [];
}

There's one important limitation to these ad-hoc defined properties however: They are not saved to disk. So every time the server restarts, all the values in these properties will be lost. If you want the properties to persist, you should define them as part of the data property. Unfortunately, writing these data properties is a little bit more awkward:

function() {
    this.setGameObjectListData("enemies", []);

    // this.data.enemies is now defined, and will be stored to disk
    // any changes need to be written using this.setGameObjectListData() though...
}

Besides setGameObjectListData(), there's also setGameObjectData(), setStringData(), setIntData() and setBoolData().

Adding Methods

You can add methods to game objects by adding them to the JavaScript prototype for the specific object type. The prototypes are defined in the data/scripts/gameobjects/ directory. Take a look at the files in that directory for examples.

Creating New Game Object Types

Creating new types of game objects is currently only possible using C++. To do this, you will have to create a class that derives from GameObject. You may want to take the source of one of the existing types as template to create your own type. The Area class makes a good candidate as it's rather simple and easily stripped of its existing methods and properties.

Once you've created your own class, you have to add it to the GameObjectType enum defined in gameobject.h, and add the necessary isMyType() function and a new case for your type in createByObjectType() in gameobject.h and gameobject.cpp.

You will have to recompile PlainText after adding your own game object type.

Further Reading

Read how you can create triggers, how you can implement your own commands, or how you can customize game events.

You may want to take a look at the Frequently Asked Questions.