bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { uint64 guid = m_session->GetPlayer()->GetSelection(); if (guid == 0) { SystemMessage(m_session, "No selection."); return true; } Creature* unit = NULL; if(m_session->GetPlayer()->GetMapMgr()->GetVehicle(GET_LOWGUID_PART(guid))) unit = m_session->GetPlayer()->GetMapMgr()->GetVehicle(GET_LOWGUID_PART(guid)); else unit = m_session->GetPlayer()->GetMapMgr()->GetCreature(GET_LOWGUID_PART(guid)); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } if( unit->m_spawn != NULL && !m_session->CanUseCommand('z') ) { SystemMessage(m_session, "You do not have permission to do that. Please contact higher staff for removing of saved spawns."); return true; } if(unit->GetAIInterface()) unit->GetAIInterface()->StopMovement(10000); if(unit->IsVehicle()) { Vehicle* veh = TO_VEHICLE(unit); for(int i = 0; i < 8; i++) { if(!veh->GetPassenger(i)) continue; // Remove any players if(veh->GetPassenger(i)->IsPlayer()) veh->RemovePassenger(veh->GetPassenger(i)); else // Remove any units. veh->GetPassenger(i)->RemoveFromWorld(true); } } sGMLog.writefromsession(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->m_spawn ? unit->m_spawn : 0, unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); MapMgr* unitMgr = unit->GetMapMgr(); unit->DeleteFromDB(); if(!unit->IsInWorld()) return true; if(unit->m_spawn) { uint32 cellx=float2int32(((_maxX-unit->m_spawn->x)/_cellSize)); uint32 celly=float2int32(((_maxY-unit->m_spawn->y)/_cellSize)); if(cellx <= _sizeX && celly <= _sizeY && unitMgr != NULL) { CellSpawns * c = unitMgr->GetBaseMap()->GetSpawnsList(cellx, celly); if( c != NULL ) { CreatureSpawnList::iterator itr, itr2; for(itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end();) { itr2 = itr; ++itr; if((*itr2) == unit->m_spawn) { c->CreatureSpawns.erase(itr2); delete unit->m_spawn; break; } } } } } unit->RemoveFromWorld(false,true); if(unit->IsVehicle()) TO_VEHICLE(unit)->Destructor(); else unit->Destructor(); return true; }
bool ChatHandler::HandleDeleteCommand(const char* args, WorldSession *m_session) { Creature* unit = getSelectedCreature(m_session, false); if(!unit) { SystemMessage(m_session, "You should select a creature."); return true; } else if(unit->IsPet() || unit->IsSummon()) { SystemMessage(m_session, "You can't delete playerpets."); return true; } if( unit->m_spawn != NULL && !m_session->CanUseCommand('z') ) { SystemMessage(m_session, "You do not have permission to do that. Please contact higher staff for removing of saved spawns."); return true; } if(unit->IsVehicle()) { Vehicle* veh = TO_VEHICLE(unit); for(int i = 0; i < 8; i++) { if(!veh->GetPassenger(i)) continue; // Remove any players if(veh->GetPassenger(i)->IsPlayer()) veh->RemovePassenger(veh->GetPassenger(i)); else // Remove any units. veh->GetPassenger(i)->RemoveFromWorld(true); } } sWorld.LogGM(m_session, "used npc delete, sqlid %u, creature %s, pos %f %f %f", unit->m_spawn ? unit->m_spawn->id : 0, unit->GetCreatureInfo() ? unit->GetCreatureInfo()->Name : "wtfbbqhax", unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ()); BlueSystemMessage(m_session, "Deleted creature ID %u", unit->spawnid); unit->DeleteFromDB(); if(!unit->IsInWorld()) return true; MapMgr* unitMgr = unit->GetMapMgr(); if(unit->m_spawn) { uint32 cellx = unitMgr->GetPosX(unit->m_spawn->x); uint32 celly = unitMgr->GetPosX(unit->m_spawn->y); if(cellx <= _sizeX && celly <= _sizeY ) { CellSpawns *c = unitMgr->GetBaseMap()->GetSpawnsList(cellx, celly); if( c != NULL ) { CreatureSpawnList::iterator itr, itr2; for(itr = c->CreatureSpawns.begin(); itr != c->CreatureSpawns.end();) { itr2 = itr++; if((*itr2) == unit->m_spawn) { c->CreatureSpawns.erase(itr2); delete unit->m_spawn; break; } } } } } unit->RemoveFromWorld(false, true); if(unit->IsVehicle()) TO_VEHICLE(unit)->Destruct(); else unit->Destruct(); m_session->GetPlayer()->SetSelection(NULL); return true; }