[Commands][Gameobject] No arg requirement for .gobject commands

It’s a pretty simple patch.

Normally, when you use .gobject delete or any other .gobject command, you need to supply a GUID.

This might not be an issue if you’re only working with a few gameobjects, but if you’re working with 5+, it can get pretty tedious.

I tried to keep this limited to just external scripts, but I ended up having to put a few things in the player class. /emoticons/default_sad.png

So, it adds a new command, .gobject select. When you use it, it stores the GUID of the selected gameobject for when you use the next .gobject command.

.gobject target still works fine, and you can still use GUIDs with the other .gobject commands.

[CODE]diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp

index 280aef3…3fe8827 100755

— a/src/server/game/Entities/Player/Player.cpp

+++ b/src/server/game/Entities/Player/Player.cpp

@@ -650,6 +650,8 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa

 m_curSelection = 0;

 m_lootGuid = 0;
  • m_selectedGobject = 0;

    m_comboTarget = 0;

    m_comboPoints = 0;

diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h

index a04494c…30a2446 100755

— a/src/server/game/Entities/Player/Player.h

+++ b/src/server/game/Entities/Player/Player.h

@@ -1531,6 +1531,10 @@ class Player : public Unit, public GridObject

     Player *GetSelectedPlayer() const;

     void SetSelection(const uint64 &guid) { m_curSelection = guid; SetUInt64Value(UNIT_FIELD_TARGET, guid); }
  •    uint32 m_selectedGobject;
    
  •    uint32 GetSelectedGobject() { return m_selectedGobject; }
    
  •    void SetSelectedGobject(uint32 gobId) { m_selectedGobject = gobId; }
    
     uint8 GetComboPoints() { return m_comboPoints; }

     const uint64& GetComboTarget() const { return m_comboTarget; }

diff --git a/src/server/scripts/Commands/cs_gobject.cpp b/src/server/scripts/Commands/cs_gobject.cpp

index aef5e85…c884d2a 100644

— a/src/server/scripts/Commands/cs_gobject.cpp

+++ b/src/server/scripts/Commands/cs_gobject.cpp

@@ -55,6 +55,7 @@ public:

         { "info",           SEC_GAMEMASTER,     false, &HandleGameObjectInfoCommand,      "", NULL },

         { "move",           SEC_GAMEMASTER,     false, &HandleGameObjectMoveCommand,      "", NULL },

         { "near",           SEC_GAMEMASTER,     false, &HandleGameObjectNearCommand,      "", NULL },
  •        { "select",         SEC_GAMEMASTER,     false, &HandleGameObjectSelectCommand, "", NULL },
    
           { "target",         SEC_GAMEMASTER,     false, &HandleGameObjectTargetCommand,    "", NULL },
    
           { "turn",           SEC_GAMEMASTER,     false, &HandleGameObjectTurnCommand,      "", NULL },
    
           { "add",            SEC_GAMEMASTER,     false, NULL,            "", gobjectAddCommandTable },
    

@@ -71,14 +72,12 @@ public:

 static bool HandleGameObjectActivateCommand(ChatHandler* handler, const char* args)

 {
  •    if (!*args)
    
  •        return false;
    
  •    // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
    
       char* cId = handler->extractKeyFromLink((char*)args,"Hgameobject");
    
  •    if (!cId)
    
  •    if (!cId && !args)
    
           return false;
    
  •    uint32 lowguid = atoi(cId);
    
  •   uint32 lowguid = (args) ? handler->GetSession()->GetPlayer()->GetSelectedGobject(): atoi(cId);
    
       if (!lowguid)
    
           return false;
    

@@ -334,10 +333,10 @@ public:

 {

     // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r

     char* cId = handler->extractKeyFromLink((char*)args,"Hgameobject");
  •    if (!cId)
    
  •    if (!cId && !args)
    
           return false;
    
  •    uint32 lowguid = atoi(cId);
    
  •   uint32 lowguid = (args) ? handler->GetSession()->GetPlayer()->GetSelectedGobject(): atoi(cId);
    
       if (!lowguid)
    
           return false;
    

@@ -380,12 +379,12 @@ public:

 //turn selected object

 static bool HandleGameObjectTurnCommand(ChatHandler* handler, const char* args)

 {
  •    // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
    
  •    // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
    
       char* cId = handler->extractKeyFromLink((char*)args,"Hgameobject");
    
  •    if (!cId)
    
  •    if (!cId && !args)
    
           return false;
    
  •    uint32 lowguid = atoi(cId);
    
  •   uint32 lowguid = (args) ? handler->GetSession()->GetPlayer()->GetSelectedGobject(): atoi(cId);
    
       if (!lowguid)
    
           return false;
    

@@ -433,10 +432,10 @@ public:

 {

     // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r

     char* cId = handler->extractKeyFromLink((char*)args,"Hgameobject");
  •    if (!cId)
    
  •    if (!cId && !args)
    
           return false;
    
  •    uint32 lowguid = atoi(cId);
    
  •   uint32 lowguid = (args) ? handler->GetSession()->GetPlayer()->GetSelectedGobject(): atoi(cId);
    
       if (!lowguid)
    
           return false;
    

@@ -498,10 +497,10 @@ public:

 {

     // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r

     char* cId = handler->extractKeyFromLink((char*)args,"Hgameobject");
  •    if (!cId)
    
  •    if (!cId && !args)
    
           return false;
    
  •    uint32 lowguid = atoi(cId);
    
  •   uint32 lowguid = (args) ? handler->GetSession()->GetPlayer()->GetSelectedGobject(): atoi(cId);
    
       if (!lowguid)
    
           return false;
    

@@ -610,14 +609,44 @@ public:

     return true;

 }
  • static bool HandleGameObjectSelectCommand(ChatHandler* handler, const char* args)

  • {

  •    uint32 entry = 0;
    
  •    std::string name;
    
  •    uint32 guid = 0;
    
  •    WorldObject* obj = handler->getSelectedObject();
    
  •    if (!*args)
    
  •    {
    
  •        if (obj)
    
  •            entry = obj->GetEntry();
    
  •        else
    
  •            entry = atoi((char*)args);
    
  •    }
    
  •    GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(entry);
    
  •    if (!goinfo)
    
  •        return false;
    
  •    name = goinfo->name;
    
  •    guid = obj->ToGameObject()->GetGUIDLow();
    
  •   handler->PSendSysMessage("Selected GameObject [ %s ](ID: %u) which is %.3f meters away from you.", name.c_str(), entry, handler->GetSession()->GetPlayer()->GetDistance(obj));
    
  •    handler->GetSession()->GetPlayer()->SetSelectedGobject(guid);
    
  •    return true;
    
  • }

 static bool HandleGameObjectSetStateCommand(ChatHandler* handler, const char* args)

 {

     // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
  •    char* cId = handler->extractKeyFromLink((char*)args, "Hgameobject");
    
  •    if (!cId)
    
  •    char* cId = handler->extractKeyFromLink((char*)args,"Hgameobject");
    
  •    if (!cId && !args)
    
           return false;
    
  •    uint32 lowguid = atoi(cId);
    
  •   uint32 lowguid = (args) ? handler->GetSession()->GetPlayer()->GetSelectedGobject(): atoi(cId);
    
       if (!lowguid)
    
           return false;
    

[/CODE]

This could be posted as a patch on the issues tracker, no reason it can’t go to the repo, as far as I see… or, as a pull request.

http://www.trinitycore.org/t/trinitycore/ticket/1301

I wasn’t sure if we were allowed to post command edits that contained code-changes outside of external scripts, but I went ahead and posted it because the internal changes were minimal.

Well, it’s out there now, we’ll see if anything comes of it. /emoticons/default_smile.png

Well, there is a difference between hacking core code for something that can be done in a script, and making some supporting changes in the core code to make the script code work, if necessary, in my mind, anyway. similar to adding new hooks so something can be scripted using the hooks.

This is the exact same use of TrinityAdmin, great work mate /emoticons/default_smile.png

Thanks. /emoticons/default_smile.png

I plan on fleshing out the command system a bit more or at least finishing the transition to external scripts.

/root/TrinityCore/src/server/scripts/Commands/cs_gobject.cpp: In static member function âstatic bool gobject_commandscript::HandleGameObjectSelectCommand(ChatHandler*, const char*)â:

/root/TrinityCore/src/server/scripts/Commands/cs_gobject.cpp:626: error: âGameObjectInfoâ was not declared in this scope

/root/TrinityCore/src/server/scripts/Commands/cs_gobject.cpp:626: error: expected â;â before âconstâ

/root/TrinityCore/src/server/scripts/Commands/cs_gobject.cpp:628: error: âgoinfoâ was not declared in this scope

/root/TrinityCore/src/server/scripts/Commands/cs_gobject.cpp:631: error: âgoinfoâ was not declared in this scope

make[2]: *** [src/server/scripts/CMakeFiles/scripts.dir/Commands/cs_gobject.cpp.o] Error 1

to fix those errors simply replace the following lines:

GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(entry);

with

GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(entry);

on line 626

So how do I apply this patch?

Copy&Paste

i vote to get this implemented into the repo /emoticons/default_smile.png

That would be pretty neat. /emoticons/default_smile.png

Unfortunately, I don’t think the devs look in this section very often.

bump add this to the repo /emoticons/default_tongue.png

If you want it added submit a pull request on GitHub. They’re pretty receptive of enhancements/fixes as long as it follows the style guidelines and doesn’t break anything / implement a bad hack at core functionality; so an extra GM command like this seems like it would be perfect for inclusion.