feat(Core/Commands): command to teleport character to npc (#8887)
This commit is contained in:
committed by
GitHub
parent
5df73f6680
commit
c21d83b30a
@@ -0,0 +1,10 @@
|
|||||||
|
INSERT INTO `version_db_world` (`sql_rev`) VALUES ('1635830311358655196');
|
||||||
|
|
||||||
|
DELETE FROM `command` WHERE `name` IN ('teleport name npc id','teleport name npc guid','teleport name npc name');
|
||||||
|
INSERT INTO `command` (`name`,`security`,`help`) VALUES
|
||||||
|
('teleport name npc id',2,'Syntax: .teleport name id #playername #creatureId
|
||||||
|
Teleport the given character to first found creature with id #creatureId. Character can be offline.'),
|
||||||
|
('teleport name npc guid',2,'Syntax: .teleport name id #playername #creatureSpawnId
|
||||||
|
Teleport the given character to creature with spawn id #creatureSpawnId. Character can be offline.'),
|
||||||
|
('teleport name npc name',2,'Syntax: .teleport name id #playername #creatureName
|
||||||
|
Teleport the given character to first found creature with name (must match exactly) #creatureName. Character can be offline.');
|
||||||
@@ -23,6 +23,8 @@ Category: commandscripts
|
|||||||
EndScriptData */
|
EndScriptData */
|
||||||
|
|
||||||
#include "Chat.h"
|
#include "Chat.h"
|
||||||
|
#include "DatabaseEnv.h"
|
||||||
|
#include "DBCStores.h"
|
||||||
#include "Group.h"
|
#include "Group.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
#include "MapMgr.h"
|
#include "MapMgr.h"
|
||||||
@@ -39,13 +41,24 @@ public:
|
|||||||
|
|
||||||
ChatCommandTable GetCommands() const override
|
ChatCommandTable GetCommands() const override
|
||||||
{
|
{
|
||||||
|
static ChatCommandTable teleNameNpcCommandTable =
|
||||||
|
{
|
||||||
|
{ "id", HandleTeleNameNpcIdCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
|
{ "guid", HandleTeleNameNpcSpawnIdCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
|
{ "name", HandleTeleNameNpcNameCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
|
};
|
||||||
|
static ChatCommandTable teleNameCommandTable =
|
||||||
|
{
|
||||||
|
{ "npc", teleNameNpcCommandTable },
|
||||||
|
{ "", HandleTeleNameCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
|
};
|
||||||
static ChatCommandTable teleCommandTable =
|
static ChatCommandTable teleCommandTable =
|
||||||
{
|
{
|
||||||
{ "add", HandleTeleAddCommand, SEC_ADMINISTRATOR, Console::No },
|
{ "add", HandleTeleAddCommand, SEC_ADMINISTRATOR, Console::No },
|
||||||
{ "del", HandleTeleDelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
{ "del", HandleTeleDelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "name", HandleTeleNameCommand, SEC_GAMEMASTER, Console::Yes },
|
{ "name", teleNameCommandTable },
|
||||||
{ "group", HandleTeleGroupCommand, SEC_GAMEMASTER, Console::No },
|
{ "group", HandleTeleGroupCommand, SEC_GAMEMASTER, Console::No },
|
||||||
{ "", HandleTeleCommand, SEC_GAMEMASTER, Console::No }
|
{ "", HandleTeleCommand, SEC_GAMEMASTER, Console::No }
|
||||||
};
|
};
|
||||||
static ChatCommandTable commandTable =
|
static ChatCommandTable commandTable =
|
||||||
{
|
{
|
||||||
@@ -97,7 +110,6 @@ public:
|
|||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name = tele->name;
|
std::string name = tele->name;
|
||||||
sObjectMgr->DeleteGameTele(name);
|
sObjectMgr->DeleteGameTele(name);
|
||||||
handler->SendSysMessage(LANG_COMMAND_TP_DELETED);
|
handler->SendSysMessage(LANG_COMMAND_TP_DELETED);
|
||||||
@@ -310,6 +322,70 @@ public:
|
|||||||
player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
|
player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool HandleTeleNameNpcIdCommand(ChatHandler* handler, PlayerIdentifier player, Variant<Hyperlink<creature_entry>, uint32> creatureId)
|
||||||
|
{
|
||||||
|
CreatureData const* spawnpoint = nullptr;
|
||||||
|
for (auto const& pair : sObjectMgr->GetAllCreatureData())
|
||||||
|
{
|
||||||
|
if (pair.second.id != *creatureId)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!spawnpoint)
|
||||||
|
spawnpoint = &pair.second;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!spawnpoint)
|
||||||
|
{
|
||||||
|
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
|
||||||
|
handler->SetSentErrorMessage(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatureTemplate const* creatureTemplate = ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(*creatureId));
|
||||||
|
|
||||||
|
return DoNameTeleport(handler, player, spawnpoint->mapid, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, creatureTemplate->Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool HandleTeleNameNpcSpawnIdCommand(ChatHandler* handler, PlayerIdentifier player, Variant<Hyperlink<creature>, ObjectGuid::LowType> spawnId)
|
||||||
|
{
|
||||||
|
CreatureData const* spawnpoint = sObjectMgr->GetCreatureData(spawnId);
|
||||||
|
if (!spawnpoint)
|
||||||
|
{
|
||||||
|
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
|
||||||
|
handler->SetSentErrorMessage(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatureTemplate const* creatureTemplate = ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(spawnpoint->id));
|
||||||
|
|
||||||
|
return DoNameTeleport(handler, player, spawnpoint->mapid, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, creatureTemplate->Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool HandleTeleNameNpcNameCommand(ChatHandler* handler, PlayerIdentifier player, Tail name)
|
||||||
|
{
|
||||||
|
std::string normalizedName(name);
|
||||||
|
WorldDatabase.EscapeString(normalizedName);
|
||||||
|
|
||||||
|
QueryResult result = WorldDatabase.PQuery("SELECT c.position_x, c.position_y, c.position_z, c.orientation, c.map, ct.name FROM creature c INNER JOIN creature_template ct ON c.id = ct.entry WHERE ct.name LIKE '%s'", normalizedName.c_str());
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
|
||||||
|
handler->SetSentErrorMessage(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result->GetRowCount() > 1)
|
||||||
|
handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE);
|
||||||
|
|
||||||
|
Field* fields = result->Fetch();
|
||||||
|
return DoNameTeleport(handler, player, fields[4].GetUInt16(), { fields[0].GetFloat(), fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat() }, fields[5].GetString());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddSC_tele_commandscript()
|
void AddSC_tele_commandscript()
|
||||||
|
|||||||
Reference in New Issue
Block a user