Guest User

Untitled

a guest
May 9th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2.  
  3. #define MIN_INTERVAL 18000 // 30 minutes
  4. #define MAX_INTERVAL 72000 // 2 hours
  5. #define DESPAWN_TIMER_IN_MILISECONDS 60000 // 1 minutes
  6. #define NPC_WRATHION 190050 // Task Master
  7. #define SPELL_TELEPORT 33056 // Visual
  8.  
  9. class custom_world_event : public WorldScript
  10. {
  11. public:
  12.     custom_world_event() : WorldScript("custom_world_event") { }
  13.  
  14.     uint32 Event_Timer;
  15.  
  16.     void OnStartup()
  17.     {
  18.         Event_Timer = urand(MIN_INTERVAL, MAX_INTERVAL);
  19.     }
  20.  
  21.     void OnUpdate(const uint32 diff)
  22.     {
  23.         if (Event_Timer <= diff)
  24.         {
  25.             SessionMap Players = sWorld->GetAllSessions();
  26.             if (Players.empty())
  27.                 return;
  28.  
  29.             for (SessionMap::iterator itr = Players.find(urand(0, Players.size())); itr != Players.end(); ++itr)
  30.             {
  31.                 if (!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld())
  32.                     continue;
  33.  
  34.                 Player* player = itr->second->GetPlayer();
  35.                 Map* playerMap = player->GetMap();
  36.  
  37.                 if (!player->isDead() && !player->isInCombat() && !player->GetMotionMaster()->GetMotionSlotType(FLIGHT_MOTION_TYPE) && !playerMap->IsBattlegroundOrArena() && !playerMap->IsRaidOrHeroicDungeon() && !player->isAFK() && !player->isGameMaster())
  38.                 {
  39.                     Creature* wrathion = player->SummonCreature(NPC_WRATHION, player->GetPositionX(), player->GetPositionY()+5.0f, player->GetPositionZ(), player->GetOrientation(), TEMPSUMMON_TIMED_DESPAWN, DESPAWN_TIMER_IN_MILISECONDS);
  40.                     wrathion->AI()->DoCast(wrathion, SPELL_TELEPORT);
  41.                     wrathion->GetMotionMaster()->MoveFollow(player, 0.0f, 0.0f);
  42.                     std::ostringstream ss;
  43.                     ss << "Greetings " << player->GetName() << " could you assist me for a moment please?";
  44.                     wrathion->MonsterSay(ss.str().c_str(), LANG_UNIVERSAL, wrathion->GetGUID());
  45.                     Event_Timer = urand(MIN_INTERVAL, MAX_INTERVAL);
  46.                 } else Event_Timer = 60000;
  47.             }
  48.         } else Event_Timer -= diff;
  49.     }
  50. };
  51.  
  52. void AddSC_custom_world_event()
  53. {
  54.     new custom_world_event;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment