rendered paste bodybool ChatHandler::HandleCreatureSpawnCommand(const char *args, WorldSession *m_session)
{
uint32 entry = atol(args);
if(entry == 0)
return false;
CreatureProto * proto = CreatureProtoStorage.LookupEntry(entry);
CreatureInfo * info = CreatureNameStorage.LookupEntry(entry);
if(proto == 0 || info == 0)
{
RedSystemMessage(m_session, "Invalid entry id.");
return true;
}
CreatureSpawn * sp = new CreatureSpawn;
sp->displayid = info->DisplayID;
sp->entry = entry;
sp->form = 0;
sp->id = objmgr.GenerateCreatureSpawnID();
sp->movetype = 0;
sp->x = m_session->GetPlayer()->GetPositionX();
sp->y = m_session->GetPlayer()->GetPositionY();
sp->z = m_session->GetPlayer()->GetPositionZ();
sp->o = m_session->GetPlayer()->GetOrientation();
sp->emote_state =0;
sp->flags = 0;
sp->factionid = proto->Faction;
sp->bytes=0;
sp->bytes2=0;
sp->respawnNpcLink = 0;
Creature * p = m_session->GetPlayer()->GetMapMgr()->CreateCreature();
ASSERT(p);
p->Load(sp, NULL, NULL);
p->PushToWorld(m_session->GetPlayer()->GetMapMgr());
uint32 x = m_session->GetPlayer()->GetMapMgr()->GetPosX(m_session->GetPlayer()->GetPositionX());
uint32 y = m_session->GetPlayer()->GetMapMgr()->GetPosY(m_session->GetPlayer()->GetPositionY());
// Add spawn to map
m_session->GetPlayer()->GetMapMgr()->GetBaseMap()->GetSpawnsListAndCreate(
x,
y)->CreatureSpawns.insert(sp);
BlueSystemMessage(m_session, "Spawned a creature `%s` with entry %u at %f %f %f on map %u", info->Name,
entry, sp->x, sp->y, sp->z, m_session->GetPlayer()->GetMapId());
// Save it to the database.
p->SaveToDB();
return true;
}