trying again stealing boilerplate code

This commit is contained in:
Flerp 2025-10-25 00:40:16 -07:00
parent 3e07ca5ee7
commit 6014ef5d46
2 changed files with 47 additions and 23 deletions

View File

@ -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();
}

View File

@ -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,6 +9,9 @@
#include "Player.h"
#include "GameObject.h"
#include <vector>
#include <limits>
using namespace Acore::ChatCommands;
namespace
@ -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();
}