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.getGMST(setting) |
Get a GMST setting from content files. |
core.getGameTime() |
Game time in seconds. |
core.getGameTimeScale() |
The scale of game time relative to simulation time. |
core.getRealTime() |
Real time in seconds; starting point is not fixed (can be time since last reboot), use only for measuring intervals. |
core.getSimulationTime() |
Simulation time in seconds. |
core.getSimulationTimeScale() |
The scale of simulation time relative to real time. |
core.isWorldPaused() |
Whether the world is paused (onUpdate doesn't work when the world is paused). |
core.l10n(context, fallbackLocale) |
Return l10n formatting function for the given context. |
core.quit() |
Terminates the game and quits to the OS. |
core.sendGlobalEvent(eventName, eventData) |
Send an event to global scripts. |
Type Cell
Cell:getAll(type) |
Get all objects of given type from the 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 |
Whether the cell is an exterior. |
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.isQuasiExterior |
Whether the cell is a quasi exterior (like interior but with the sky and the wheather). |
Cell.name |
Name of the cell (can be empty string). |
Cell.region |
Region of the cell. |
Type GameObject
GameObject:activateBy(actor) |
Activate the object. |
GameObject:addScript(scriptPath) |
Add new local script to the object. |
GameObject.cell |
The cell where the object currently is. During loading a game and for objects in an inventory or a container |
GameObject.count |
Count (makes sense if stored in a container). |
GameObject:hasScript(scriptPath) |
Whether a script with given path is attached to this object. |
GameObject:isValid() |
Does the object still exist and is available. |
GameObject.position |
Object position. |
GameObject.recordId |
Record ID. |
GameObject:removeScript(scriptPath) |
Removes script that was attached by |
GameObject.rotation |
Object rotation (ZXY order). |
GameObject:sendEvent(eventName, eventData) |
Send local event to the object. |
GameObject:teleport(cellName, position, rotation) |
Moves object to given cell and position. |
GameObject.type |
Type of the object (one of the tables from the package openmw.types#types). |
Type Inventory
Inventory:countOf(recordId) |
The number of items with given recordId. |
Inventory:getAll(type) |
Get all items of given type from the inventory. |
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.
- core.getGMST(setting)
-
Get a GMST setting from content files.
Parameter
-
#string setting
: Setting name
Return value
#any:
-
- core.getGameTime()
-
Game time in seconds.
Return value
#number:
- core.getGameTimeScale()
-
The scale of game time relative to simulation time.
Return value
#number:
- core.getRealTime()
-
Real time in seconds; starting point is not fixed (can be time since last reboot), use only for measuring intervals.
For Unix time use
os.time()
.Return value
#number:
- core.getSimulationTime()
-
Simulation time in seconds.
The number of simulation seconds passed in the game world since starting a new game.
Return value
#number:
- core.getSimulationTimeScale()
-
The scale of simulation time relative to real time.
Return value
#number:
- core.isWorldPaused()
-
Whether the world is paused (onUpdate doesn't work when the world is paused).
Return value
#boolean:
- core.l10n(context, fallbackLocale)
-
Return l10n formatting function for the given context.
Localisation files (containing the message names and translations) should be stored in VFS as files of the form
l10n/<ContextName>/<Locale>.yaml
.See Localisation for details of the localisation file structure.
When calling the l10n formatting function, if no localisation can be found for any of the requested locales then the message key will be returned instead (and formatted, if possible). This makes it possible to use the source strings as message identifiers.
If you do not use the source string as a message identifier you should instead make certain to include a fallback locale with a complete set of messages.
Parameters
-
#string context
: l10n context; recommended to use the name of the mod.This must match the <ContextName> directory in the VFS which stores the localisation files.
-
#string fallbackLocale
: The source locale containing the default messagesIf omitted defaults to "en".
Return value
#function:
Usages:
# DataFiles/l10n/MyMod/en.yaml good_morning: 'Good morning.' you_have_arrows: |- {count, plural, one {You have one arrow.} other {You have {count} arrows.} }
# DataFiles/l10n/MyMod/de.yaml good_morning: "Guten Morgen." you_have_arrows: |- {count, plural, one {Du hast ein Pfeil.} other {Du hast {count} Pfeile.} } "Hello {name}!": "Hallo {name}!"
-- Usage in Lua local myMsg = core.l10n('MyMod', 'en') print( myMsg('good_morning') ) print( myMsg('you_have_arrows', {count=5}) ) print( myMsg('Hello {name}!', {name='World'}) )
-
- 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)
- Cell:getAll(type)
-
Get all objects of given type from the cell.
Parameter
-
type
: (optional) object type (see openmw.types#types)
Return value
Usage:
local type = require('openmw.types') local all = cell:getAll() local weapons = cell:getAll(types.Weapon)
-
- #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
-
Whether the cell is an exterior.
- 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
-
#GameObject object
:
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
-
- #boolean Cell.isQuasiExterior
-
Whether the cell is a quasi exterior (like interior but with the sky and the wheather).
- #string Cell.name
-
Name of the cell (can be empty string).
- #string Cell.region
-
Region of the cell.
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:activateBy(actor)
-
Activate the object.
Parameter
-
#GameObject actor
: The actor who activates the object
Usage:
local self = require('openmw.self') object:activateBy(self)
-
- GameObject:addScript(scriptPath)
-
Add new local script to the object.
Can be called only from a global script. Script should be specified in a content file (omwgame/omwaddon/omwscripts) with a CUSTOM flag. Scripts can not be attached to Statics.
Parameter
-
#string scriptPath
: Path to the script in OpenMW virtual filesystem.
-
- #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 stored in a container).
- GameObject:hasScript(scriptPath)
-
Whether a script with given path is attached to this object.
Can be called only from a global script.
Parameter
-
#string scriptPath
: Path to the script in OpenMW virtual filesystem.
Return value
#boolean:
-
- GameObject:isValid()
-
Does the object still exist and is 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.
- GameObject:removeScript(scriptPath)
-
Removes script that was attached by
addScript
Can be called only from a global script.Parameter
-
#string scriptPath
: Path to the script in OpenMW virtual filesystem.
-
- openmw.util#Vector3 GameObject.rotation
-
Object rotation (ZXY order).
- GameObject:sendEvent(eventName, eventData)
-
Send local event to the object.
Parameters
-
#string eventName
: -
eventData
:
-
- 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.
-
- #table GameObject.type
-
Type of the object (one of the tables from the package openmw.types#types).
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(type)
-
Get all items of given type from the inventory.
Parameter
-
type
: (optional) items type (see openmw.types#types)
Return value
Usage:
local types = require('openmw.types') local self = require('openmw.self') local playerInventory = types.Actor.inventory(self.object) local all = playerInventory:getAll() local weapons = playerInventory:getAll(types.Weapon)
-
Type ObjectList
List of GameObjects.
Implements iterables#List of #GameObject
ObjectList
is a list of #GameObject
.