From 6014ef5d46507c914583744220d7e85edecb693c Mon Sep 17 00:00:00 2001 From: Flerp Date: Sat, 25 Oct 2025 00:40:16 -0700 Subject: [PATCH] trying again stealing boilerplate code --- src/loader.cpp | 11 ++++++-- src/teleport-to-node.cpp | 59 ++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/loader.cpp b/src/loader.cpp index c138e39..36d2912 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -1,6 +1,11 @@ -void Addmod_telenodeScripts(); +/* + * AzerothCore module loader for mod-teleport-to-node + */ -void Addmod_telenode_loaderScripts() +void AddSC_telenode_commandscript(); + +// Called by the module system; name can be anything, just referenced in CMake +void Addmod_teleport_to_nodeScripts() { - Addmod_telenodeScripts(); + AddSC_telenode_commandscript(); } diff --git a/src/teleport-to-node.cpp b/src/teleport-to-node.cpp index b9be826..7bf759f 100644 --- a/src/teleport-to-node.cpp +++ b/src/teleport-to-node.cpp @@ -1,4 +1,7 @@ -// src/teleport-to-node.cpp +/* + * MIT-style module command following AzerothCore boilerplate + */ + #include "ScriptMgr.h" #include "CommandScript.h" #include "Chat.h" @@ -6,13 +9,16 @@ #include "Player.h" #include "GameObject.h" +#include +#include + using namespace Acore::ChatCommands; namespace { // === CONFIG === static constexpr float TELEPORT_DISTANCE = 200.0f; // yards - static constexpr float Z_BUMP = 1.5f; // anti-clip offset + static constexpr float Z_BUMP = 1.5f; // anti-clip offset // Mining node entries (trim as needed) static const std::vector kVeinEntries = { @@ -52,7 +58,7 @@ namespace if (player->IsInCombat()) { ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat."); - return true; + return true; // handled } if (GameObject* node = FindNearestVein(player, TELEPORT_DISTANCE)) @@ -78,31 +84,44 @@ class telenode_commandscript : public CommandScript public: telenode_commandscript() : CommandScript("telenode_commandscript") { } - // NOTE: Use Acore::ChatCommands::ChatCommandTable (or the 'using' above) + // EXACTLY like the AzerothCore boilerplate: a ChatCommandTable + static handler fn ChatCommandTable GetCommands() const override { - static ChatCommandTable cmds = + static ChatCommandTable commandTable = { - // .telenode (player-only; change SEC if you want) + // .telenode { "telenode", - SEC_PLAYER, - Console::No, - // handler signature with no args - [](ChatHandler* handler) - { - if (auto* session = handler->GetSession()) - return DoTeleNode(session->GetPlayer()); - return false; - }, - "" // help text (optional) - }, + SEC_PLAYER, // security (adjust via DB if you want) + Console::No, // no console by default + &HandleTeleNode, // function pointer (NOT a lambda) + "" } // help text (optional) }; - return cmds; + return commandTable; + } + + // Boilerplate-compatible handler signature + static bool HandleTeleNode(ChatHandler* handler, char const* /*args*/) + { + if (!handler) + return false; + + Player* player = nullptr; + if (auto* session = handler->GetSession()) + player = session->GetPlayer(); + + if (!player) + { + handler->SendSysMessage("Player only."); + handler->SetSentErrorMessage(true); + return false; + } + + return DoTeleNode(player); } }; -// Called by your module loader -void Addmod_telenodeScripts() +// Boilerplate-style exported symbol that your loader will call +void AddSC_telenode_commandscript() { new telenode_commandscript(); }