Skip to content

Conversation

@ranisalt
Copy link
Member

@ranisalt ranisalt commented Nov 15, 2025

Pull Request Prelude

Changes Proposed

Migrates talkactions to use the TalkAction Lua interface

Converted talkactions with this Python script and a few manual adjustments:

import xml.etree.ElementTree as ET
from os import makedirs, path, unlink

tree = ET.parse("talkactions.xml")
root = tree.getroot()
assert root.tag == "talkactions"

for child in root:
    assert child.tag in [
        "talkaction",
    ], f"Invalid tag '{child.tag}', must be 'talkaction'"

    if "script" not in child.attrib:
        continue

    words = []
    lines = []
    script = ""

    for attrib in child.attrib:
        if attrib.lower() == "script":
            script = child.attrib[attrib]

        elif attrib.lower() == "words":
            words = child.attrib[attrib].split(";")

        elif attrib.lower() == "separator":
            lines.append(f'talkaction:separator("{child.attrib[attrib]}")')

        else:
            print(f"Unknown attribute: {attrib}")

    with open(f"scripts/{script}", "r") as f:
        talkaction = f.read().split("\n")

    for idx, line in enumerate(talkaction):
        if line.startswith("function onSay"):
            talkaction[idx] = talkaction[idx].replace("onSay", "talkaction.onSay")
            break
    else:
        print(f"talkaction {child.attrib['words']} does not have onSay function")
        continue

    talkaction.insert(0, f"local talkaction = TalkAction({', '.join(f'\"{word}\"' for word in words)})\n")
    talkaction.extend(lines)
    talkaction.append("talkaction:register()")

    print(f"Converting talkaction {child.attrib['words']}")

    makedirs(f"../scripts/talkactions/{path.dirname(script)}", exist_ok=True)
    with open(f"../scripts/talkactions/{script}", "w") as f:
        f.write("\n".join(talkaction))

    unlink(f"scripts/{script}")

@ranisalt ranisalt requested a review from Copilot November 15, 2025 04:42
Copilot finished reviewing on behalf of ranisalt November 15, 2025 04:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request migrates the talkactions system from XML-based configuration to a Lua-based registration system using the TalkAction interface. This modernizes the talkaction loading mechanism and provides better code organization and type safety.

  • Converts all existing talkaction scripts to use the new TalkAction Lua interface with explicit registration
  • Adds a backward-compatibility XML loader for legacy configurations
  • Introduces a new library for talkaction utilities (command logging)

Reviewed Changes

Copilot reviewed 43 out of 44 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
data/talkactions/talkactions.xml Removes all XML talkaction entries, leaving only a deprecation notice
data/scripts/xml/talkactions.lua Adds XML loader for backward compatibility with legacy talkaction configurations
data/scripts/lib/talkactions.lua Adds utility library with command logging functionality
data/scripts/talkactions/test/*.lua Converts test talkactions (magic_effect, animation_effect, looktype) to use TalkAction interface
data/scripts/talkactions/player/*.lua Converts player talkactions (uptime, server_info, online, kills, death_list, change_sex, buy_premium) to use TalkAction interface
data/scripts/talkactions/house/*.lua Converts house-related talkactions (sell_house, leave_house, buy_house) to use TalkAction interface
data/scripts/talkactions/commands/*.lua Converts all admin/GM command talkactions to use TalkAction interface with proper registration and separator configuration
Comments suppressed due to low confidence (1)

data/scripts/talkactions/house/buy_house.lua:4

  • [nitpick] The config variable should be moved after the talkaction declaration for consistency with the pattern used in other converted scripts (e.g., buy_premium.lua, change_sex.lua). This maintains a consistent structure across all talkaction files where the TalkAction object is declared first, followed by any local variables or helper functions, and finally the onSay implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ranisalt ranisalt force-pushed the feat/talkactions-xml-to-lua branch from 7a1984c to 2155770 Compare November 15, 2025 05:21
@kygov
Copy link
Contributor

kygov commented Nov 15, 2025

Last time I checked, commit 79138e8 completely broke ability to reload actions because bool configureEvent(const pugi::xml_node&) override { return false; }

so it fails here https://github.com/otland/forgottenserver/blob/master/src/baseevents.cpp#L45

Looks like its not case here but you can check this.

@ranisalt
Copy link
Member Author

@kygov correct, I see a few calls to g_actions->loadFromXml() are still present which will print the error message. With the new code, reloading actions is done through reloading scripts instead, and g_actions->loadFromXml() should never be called.

There is no way of reloading a subset of scripts (so for example only reloading data/scripts/actions)

@ranisalt ranisalt force-pushed the feat/talkactions-xml-to-lua branch from 0f33d1f to c8ae1ff Compare December 4, 2025 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants