Entities
Your game is made up of entities each of which have an associated UUID, position, type and data.
The Entity Object
This section details the fields and methods available on each entity object.
Fields
Methods
Types & Behaviour Scripting
Entities are divided into types, each of which have their own behaviour. This behaviour is determined by a script in the entity
folder; to create a new entity type, simply create a new file in this folder, call the file entitytypename.lua
and add the stub code shown below:
These three functions, init
, update
and message
are explained in detail later. There must always be an entity type called player
which acts as the abstraction for players within the simulation.
These three functions, init
, update
and message
, govern the behaviour of all entities of this type.
Init
This is called when the entity is created and should be used to set initial state (for example, setting the Chunkloader or Data fields).
Update
This is called each tick to update the entity, dt is the time since the last update in seconds.
Message
This is called when another entity sends a message to this entity (note that the entity sending the message might not be in the same chunk). The message is of type message (see types below).
On the player entity this function also acts as the handler for messages received from a game client, which follow the same format.
The msg argument supplied to this function is defined as follows:
Entity API
A number of API calls are available for certain entity-related actions such as spawning entities, they are accessed by interfacing with the api.entity
object in the global scope within all server-side scripts.
For example, sending a message to a particular entity each tick would look like:
Example
Below is the example cat.lua script which exists in the default template repository. The comments provide further information on what each line is doing.
Last updated