From d0f10a12c0de2cf8ab43dac75e80223c55472b76 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Sun, 3 Dec 2023 02:57:41 +0100 Subject: [PATCH] feat(Scripts/Commands): introduce go creature name (#17910) * feat(Scripts/Commands): introduce go creature name * closes https://github.com/azerothcore/azerothcore-wotlk/issues/2315 * Since new command handler the old "go creature" dont take name as argument * Update cs_go.cpp * this could be null... so let's avoid stupid crashes * we only need the first result if there are multiple * Update cs_go.cpp * Update rev_1701381015172273800.sql --- .../rev_1701381015172273800.sql | 6 +++++ src/server/scripts/Commands/cs_go.cpp | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 data/sql/updates/pending_db_world/rev_1701381015172273800.sql diff --git a/data/sql/updates/pending_db_world/rev_1701381015172273800.sql b/data/sql/updates/pending_db_world/rev_1701381015172273800.sql new file mode 100644 index 000000000..02fed2416 --- /dev/null +++ b/data/sql/updates/pending_db_world/rev_1701381015172273800.sql @@ -0,0 +1,6 @@ +-- +DELETE FROM `command` WHERE `name`='go creature name'; +INSERT INTO `command` (`name`, `security`, `help`) VALUES +('go creature name', 1, 'Syntax: .go creature name #name\r\nTeleports you to the first spawn for the given creature name.\r\n*If* more than one creature is found, then you are teleported to the first that is found inside the database.'); + +UPDATE `command` SET `help` = 'Syntax: .go creature id #creature_entry\r\nTeleports you to the given creature entry.\r\n*If* more than one creature is found, then you are teleported to the first that is found inside the database.' WHERE `name` = 'go creature id'; diff --git a/src/server/scripts/Commands/cs_go.cpp b/src/server/scripts/Commands/cs_go.cpp index 4d0bc6ba0..a46bd901f 100644 --- a/src/server/scripts/Commands/cs_go.cpp +++ b/src/server/scripts/Commands/cs_go.cpp @@ -47,6 +47,7 @@ public: { { "creature", HandleGoCreatureSpawnIdCommand, SEC_MODERATOR, Console::No }, { "creature id", HandleGoCreatureCIdCommand, SEC_MODERATOR, Console::No }, + { "creature name", HandleGoCreatureNameCommand, SEC_MODERATOR, Console::No }, { "gameobject", HandleGoGameObjectSpawnIdCommand, SEC_MODERATOR, Console::No }, { "gameobject id", HandleGoGameObjectGOIdCommand, SEC_MODERATOR, Console::No }, { "graveyard", HandleGoGraveyardCommand, SEC_MODERATOR, Console::No }, @@ -117,6 +118,29 @@ public: return DoTeleport(handler, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, spawnpoint->mapid); } + static bool HandleGoCreatureNameCommand(ChatHandler* handler, Tail name) + { + if (!name.data()) + return false; + + QueryResult result = WorldDatabase.Query("SELECT entry FROM creature_template WHERE name = \"{}\" LIMIT 1" , name.data()); + if (!result) + { + handler->SendErrorMessage(LANG_COMMAND_GOCREATNOTFOUND); + return false; + } + + uint32 entry = result->Fetch()[0].Get(); + CreatureData const* spawnpoint = GetCreatureData(handler, entry); + if (!spawnpoint) + { + handler->SendErrorMessage(LANG_COMMAND_GOCREATNOTFOUND); + return false; + } + + return DoTeleport(handler, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, spawnpoint->mapid); + } + static bool HandleGoGameObjectSpawnIdCommand(ChatHandler* handler, uint32 spawnId) { GameObjectData const* spawnpoint = sObjectMgr->GetGameObjectData(spawnId);