Skip to content

Hypothetical feature request: MWSE-side "event handling"? #11

@Nakashio

Description

@Nakashio

New MWSE features:

Utilizing the xStartScript functionality after it's implemented, some optional event handling extension for MW scripts could hypothetically be accomplished by MWSE on its own side, provided it can be made to fire opcodes on its own. This is probably a very good idea.

For lack of actual hooks (perhaps those could be implemented eventually, too), this would be accomplished by MWSE-side polling for conditions (such as by using existing functionality of a MWSE or vanilla script command), instead of on the MWScript side, which should be more efficient and convenient.

Suggested implementation:
A mod would have a fire-once startscript run a MWSE function once per game load (simply managed by adding StopScript selfid to said startscript) to register a different script included in the mod for an event by calling a new MWSE function with a literal or dynamic scriptid. Then on the MWSE side, MWSE will maintain a background list of scripts and conditions and do background checks of the requested event (condition) and launch the respective scripts (as per xStartScript) as appropriate. Each event type is "maintained" separately by MWSE.

Possible examples of events/conditions (there should be the ability to require multiple conditions for the firing of one script, too):

  • A key is pressed; possibility for a key combination (relies on functionality: xKeyPressed or similar).
  • A mouseclick is done / a mouse button is pressed
  • The current cell is changed (relies on functionality: CellChanged or the more reliable (without the MCP fix) xGetPCCell).
  • The player enters a cell name that matches a regular expression (relies on functionality: basis of xGetPCCell + xStringMatch). This is quite powerful, as regular expressions are powerful.
  • The player is targetting an entity (relies on functionality: xGetPCTarget)
  • The player is targetting an entity of a specific type (relies on functionality: xRefType)
  • The player is affected by a specific spellid (relies on functionality: GetSpellEffects)
  • The player is affected by a specific effectid (relies on functionality: GetEffect)
  • A certain real world time threshold is passed i.e. "launch this script after X seconds".
  • As above, but the script is periodically launched by MWSE i.e. "launch this script every X seconds".
  • A certain in-game date or number of days passed since the beginning of the game is reached (relies on functionality: DaysPassed, Day, Month, Year) A mod could use the previous scheduling event to pretty much do this itself, though.
  • A certain in-game hour in the day is reached (relies on functionality: GameHour, DaysPassed)
  • The player readies a weapon of a specific type, or his magic stance, or the player is sneaking or jumping (relies on functionality: GetWeaponDrawn, GetSpellReadied, GetPCSneaking, GetPCJumping).
  • The player character starts sleeping or starts being in jail (relies on functionality: GetPCInJail, GetPCSleep)
  • The player is targetting an entity which's ID or Name matches a regular expression?
  • A specific sound is played? (relies on functionality: GetSoundPlaying)
  • A different script is started or stopped? (relies on functionality: ScriptRunning)
  • A Journal entry reaches a given index? (relies on functionality: GetJournalIndex) Polled for infrequently.
  • The weather changes (relies on functionality: GetCurrentWeather). Polled for infrequently.

Hypothetical, relies on new functionality:

  • The player enters combat / combat music starts playing. The same for combat ending.
  • The player enters dialog. Needs an extra MWSE function or a way for the launched script to get the reference of the NPC (or creature) being talked to.
  • The player leaves dialog.
  • A menu of a specific type is opened or closed (new functionality. menu types can include dialog, inventory, container inventory, enchanting, etc)?
  • A spell of a given type or school is cast, or a spell of a specific ID is cast by the player or by an NPC/creature.
  • Likely troublesome: the player equips/unequips an item of a specific id or a spell of a specific id.
  • Likely troublesome: an item of a given id is removed/added to the player's inventory.

Probably extraneous (?):

  • The player's health, magicka, fatigue or encumbrance is above or below a certain percentage.
  • The player levels up or his/her level changes (relies on functionality: GetLevel)

Example function call:
x[un]RegisterEventCellChanged scriptid
or, a better, generalized form:
x[un]RegisterEvent scriptid eventid where eventid is a short taken from a premade list of events provided in MWSE's documentation.
The polling frequency for MWSE to use could also possibly be specified/customizable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions