T端单机定时间随机召唤生物的脚本
下面是以个T端335版本WOTLK版本的随机召唤生物,并公告的脚本。。 注意:你需要定义好比较好的时间设置,否则容易当机。最好多测试一下 #include "ScriptPCH.h" #define MIN_INTERVAL_TIMER 900000 // 15 minutes, in miliseconds.... 1 second = 1000 miliseconds #define MAX_INTERVAL_TIMER 1800000 // 30 minutes #define RANDOM_NPC_ENTRY 00000 #define RANDOM_ITEM_REWARD_ENTRY 10000 // edit all this shit ^ class Random_Appearance : public WorldScript { public: Random_Appearance() : WorldScript("Random_Appearance") {} uint32 Timer; void DoRandomShit() { SessionMap Players = sWorld->GetAllSessions(); if(Players.empty()) return; SessionMap::iterator itr = Players.find(urand(0, Players.size())); Player* player = itr->second->GetPlayer(); Position *pos; player->GetPosition(pos); pos->m_positionX -= 3; pos->m_positionY -= 3; Creature* Summoned = player->SummonCreature(RANDOM_NPC_ENTRY, *pos, TEMPSUMMON_MANUAL_DESPAWN, 5000); const ItemTemplate* rewardedItem = sObjectMgr->GetItemTemplate(RANDOM_ITEM_REWARD_ENTRY); std::ostringstream ss; ss << "Congratulations, you have been randomly gifted with "; ss << rewardedItem->Name1; ss << " !"; Summoned->MonsterSay(ss.str().c_str(), LANG_UNIVERSAL, player->GetGUID()); player->AddItem(RANDOM_ITEM_REWARD_ENTRY, 1); Timer = urand(MIN_INTERVAL_TIMER, MAX_INTERVAL_TIMER); } void OnStartup() { Timer = urand(MIN_INTERVAL_TIMER, MAX_INTERVAL_TIMER); } void OnUpdate(uint32 diff) { if(diff > Timer) DoRandomShit(); else Timer -= diff; } }; void AddSC_Random_Appearance() { new Random_Appearance(); }