1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-07 13:30:57 +00:00

FEAT: AddTopic in Lua, close #8334

This commit is contained in:
Dave Corley 2025-02-01 03:21:40 -07:00 committed by Dave Corley
parent f5de0d1c40
commit 4150f5fad6

View file

@ -1,5 +1,6 @@
#include "types.hpp"
#include <apps/openmw/mwbase/dialoguemanager.hpp>
#include <components/esm3/loadbsgn.hpp>
#include <components/esm3/loadfact.hpp>
@ -195,6 +196,18 @@ namespace MWLua
throw std::runtime_error("Only player and global scripts can toggle teleportation.");
MWBase::Environment::get().getWorld()->enableTeleporting(state);
};
player["addTopic"] = [](const Object& player, std::string topicId) {
if (dynamic_cast<const LObject*>(&player) && !dynamic_cast<const SelfObject*>(&player))
throw std::runtime_error("Only player and global scripts may add topics.");
ESM::RefId topic = ESM::RefId::stringRefId(topicId);
if (!MWBase::Environment::get().getESMStore()->get<ESM::Dialogue>().search(topic))
{
throw std::runtime_error("Failed to add topic " + topicId + ": topic record not found");
}
MWBase::Environment::get().getDialogueManager()->addTopic(topic);
};
player["sendMenuEvent"] = [context](const Object& player, std::string eventName, const sol::object& eventData) {
verifyPlayer(player);
context.mLuaEvents->addMenuEvent({ std::move(eventName), LuaUtil::serialize(eventData) });