Game

This module provides defines an interface for game related state.

Constants

PLUGIN_COMBAT_ENGINE

Combat engine plugin ID.


2DA

Get2daColumnCount(twoda)

Get number of columns in 2da.

Parameters:
  • twoda – 2da file.
Get2daFloat(twoda, col, row)

Get float value.

Parameters:
  • twoda (string) – 2da file.
  • col (int or string) – Column label or index.
  • row (int) – Row index.
Get2daInt(twoda, col, row)

Get int value.

Parameters:
  • twoda (string) – 2da file.
  • col (int or string) – Column label or index.
  • row (int) – Row index.
Get2daRowCount(twoda)

Get number of rows in 2da.

Parameters:
  • twoda (string) – 2da file.
Get2daString(twoda, col, row)

Get string value.

Parameters:
  • twoda (string) – 2da file.
  • col (int or string) – Column label or index.
  • row (int) – Row index.

Events

EventActivateItem(item, location, target)

Create activate item even.

Parameters:
  • item – Item.
  • location – Target location.
  • target – Target object.
EventConversation()

Create conversation event.

EventSpellCastAt(caster, spell[, is_harmful])

Creature spell cast at event.

Parameters:
  • caster – Spell caster.
  • spell (int) – SPELL_* constant.
  • is_harmful (bool) – Is spell harmful to target. Default: true
EventUserDefined(event)

Create user defined event.

Parameters:
  • event – An integer id.
GetClickingObject()

Get last clicking object.

GetEnteringObject()

Get last object to enter.

GetExitingObject()

Get last object to exit.

GetItemActivated()

Gets the item activated.

GetItemActivatedTarget()

Gets item activated event target.

GetItemActivatedTargetLocation()

Gets item activated event location.

GetItemActivator()

Gets object that activated item.

GetLastPCToCancelCutscene()

Gets last PC to cancel cutscene.

GetLastPlayerDied()

Gets last player died.

GetLastPlayerDying()

Gets last player dying.

GetLastUsedBy()

Gets last object to use something.

GetPCLevellingUp()

Gets last PC that leveled up.

GetPlaceableLastClickedBy()

Get last object to click a placeable.

GetUserDefinedEventNumber()

Get user defined event number.

GetUserDefinedItemEventNumber(obj)

Get the current UserDefined Item Event Number.

Parameters:
  • obj (Item) – Item object
Return type:

ITEM_EVENT_* (see itemevents.2da)

SetUserDefinedItemEventNumber(obj, event)

Set the current UserDefined Item Event Number

Parameters:
  • obj (Item) – Item object
  • event – ITEM_EVENT_* (see itemevents.2da)
SignalEvent(obj, event)

Signal an event.

Parameters:
  • obj (Object) – Object to signal.
  • event – Event object.

Objects

ClearCacheData(obj)

Clear the effect cache.

CreateObject(object_type, template, loc[, appear[, newtag]])

Create an object of a specified type at a given location

Parameters:
  • object_type (int) – OBJECT_TYPE_*
  • template (string) – The resref of the object to create from the pallet.
  • loc (Location) – The location to create the object at.
  • appear (bool) – If true, the object will play its spawn in animation. Default: false.
  • newtag (string) – If this string is not empty, it will replace the default tag from the template. Default: “”
Return type:

New object or OBJECT_INVALID

ExportSingleCharacter(player)

Export single character.

Parameters:
  • player (Creature) – Object to export.
GetCanonicalID(cre)

Get canonical ID

Parameters:
GetModule()

Get Module.

GetObjectByID(id)

Get object by ID.

Parameters:
  • id (int) – Object ID.
Return type:

An object or OBJECT_INVALID

GetObjectByTag(tag[, nth])

Gets an object by tag

Parameters:
  • tag (string) – Tag of object.
  • nth (int) – Nth object. Default: 1
GetPCSpeaker()

Gets the PC speaker.

Return type:Creature or OBJECT_INVALID
GetWaypointByTag(tag)

Finds a waypiont by tag

Parameters:
  • tag (string) – Tag of waypoint.
Return type:

Waypoint or OBJECT_INVALID

ObjectsByTag(tag)

Iterator over objects by tag

Parameters:
  • tag (string) – Tag of object
ObjectsInShape(shape, size, location[, line_of_sight[, mask[, origin]]])

Iterator over objects in a shape.

Parameters:
  • shape (int) – SHAPE_*
  • size (int) – The size of the shape. Dependent on shape or RADIUS_SIZE_*.
  • location – Shapes location.
  • line_of_sight (bool) – This can be used to ensure that spell effects don’t go through walls. Default: false
  • mask (int) – Object type mask. Default: OBJECT_TYPE_CREATURE.
  • origin (vector) – Normally the spell-caster’s position. Default: Zero vector.
PCs()

Iterator over all PCs

RemoveObjectFromCache(obj)

Remove object from Solstice object cache. :param obj: Any object. :type obj: Object


Plugins

The plugin in system allows registering plugins by a string identifier and optionally enforcing a particular interface.

Note

Only one plugin can be registered to a plugin interface.

RegisterPlugin(name[, enforcer])

Registers a plugin interface.

Parameters:
  • name (string) – Plugin interface name.
  • enforcer (function) – Function that is called when a plugin attempts to load. This is to allow enforcing a particular interface.
LoadPlugin(name, interface)

Loads a plugin for a given plugin interface. If the plugin is successfully loaded the plugin system will attempt to call plugin.OnLoad if it exists.

Parameters:
  • name (string) – Plugin interface name.
  • interface (table) – A table of functions that satisfy the plugin interface.
GetPlugin(name)

Gets a plugin by name.

Parameters:
  • name (string) – Plugin interface name.
UnloadPlugin(name)

Unloads a plugin for a given plugin interface. The plugin system will attempt to call plugin.OnUnload if it exists.

Parameters:
  • name (string) – Plugin interface name.
IsPluginLoaded(name)

Determines if a plugin is loaded.

Parameters:
  • name (string) – Plugin interface name.

Signals

OnPreExportCharacter

This event is fired before saving a character.

OnPostExportCharacter

This event is fired after saving a character.

OnObjectClearCacheData

This signal is called when an object has its data cleared from the cache. This is typically for PCs only as they are not removed from the cache, but need some data reset for when the log in again.

OnObjectRemovedFromCache

This signal is called when an object is removed from the cache. Note that PCs are never removed from the cache.

OnUpdateCombatInfo

This signal is called when combat information is updated. Only one parameters is passed: a Creature instance.

Note

This is only active when a combat engine has been registered!

OnUpdateEffect

This is called whenever an effect is applied or removed from a creature. Two parameters are passed: a Creature instance and a Effect. Note: there is no way to determine if the effect was applied or removed, so it’s only useful in cases of updating/invalidating cached information.


Scripts

DumpScriptEnvironment()

Gets a string representation of the script environment.

ExecuteItemEvent(obj, item, event)

Executes item event. This is compatible with NWN tag based scripting. It will only work if that feature has been enabled.

Parameters:
  • obj – Object
  • item – Item
  • event – ITEM_EVENT_* See itemevents.2da
Return type:

SCRIPT_RETURN_*

ExecuteScript(script, target)

Executes a script on a specified target. This operates like the NWScript ExecuteScriptAndReturnInt rather than ExecuteScript.

Parameters:
  • script – Script to call.
  • target – Object to run the script on.
Return type:

SCRIPT_RETURN_* constant.

GetItemEventName(item)

Gets the item event script name. This function is compatible with NWN tag based scripting.

Parameters:
  • item (Item) – Item that caused the event.
GetItemEventType(obj)

Get last item event type.

Parameters:
  • obj – Object script is being run on.
Return type:

ITEM_EVENT_* See itemevents.2da

LoadScript(fname)

Load script file.

Parameters:
  • fname (string) – Script file name.
LockScriptEnvironment()

Locks the script environment. After this is called no variables can be set globally in the script environment

RunScript(script, target)

Run script.

Parameters:
  • script (string) – Script to call.
  • target – Object to run the script on.
SetItemEventPrefix([prefix=""])

Set item event prefix. This function is compatible with NWN tag based scripting.

Parameters:
  • prefix (string) – Prefix to add to script calls.
SetItemEventType(obj, event)

Sets item event type on object.

Parameters:
  • obj – Object script is being run on.
  • event (int) – ITEM_EVENT_* See itemevents.2da
SetScriptReturnValue(object[, value=SCRIPT_RETURN_CONTINUE])

Set script return value.

Parameters:
  • object – Object script is being run on.
  • value (int) – SCRIPT_RETURN_* constant.
UnlockScriptEnvironment()

Unlocks the script environment. After this is called variables can be set globally in the script environment


Time

GetDay()

Determine the current in-game calendar day.

GetHour()

Gets the current hour.

GetIsDawn()

Get if it’s dawn.

Return type:bool
GetIsDay()

Get if it’s day.

Return type:bool
GetIsDusk()

Get if it’s dusk

Return type:bool
GetIsNight()

Get if it’s night

Return type:bool
GetMillisecond()

Gets the current millisecond.

GetMinute()

Gets the current minute.

GetMonth()

Determine the current in-game calendar month.

GetSecond()

Gets the current second

GetYear()

Determine the current in-game calendar year.

HoursToSeconds(hours)

Converts hours to seconds

Parameters:
  • hours (int) – Number of hours
RoundsToSeconds(rounds)

Converts rounds to seconds

Parameters:
  • rounds (int) – Number of rounds
SetCalendar(year, month, day)

Set calendar

Parameters:
  • year (int) – Specific year to set calendar to from 1340 to 32001.
  • month (int) – Specific month to set calendar from 1 to 12.
  • day (int) – Specific day to set calendar to from 1 to 28.
SetTime(hour, minute, second, millisecond)

Sets the game’s current time.

Parameters:
  • hour (int) – The new hour value, from 0 to 23.
  • minute (int) – The new minute value from 0 to 1 (or 0 to a higher value if the module properties for time were changed).
  • second (int) – The new second value, from 0 to 59.
  • millisecond (int) – The new millisecond value, from 0 to 999.
TurnsToSeconds(turns)

Converts turns to seconds

Parameters:
  • turns (int) – Number of turns
UpdateTime()

Force update time.


TLK

GetTlkString(strref)

Get string by TLK table reference.

Parameters:
  • strref (int) – TLK table reference.
Return type:

string