View difference between Paste ID: nHJRAhtq and JS9Hirha
SHOW: | | - or go back to the newest paste.
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") { }
12+
    uint32 Event_Timer;
13
14-
	uint32 Event_Timer;
14+
    custom_world_event() : WorldScript("custom_world_event")
15
    {
16-
	void OnStartup()
16+
        Event_Timer = 0;
17-
	{
17+
    }
18-
		Event_Timer = urand(MIN_INTERVAL, MAX_INTERVAL);
18+
19-
	}
19+
    void OnStartup()
20
    {
21-
	void OnUpdate(const uint32 diff)
21+
        Event_Timer = urand(MIN_INTERVAL, MAX_INTERVAL);
22-
	{
22+
    }
23-
		if (Event_Timer <= diff)
23+
24-
		{
24+
    void OnUpdate(const uint32 diff)
25-
			SessionMap Players = sWorld->GetAllSessions();
25+
    {
26-
			if (Players.empty())
26+
        if (Event_Timer <= diff)
27-
				return;
27+
        {
28
            SessionMap const& sessions = sWorld->GetAllSessions();
29-
			for (SessionMap::iterator itr = Players.find(urand(0, Players.size())); itr != Players.end(); ++itr)
29+
            if (sessions.empty())
30-
			{
30+
                return;
31-
				if (!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld())
31+
32-
					continue;
32+
            for (SessionMap::const_iterator itr = sessions.find(urand(0, sessions.size()-1)); itr != sessions.end(); ++itr)
33
            {
34-
				Player* player = itr->second->GetPlayer();
34+
                if (!itr->second || !itr->second->GetPlayer() || !itr->second->GetPlayer()->IsInWorld())
35-
				Map* playerMap = player->GetMap();
35+
                    continue;
36
37-
				if (!player->isDead() && !player->isInCombat() && !player->GetMotionMaster()->GetMotionSlotType(FLIGHT_MOTION_TYPE) && !playerMap->IsBattlegroundOrArena() && !playerMap->IsRaidOrHeroicDungeon() && !player->isAFK() && !player->isGameMaster())
37+
                Player* player = itr->second->GetPlayer();
38-
				{
38+
                Map* playerMap = player->GetMap();
39-
				    Creature* wrathion = player->SummonCreature(NPC_WRATHION, player->GetPositionX(), player->GetPositionY()+5.0f, player->GetPositionZ(), player->GetOrientation(), TEMPSUMMON_TIMED_DESPAWN, DESPAWN_TIMER_IN_MILISECONDS);
39+
40-
				    wrathion->AI()->DoCast(wrathion, SPELL_TELEPORT);
40+
                if (!player->isDead() && !player->isInCombat() && !player->GetMotionMaster()->GetMotionSlotType(FLIGHT_MOTION_TYPE) && !playerMap->IsBattlegroundOrArena() && !playerMap->IsRaidOrHeroicDungeon() && !player->isAFK() && !player->isGameMaster())
41-
				    wrathion->GetMotionMaster()->MoveFollow(player, 0.0f, 0.0f);
41+
                {
42-
				    std::ostringstream ss;
42+
                    if(Creature* wrathion = player->SummonCreature(NPC_WRATHION, player->GetPositionX(), player->GetPositionY()+5.0f, player->GetPositionZ()+1.0f, player->GetOrientation()+M_PI, TEMPSUMMON_TIMED_DESPAWN, DESPAWN_TIMER_IN_MILISECONDS))
43-
				    ss << "Greetings " << player->GetName() << " could you assist me for a moment please?";
43+
                    {
44-
				    wrathion->MonsterSay(ss.str().c_str(), LANG_UNIVERSAL, wrathion->GetGUID());
44+
                        wrathion->CastSpell(wrathion, SPELL_TELEPORT, true);
45-
				    Event_Timer = urand(MIN_INTERVAL, MAX_INTERVAL);
45+
                        wrathion->GetMotionMaster()->MoveFollow(player, 0.0f, 0.0f);
46-
				} else Event_Timer = 60000;
46+
                        std::ostringstream ss;
47-
			}
47+
                        ss << "Greetings " << player->GetName() << " could you assist me for a moment please?";
48-
		} else Event_Timer -= diff;
48+
                        wrathion->MonsterSay(ss.str().c_str(), LANG_UNIVERSAL, player->GetGUID());
49-
	}
49+
                    }
50
                    Event_Timer = urand(MIN_INTERVAL, MAX_INTERVAL);
51
                }
52
                else
53
                    Event_Timer = 60000;
54-
	new custom_world_event;
54+
                break; // stop looping
55
            }
56
        }
57
        else
58
            Event_Timer -= diff;
59
    }
60
};
61
62
void AddSC_custom_world_event()
63
{
64
    new custom_world_event;
65
}