Jump to content

two command usefull


Enturion

Recommended Posts

adding this two permit to get coord directly from wowhead and add GObj without GO in place ;)

Level2.cpp


//spawn go ZoneXY
bool ChatHandler::HandleGameObjectAddZoneXYCommand(const char* args)
{
	    if (!*args)
        return false;
 
    Player* _player = m_session->GetPlayer();
		char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
    char* px = strtok(NULL, " ");
    char* py = strtok(NULL, " ");
    char* tail = strtok(NULL,"");

    if (!cId)
        return false;

    uint32 id = atol(cId);
    if (!id)
        return false;

    char* spawntimeSecs = strtok(NULL, " ");

    const GameObjectInfo *gInfo = sObjectMgr->GetGameObjectInfo(id);

    if (!gInfo)
    {
        PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
        SetSentErrorMessage(true);
        return false;
    }

    if (gInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId))
    {
        // report to DB errors log as in loading case
        sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.",id, gInfo->type, gInfo->displayId);
        PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA,id);
        SetSentErrorMessage(true);
        return false;
    }

    char* cAreaId = extractKeyFromLink(tail,"Harea");       // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r

    if (!px || !py)
        return false;
		Player *chr = m_session->GetPlayer();
    float x = (float)atof(px);
    float y = (float)atof(py);

    // prevent accept wrong numeric args
    if ((x == 0.0f && *px != '0') || (y == 0.0f && *py != '0'))
        return false;

    uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();

    AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);

    if (x < 0 || x > 100 || y < 0 || y > 100 || !areaEntry)
    {
        PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
        SetSentErrorMessage(true);
        return false;
    }

    // update to parent zone if exist (client map show only zones without parents)
    AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;

    Map const *mapT = sMapMgr->CreateBaseMap(zoneEntry->mapid);

    if (mapT->Instanceable())
    {
        PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[GetSessionDbcLocale()],mapT->GetId(),mapT->GetMapName());
        SetSentErrorMessage(true);
        return false;
    }

    Zone2MapCoordinates(x,y,zoneEntry->ID);

    if (!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
    {
        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
        SetSentErrorMessage(true);
        return false;
    }
    
    Map *map = (Map *)mapT;
    
    float z = std::max(mapT->GetHeight(x, y, MAX_HEIGHT), mapT->GetWaterLevel(x, y));
    float o = float(chr->GetOrientation());

    GameObject* pGameObj = new GameObject;
    uint32 db_lowGUID = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);

    if (!pGameObj->Create(db_lowGUID, gInfo->id, map, chr->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
    {
        delete pGameObj;
        return false;
    }

    if (spawntimeSecs)
    {
        uint32 value = atoi((char*)spawntimeSecs);
        pGameObj->SetRespawnTime(value);
        //sLog.outDebug("*** spawntimeSecs: %d", value);
    }

    // fill the gameobject data and save to the db
    pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()),chr->GetPhaseMaskForSpawn());

    // this will generate a new guid if the object is in an instance
    if (!pGameObj->LoadFromDB(db_lowGUID, map))
    {
        delete pGameObj;
        return false;
    }

    sLog->outDebug(GetTrinityString(LANG_GAMEOBJECT_CURRENT), gInfo->name, db_lowGUID, x, y, z, o);

    map->Add(pGameObj);

    // TODO: is it really necessary to add both the real and DB table guid here ?
    sObjectMgr->AddGameobjectToGrid(db_lowGUID, sObjectMgr->GetGOData(db_lowGUID));

    PSendSysMessage(LANG_GAMEOBJECT_ADD,id,gInfo->name,db_lowGUID,x,y,z);
    return true;

}

//spawn goXY
bool ChatHandler::HandleGameObjectAddXYCommand(const char* args)
{

    if (!*args)
        return false;

    // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
    char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
    char* px = strtok(NULL, " ");
    char* py = strtok(NULL, " ");
    char* pmapid = strtok(NULL, " ");

    if (!px || !py)
        return false;

    if (!cId)
        return false;

    uint32 id = atol(cId);
    if (!id)
        return false;

		uint32 mapid = (uint32)atoi(pmapid);
		if (!mapid) 
			return false;

    char* spawntimeSecs = strtok(NULL, " ");

    const GameObjectInfo *gInfo = sObjectMgr->GetGameObjectInfo(id);

    if (!gInfo)
    {
        PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
        SetSentErrorMessage(true);
        return false;
    }

    if (gInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(gInfo->displayId))
    {
        // report to DB errors log as in loading case
        sLog->outErrorDb("Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.",id, gInfo->type, gInfo->displayId);
        PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA,id);
        SetSentErrorMessage(true);
        return false;
    }

    Player *chr = m_session->GetPlayer();
    //float x = float(chr->GetPositionX());
    //float y = float(chr->GetPositionY());
    // float z = float(chr->GetPositionZ());
    //Map *map = chr->GetMap();
    float x = (float)atof(px);
    float y = (float)atof(py);

	  if (!MapManager::IsValidMapCoord(mapid,x,y))
    {
        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
        SetSentErrorMessage(true);
        return false;
    }
    Map const *mapT = sMapMgr->CreateBaseMap(mapid);
    Map *map = (Map *)mapT;
    
    float z = std::max(mapT->GetHeight(x, y, MAX_HEIGHT), mapT->GetWaterLevel(x, y));
    float o = float(chr->GetOrientation());

    GameObject* pGameObj = new GameObject;
    uint32 db_lowGUID = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);

    if (!pGameObj->Create(db_lowGUID, gInfo->id, map, chr->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
    {
        delete pGameObj;
        return false;
    }

    if (spawntimeSecs)
    {
        uint32 value = atoi((char*)spawntimeSecs);
        pGameObj->SetRespawnTime(value);
        //sLog.outDebug("*** spawntimeSecs: %d", value);
    }

    // fill the gameobject data and save to the db
    pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()),chr->GetPhaseMaskForSpawn());

    // this will generate a new guid if the object is in an instance
    if (!pGameObj->LoadFromDB(db_lowGUID, map))
    {
        delete pGameObj;
        return false;
    }

    sLog->outDebug(GetTrinityString(LANG_GAMEOBJECT_CURRENT), gInfo->name, db_lowGUID, x, y, z, o);

    map->Add(pGameObj);

    // TODO: is it really necessary to add both the real and DB table guid here ?
    sObjectMgr->AddGameobjectToGrid(db_lowGUID, sObjectMgr->GetGOData(db_lowGUID));

    PSendSysMessage(LANG_GAMEOBJECT_ADD,id,gInfo->name,db_lowGUID,x,y,z);
    return true;
}

Chat.cpp

        { "addXY",          SEC_GAMEMASTER,     false, &ChatHandler::HandleGameObjectAddXYCommand,     "", NULL },
        { "addzoneXY",      SEC_GAMEMASTER,     false, &ChatHandler::HandleGameObjectAddZoneXYCommand,  "", NULL },

Chat.h

        bool HandleGameObjectAddXYCommand(const char* args);
        bool HandleGameObjectAddZoneXYCommand(const char* args); 

syntax command :

.gob addXY ID x y mapID

.gob zoneXY ID zonex zoney zoneID

Link to comment
Share on other sites

How is this useful? I mean, I understand that you can add objects without having to teleport there first, but that's just sloppy because any good programmer/database manager would want to verify the correct location by seeing it. Otherwise, you're just being lazy and possibly adding objects to the wrong areas...

Link to comment
Share on other sites

you wrong ... cause a good db programmer should get the z position only from sniffer or parser instead with this command the z-position it's automated and you can get from wowhead the gobj like erbs minerals and more with a simple macro ... try yourself ;) !!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.