trying again stealing boilerplate code
This commit is contained in:
parent
3e07ca5ee7
commit
6014ef5d46
@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
// src/teleport-to-node.cpp
|
/*
|
||||||
|
* MIT-style module command following AzerothCore boilerplate
|
||||||
|
*/
|
||||||
|
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "CommandScript.h"
|
#include "CommandScript.h"
|
||||||
#include "Chat.h"
|
#include "Chat.h"
|
||||||
@ -6,13 +9,16 @@
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "GameObject.h"
|
#include "GameObject.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
using namespace Acore::ChatCommands;
|
using namespace Acore::ChatCommands;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
// === CONFIG ===
|
// === CONFIG ===
|
||||||
static constexpr float TELEPORT_DISTANCE = 200.0f; // yards
|
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)
|
// Mining node entries (trim as needed)
|
||||||
static const std::vector<uint32> kVeinEntries = {
|
static const std::vector<uint32> kVeinEntries = {
|
||||||
@ -52,7 +58,7 @@ namespace
|
|||||||
if (player->IsInCombat())
|
if (player->IsInCombat())
|
||||||
{
|
{
|
||||||
ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat.");
|
ChatHandler(player->GetSession()).PSendSysMessage("You can't use this while in combat.");
|
||||||
return true;
|
return true; // handled
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GameObject* node = FindNearestVein(player, TELEPORT_DISTANCE))
|
if (GameObject* node = FindNearestVein(player, TELEPORT_DISTANCE))
|
||||||
@ -78,31 +84,44 @@ class telenode_commandscript : public CommandScript
|
|||||||
public:
|
public:
|
||||||
telenode_commandscript() : CommandScript("telenode_commandscript") { }
|
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
|
ChatCommandTable GetCommands() const override
|
||||||
{
|
{
|
||||||
static ChatCommandTable cmds =
|
static ChatCommandTable commandTable =
|
||||||
{
|
{
|
||||||
// .telenode (player-only; change SEC if you want)
|
// .telenode
|
||||||
{ "telenode",
|
{ "telenode",
|
||||||
SEC_PLAYER,
|
SEC_PLAYER, // security (adjust via DB if you want)
|
||||||
Console::No,
|
Console::No, // no console by default
|
||||||
// handler signature with no args
|
&HandleTeleNode, // function pointer (NOT a lambda)
|
||||||
[](ChatHandler* handler)
|
"" } // help text (optional)
|
||||||
{
|
|
||||||
if (auto* session = handler->GetSession())
|
|
||||||
return DoTeleNode(session->GetPlayer());
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
"" // 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
|
// Boilerplate-style exported symbol that your loader will call
|
||||||
void Addmod_telenodeScripts()
|
void AddSC_telenode_commandscript()
|
||||||
{
|
{
|
||||||
new telenode_commandscript();
|
new telenode_commandscript();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user