Example #1
0
	void OnQuestStart(Player* pPlayer, QuestLogEntry* qLogEntry)
	{
		Creature *windwatcher = pPlayer->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(pPlayer->GetPositionX(), pPlayer->GetPositionY(), pPlayer->GetPositionZ(), 6176);
		if(!windwatcher) return;

		// questgiver will walk to the place where Cyclonian is spawned
		// only walk when we are at home
		if(windwatcher->CalcDistance(250.839996f, -1470.579956f, 55.4491f) > 1) return;
		{
			windwatcher->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "Follow me");
			sEAS.CreateCustomWaypointMap(windwatcher);
			sEAS.WaypointCreate(windwatcher, 269.29f, -1433.32f, 50.31f, 0.19f, 0, 0, 0);
			sEAS.WaypointCreate(windwatcher, 328.52f, -1442.03f, 40.5f, 5.65f, 0, 0, 0);
			sEAS.WaypointCreate(windwatcher, 333.31f, -1453.69f, 42.01f, 4.68f, 0, 0, 0);
			sEAS.EnableWaypoints(windwatcher);
			windwatcher->GetAIInterface()->setMoveType(11);
		}
		windwatcher->Despawn(15*60*1000, 0);

		// spawn cyclonian if not spawned already
		Creature *cyclonian = pPlayer->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(323.947f, -1483.68f, 43.1363f, 6239);
		if( cyclonian == NULL)
		{
			cyclonian = sEAS.SpawnCreature(pPlayer, 6239, 323.947f, -1483.68f, 43.1363f, 0.682991f);

			// if spawning cyclonian failed, we have to return.
			if(cyclonian == NULL)
				return;
		}

		// queue cyclonian for despawn
		cyclonian->Despawn(15*60*1000, 0);
	}
Creature *MapManagerScript::FindClosestLivingCreature( uint32 pEntry, float pX, float pY, float pZ, Creature* check )
{
    Creature *CurrentCreature = NULL, *Creturn = NULL;
    float closestDistance = 50000.0f, currentDistance;
    for ( uint32 i = 0; i != _manager->m_CreatureHighGuid; ++i )
    {
        currentDistance = 0.0f;
        CurrentCreature = _manager->m_CreatureStorage[i];
        if ( CurrentCreature != NULL && CurrentCreature != check)
        { 
            if ( CurrentCreature->GetEntry() == pEntry && CurrentCreature->isAlive())
            {
                currentDistance = CurrentCreature->CalcDistance(pX, pY, pZ);
                if(currentDistance <= closestDistance)
                {
                    closestDistance = currentDistance;
                    Creturn = CurrentCreature;
                }
            }
        }
    }

    return Creturn;
}