Skip to content

Instantly share code, notes, and snippets.

@Rochet2
Last active August 29, 2015 13:56
Show Gist options
  • Save Rochet2/8791005 to your computer and use it in GitHub Desktop.
Save Rochet2/8791005 to your computer and use it in GitHub Desktop.
TrinityCore | Enables you to use .gob t to target a gameobject and then use commands like .gob de without providing GUID Tested on https://github.com/TrinityCore/TrinityCore/commit/747184a7c0dc200b9c2c8607a3e1dd990161278e
diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp
index d90fd6f..28bee74 100644
--- a/src/server/game/Chat/Chat.cpp
+++ b/src/server/game/Chat/Chat.cpp
@@ -782,18 +782,31 @@ Creature* ChatHandler::getSelectedCreature()
return ObjectAccessor::GetCreatureOrPetOrVehicle(*m_session->GetPlayer(), m_session->GetPlayer()->GetTarget());
}
+// Returns selected game object (selected with .gob t) if exists and if gameobject ID is searched for
+static char* GetSelectedGameObject(ChatHandler* handler, char const* linkType)
+{
+ if (!handler || !linkType)
+ return NULL;
+ if (strcmp(linkType, "Hgameobject"))
+ return NULL;
+ Player* player;
+ if (!handler->GetSession() || !(player = handler->GetSession()->GetPlayer()))
+ return NULL;
+ return player->m_SelectedGameObject;
+}
+
char* ChatHandler::extractKeyFromLink(char* text, char const* linkType, char** something1)
{
// skip empty
if (!text)
- return NULL;
+ return GetSelectedGameObject(this, linkType);
// skip spaces
while (*text == ' '||*text == '\t'||*text == '\b')
++text;
if (!*text)
- return NULL;
+ return GetSelectedGameObject(this, linkType);
// return non link case
if (text[0] != '|')
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 9ee7bc4..96c8bc4 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -897,6 +897,8 @@ Player::Player(WorldSession* session): Unit(true)
_activeCheats = CHEAT_NONE;
m_achievementMgr = new AchievementMgr(this);
m_reputationMgr = new ReputationMgr(this);
+
+ sprintf(m_SelectedGameObject, "%u", 0);
}
Player::~Player()
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 1f5f9fe..1256507 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -2296,6 +2296,8 @@ class Player : public Unit, public GridObject<Player>
std::string GetMapAreaAndZoneString();
std::string GetCoordsMapAreaAndZoneString();
+ char m_SelectedGameObject[12]; // should be able to fit uint32 and int32
+
protected:
// Gamemaster whisper whitelist
WhisperListContainer WhisperList;
diff --git a/src/server/scripts/Commands/cs_go.cpp b/src/server/scripts/Commands/cs_go.cpp
index fecb4ed..22666a5 100644
--- a/src/server/scripts/Commands/cs_go.cpp
+++ b/src/server/scripts/Commands/cs_go.cpp
@@ -260,9 +260,6 @@ public:
//teleport to gameobject
static bool HandleGoObjectCommand(ChatHandler* handler, char const* args)
{
- if (!*args)
- return false;
-
Player* player = handler->GetSession()->GetPlayer();
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
diff --git a/src/server/scripts/Commands/cs_gobject.cpp b/src/server/scripts/Commands/cs_gobject.cpp
index 423a47e..794fc8e 100644
--- a/src/server/scripts/Commands/cs_gobject.cpp
+++ b/src/server/scripts/Commands/cs_gobject.cpp
@@ -74,9 +74,6 @@ public:
static bool HandleGameObjectActivateCommand(ChatHandler* handler, char const* args)
{
- if (!*args)
- return false;
-
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
@@ -328,6 +325,8 @@ public:
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
}
+
+ sprintf(handler->GetSession()->GetPlayer()->m_SelectedGameObject, "%u", guidLow);
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment