Package openmw.coreΒΆ

openmw.core defines functions and types that are available in both local and global scripts.

Usage:

local core = require('openmw.core')

Type core

core.API_REVISION

The revision of OpenMW Lua API.

core.EQUIPMENT_SLOT

Available equipment slots.

core.OBJECT_TYPE

Possible object.type values.

core.getGameTimeInHours()

Current time of the game world in hours.

core.getGameTimeInSeconds()

Game time in seconds.

core.quit()

Terminates the game and quits to the OS.

core.sendGlobalEvent(eventName, eventData)

Send an event to global scripts.

Type Cell

Cell.gridX

Index of the cell by X (only for exteriors).

Cell.gridY

Index of the cell by Y (only for exteriors).

Cell.hasWater

True if the cell contains water.

Cell.isExterior

Is it exterior or interior.

Cell:isInSameSpace(object)

Returns true either if the cell contains the object or if the cell is an exterior and the object is also in an exterior.

Cell.name

Name of the cell (can be empty string).

Cell.region

Region of the cell.

Cell:selectObjects(query)

Select objects from the cell with a Query (only in global scripts).

Type EQUIPMENT_SLOT

EQUIPMENT_SLOT.Ammunition
EQUIPMENT_SLOT.Amulet
EQUIPMENT_SLOT.Belt
EQUIPMENT_SLOT.Boots
EQUIPMENT_SLOT.CarriedLeft
EQUIPMENT_SLOT.CarriedRight
EQUIPMENT_SLOT.Cuirass
EQUIPMENT_SLOT.Greaves
EQUIPMENT_SLOT.Helmet
EQUIPMENT_SLOT.LeftGauntlet
EQUIPMENT_SLOT.LeftPauldron
EQUIPMENT_SLOT.LeftRing
EQUIPMENT_SLOT.Pants
EQUIPMENT_SLOT.RightGauntlet
EQUIPMENT_SLOT.RightPauldron
EQUIPMENT_SLOT.RightRing
EQUIPMENT_SLOT.Robe
EQUIPMENT_SLOT.Shirt
EQUIPMENT_SLOT.Skirt

Type GameObject

GameObject:addScript(scriptPath)

Add new local script to the object.

GameObject:canMove()

Returns true if the object is an actor and is able to move.

GameObject.cell

The cell where the object currently is. During loading a game and for objects in an inventory or a container cell is nil.

GameObject.count

Count (makes sense if holded in a container).

GameObject.destCell

Destination cell (only if a teleport door).

GameObject.destPosition

Destination (only if a teleport door).

GameObject.destRotation

Destination rotation (only if a teleport door).

GameObject:getCurrentSpeed()

Current speed.

GameObject:getEquipment()

Get equipment.

GameObject:getRunSpeed()

Speed of running.

GameObject:getWalkSpeed()

Speed of walking.

GameObject.inventory

Inventory of an Player/NPC or content of an container.

GameObject:isEquipped(item)

Returns true if the item is equipped on the object.

GameObject:isInMagicStance()

Is the actor in magic stance.

GameObject:isInWeaponStance()

Is the actor in weapon stance.

GameObject:isOnGround()

Is the actor standing on ground.

GameObject:isSwimming()

Is the actor in water.

GameObject.isTeleport

True if it is a teleport door (only if object.type == "Door").

GameObject:isValid()

Is the object still exists/available.

GameObject.position

Object position.

GameObject.recordId

Record ID.

GameObject.rotation

Object rotation (ZXY order).

GameObject:sendEvent(eventName, eventData)

Send local event to the object.

GameObject:setEquipment(equipment)

Set equipment.

GameObject:teleport(cellName, position, rotation)

Moves object to given cell and position.

GameObject.type

Type of the object (see openmw.core#OBJECT_TYPE).

Type Inventory

Inventory:countOf(recordId)

The number of items with given recordId.

Inventory:getAll()

Get all content of the inventory.

Inventory:getApparatuses()

Get all apparatuses.

Inventory:getArmor()

Get all armor.

Inventory:getBooks()

Get all books.

Inventory:getClothing()

Get all clothing.

Inventory:getIngredients()

Get all ingredients.

Inventory:getLights()

Get all lights.

Inventory:getLockpicks()

Get all lockpicks.

Inventory:getMiscellaneous()

Get all miscellaneous items.

Inventory:getPotions()

Get all potions.

Inventory:getProbes()

Get all probes.

Inventory:getRepairKits()

Get all repair kits.

Inventory:getWeapons()

Get all weapon.

Type OBJECT_TYPE

OBJECT_TYPE.Activator

"Activator"

OBJECT_TYPE.Armor

"Armor"

OBJECT_TYPE.Book

"Book"

OBJECT_TYPE.Clothing

"Clothing"

OBJECT_TYPE.Container

"Container"

OBJECT_TYPE.Creature

"Creature"

OBJECT_TYPE.Door

"Door"

OBJECT_TYPE.Ingredient

"Ingredient"

OBJECT_TYPE.Light

"Light"

OBJECT_TYPE.Miscellaneous

"Miscellaneous"

OBJECT_TYPE.NPC

"NPC"

OBJECT_TYPE.Player

"Player"

OBJECT_TYPE.Potion

"Potion"

OBJECT_TYPE.Static

"Static"

OBJECT_TYPE.Weapon

"Weapon"

Type ObjectList

ObjectList:ipairs()

Create iterator.

ObjectList:select(query)

Filter list with a Query.

Type core

Field(s)

#number core.API_REVISION

The revision of OpenMW Lua API.

It is an integer that is incremented every time the API is changed.

#EQUIPMENT_SLOT core.EQUIPMENT_SLOT

Available equipment slots.

Used in object:getEquipment and object:setEquipment.

#OBJECT_TYPE core.OBJECT_TYPE

Possible object.type values.

core.getGameTimeInHours()

Current time of the game world in hours.

Note that the number of game seconds in a game hour is not guaranteed to be fixed.

Return value

#number:

core.getGameTimeInSeconds()

Game time in seconds.

The number of seconds in the game world, passed from starting a new game.

Return value

#number:

core.quit()

Terminates the game and quits to the OS.

Should be used only for testing purposes.

core.sendGlobalEvent(eventName, eventData)

Send an event to global scripts.

Parameters

  • #string eventName :

  • eventData :

Type Cell

A cell of the game world.

Field(s)

#number Cell.gridX

Index of the cell by X (only for exteriors).

#number Cell.gridY

Index of the cell by Y (only for exteriors).

#boolean Cell.hasWater

True if the cell contains water.

#boolean Cell.isExterior

Is it exterior or interior.

Cell:isInSameSpace(object)

Returns true either if the cell contains the object or if the cell is an exterior and the object is also in an exterior.

Parameter

Return value

#boolean:

Usage:

if obj1.cell:isInSameSpace(obj2) then
    dist = (obj1.position - obj2.position):length()
else
    -- the distance can't be calculated because the coordinates are in different spaces
end
#string Cell.name

Name of the cell (can be empty string).

#string Cell.region

Region of the cell.

Cell:selectObjects(query)

Select objects from the cell with a Query (only in global scripts).

Returns an empty list if the cell is not loaded.

Parameter

Return value

#ObjectList:

Type EQUIPMENT_SLOT

Field(s)

#number EQUIPMENT_SLOT.Ammunition
#number EQUIPMENT_SLOT.Amulet
#number EQUIPMENT_SLOT.Belt
#number EQUIPMENT_SLOT.Boots
#number EQUIPMENT_SLOT.CarriedLeft
#number EQUIPMENT_SLOT.CarriedRight
#number EQUIPMENT_SLOT.Cuirass
#number EQUIPMENT_SLOT.Greaves
#number EQUIPMENT_SLOT.Helmet
#number EQUIPMENT_SLOT.LeftGauntlet
#number EQUIPMENT_SLOT.LeftPauldron
#number EQUIPMENT_SLOT.LeftRing
#number EQUIPMENT_SLOT.Pants
#number EQUIPMENT_SLOT.RightGauntlet
#number EQUIPMENT_SLOT.RightPauldron
#number EQUIPMENT_SLOT.RightRing
#number EQUIPMENT_SLOT.Robe
#number EQUIPMENT_SLOT.Shirt
#number EQUIPMENT_SLOT.Skirt

Type GameObject

Any object that exists in the game world and has a specific location.

Player, actors, items, and statics are game objects.

Field(s)

GameObject:addScript(scriptPath)

Add new local script to the object.

Can be called only from a global script.

Parameter

  • #string scriptPath : Path to the script in OpenMW virtual filesystem

GameObject:canMove()

Returns true if the object is an actor and is able to move.

For dead, paralized, or knocked down actors in returns false. access to the object will raise an error.

Return value

#boolean:

#Cell GameObject.cell

The cell where the object currently is. During loading a game and for objects in an inventory or a container cell is nil.

#number GameObject.count

Count (makes sense if holded in a container).

#string GameObject.destCell

Destination cell (only if a teleport door).

openmw.util#Vector3 GameObject.destPosition

Destination (only if a teleport door).

openmw.util#Vector3 GameObject.destRotation

Destination rotation (only if a teleport door).

GameObject:getCurrentSpeed()

Current speed.

Can be called only from a local script.

Return value

#number:

GameObject:getEquipment()

Get equipment.

Returns a table slot -> GameObject of currently equipped items. See openmw.core#EQUIPMENT_SLOT. Returns empty table if the object doesn't have equipment slots.

Return value

#map<#number,#GameObject>:

GameObject:getRunSpeed()

Speed of running.

Returns 0 if not an actor, but for dead actors it still returns a positive value.

Return value

#number:

GameObject:getWalkSpeed()

Speed of walking.

Returns 0 if not an actor, but for dead actors it still returns a positive value.

Return value

#number:

#Inventory GameObject.inventory

Inventory of an Player/NPC or content of an container.

GameObject:isEquipped(item)

Returns true if the item is equipped on the object.

Parameter

Return value

#boolean:

GameObject:isInMagicStance()

Is the actor in magic stance.

Can be called only from a local script.

Return value

#boolean:

GameObject:isInWeaponStance()

Is the actor in weapon stance.

Can be called only from a local script.

Return value

#boolean:

GameObject:isOnGround()

Is the actor standing on ground.

Can be called only from a local script.

Return value

#boolean:

GameObject:isSwimming()

Is the actor in water.

Can be called only from a local script.

Return value

#boolean:

#boolean GameObject.isTeleport

True if it is a teleport door (only if object.type == "Door").

GameObject:isValid()

Is the object still exists/available.

Returns true if the object exists and loaded, and false otherwise. If false, then every access to the object will raise an error.

Return value

#boolean:

openmw.util#Vector3 GameObject.position

Object position.

#string GameObject.recordId

Record ID.

openmw.util#Vector3 GameObject.rotation

Object rotation (ZXY order).

GameObject:sendEvent(eventName, eventData)

Send local event to the object.

Parameters

  • #string eventName :

  • eventData :

GameObject:setEquipment(equipment)

Set equipment.

Keys in the table are equipment slots (see openmw.core#EQUIPMENT_SLOT). Each value can be either a GameObject or recordId. Raises an error if the object doesn't have equipment slots and table is not empty. Can be called only on self or from a global script.

Parameter

  • equipment :

GameObject:teleport(cellName, position, rotation)

Moves object to given cell and position.

The effect is not immediate: the position will be updated only in the next frame. Can be called only from a global script.

Parameters

  • #string cellName : Name of the cell to teleport into. For exteriors can be empty.

  • openmw.util#Vector3 position : New position

  • openmw.util#Vector3 rotation : New rotation. Optional argument. If missed, then the current rotation is used.

#string GameObject.type

Type of the object (see openmw.core#OBJECT_TYPE).

Type Inventory

Inventory of a player/NPC or a content of a container.

Field(s)

Inventory:countOf(recordId)

The number of items with given recordId.

Parameter

  • #string recordId :

Return value

#number:

Inventory:getAll()

Get all content of the inventory.

Return value

#ObjectList:

Inventory:getApparatuses()

Get all apparatuses.

Return value

#ObjectList:

Inventory:getArmor()

Get all armor.

Return value

#ObjectList:

Inventory:getBooks()

Get all books.

Return value

#ObjectList:

Inventory:getClothing()

Get all clothing.

Return value

#ObjectList:

Inventory:getIngredients()

Get all ingredients.

Return value

#ObjectList:

Inventory:getLights()

Get all lights.

Return value

#ObjectList:

Inventory:getLockpicks()

Get all lockpicks.

Return value

#ObjectList:

Inventory:getMiscellaneous()

Get all miscellaneous items.

Return value

#ObjectList:

Inventory:getPotions()

Get all potions.

Return value

#ObjectList:

Inventory:getProbes()

Get all probes.

Return value

#ObjectList:

Inventory:getRepairKits()

Get all repair kits.

Return value

#ObjectList:

Inventory:getWeapons()

Get all weapon.

Return value

#ObjectList:

Type OBJECT_TYPE

Field(s)

#string OBJECT_TYPE.Activator

"Activator"

#string OBJECT_TYPE.Armor

"Armor"

#string OBJECT_TYPE.Book

"Book"

#string OBJECT_TYPE.Clothing

"Clothing"

#string OBJECT_TYPE.Container

"Container"

#string OBJECT_TYPE.Creature

"Creature"

#string OBJECT_TYPE.Door

"Door"

#string OBJECT_TYPE.Ingredient

"Ingredient"

#string OBJECT_TYPE.Light

"Light"

#string OBJECT_TYPE.Miscellaneous

"Miscellaneous"

#string OBJECT_TYPE.NPC

"NPC"

#string OBJECT_TYPE.Player

"Player"

#string OBJECT_TYPE.Potion

"Potion"

#string OBJECT_TYPE.Static

"Static"

#string OBJECT_TYPE.Weapon

"Weapon"

Type ObjectList

Extends #list<#GameObject>

List of GameObjects.

Field(s)

ObjectList:ipairs()

Create iterator.

ObjectList:select(query)

Filter list with a Query.

Parameter

Return value

#ObjectList: