View difference between Paste ID: xCp3Fvxa and FqRRFfjj
SHOW: | | - or go back to the newest paste.
1-
--[[
1+
#include "ScriptPCH.h"
2-
	Script made by Blyitgen @ AC-Web.org
2+
3
/*
4-
]]
4+
	Script made by Blyitgen
5
    Script converted to TC C++ by Rochet2
6-
-- Variables
6+
    @ AC-Web.org
7-
local NPC = 78000  -- NPC entry for gossip
7+
8
*/
9-
local m1,x1,y1,z1 = 1.1, 1.2, 1.3, 1.4 -- Location for Player 1
9+
10-
local m2,x2,y2,z2 = 1.1, 1.2, 1.3, 1.4 -- Location for Player 2
10+
namespace
11
{
12-
local am,ax,ay,az = 1.1, 1.2, 1.3, 1.4 -- Location after arena for alliance
12+
#define REWARD  125 // Reward (in honor) for the winner
13-
local hm,hx,hy,hz = 1.1, 1.2, 1.3, 1.4 -- Location after arena for horde
13+
    
14
    // WorldLocation(map, x, y, z, o)
15-
local reward = 125                     -- Reward (in honor) for the winner
15+
    // Start locations
16
    static const WorldLocation startLoc1 = WorldLocation(1, 1.2f, 1.3f, 1.4f, 1.5f);
17-
local started = false  				   -- Status of the arena (false = not started, true = started)
17+
    static const WorldLocation startLoc2 = WorldLocation(1, 1.2f, 1.3f, 1.4f, 1.5f);
18
    // Location after arena
19-
local p1 = {}
19+
    static const WorldLocation allyAA = WorldLocation(1, 1.2f, 1.3f, 1.4f, 1.5f);
20-
local p2 = {}
20+
    static const WorldLocation hordeAA = WorldLocation(1, 1.2f, 1.3f, 1.4f, 1.5f);
21
22-
local t1,t2 = false, false
22+
    // Dont edit below
23
24-
-- Custom Functions
24+
    static std::list<uint64> que;
25
    uint64 p1 = 0;
26-
local function endArena()
26+
    uint64 p2 = 0;
27-
	local p1t = p1[t1]:getTeam()
27+
28-
	local p2t = p2[t2]:getTeam()
28+
    static Player* getPlayer()
29-
	
29+
    {
30-
	if(p1t == 1) then
30+
        if (que.empty())
31-
		p1[t1]:Teleport(hm,hx,hy,hz)
31+
            return NULL;
32-
	else
32+
        Player* player = sObjectAccessor->FindPlayer(que.front());
33-
		p1[t1]:Teleport(am,ax,ay,az)
33+
        que.pop_front();
34-
	end
34+
        return player;
35-
	
35+
    }
36-
	if(p2t == 1) then
36+
37-
		p2[t2]:Teleport(hm,hx,hy,hz)
37+
    static void sendPlayers()
38-
	else
38+
    {
39-
		p2[t2]:Teleport(am,ax,ay,az)
39+
        if(!p1 || !p2)
40-
	end
40+
            return;
41-
	
41+
        if (que.size() < 2)
42-
	table.remove(p1,t1)
42+
            return;
43-
	table.remove(p2,t2)
43+
44-
	started = false
44+
        Player* player1 = NULL;
45-
end
45+
        Player* player2 = NULL;
46
        while (!p1 && que.size >= 2)
47-
local function checkArena()
47+
            player1 = getPlayer();
48-
	if(started) then
48+
        while (!p2 && que.size >= 2)
49-
		if(t1 and t2) then
49+
            player2 = getPlayer();
50-
			if(p1[t1]:isDead()) then
50+
51-
				p2[t2]:SendBroadcastMessage("Congratulations! You won "..reward.." honor!")
51+
        if(!player1 || !player2)
52-
				p1[t1]:SendBroadcastMessage("You can do better than that.")
52+
            return;
53-
				p2[t2]:giveHonor(reward)
53+
54-
				p1[t1]:ResurrectPlayer()
54+
        p1 = player1->GetGUID();
55-
				endArena()
55+
        p2 = player2->GetGUID();
56-
			elseif(p2[t2]:isDead()) then
56+
        player1->TeleportTo(startLoc1);
57-
				p1[t1]:SendBroadcastMessage("Congratulations! You won "..reward.." honor!")
57+
        player2->TeleportTo(startLoc2);
58-
				p2[t2]:SendBroadcastMessage("You can do better than that.")
58+
    }
59-
				p1[t1]:giveHonor(reward)
59+
}
60-
				p2[t2]:ResurrectPlayer()
60+
61-
				endArena()
61+
class FightMaster : public CreatureScript
62-
			end
62+
{
63-
		end
63+
public:
64-
	end
64+
    FightMaster() : CreatureScript("FightMaster")
65-
end
65+
    {
66
    }
67-
local function getRandom(array)
67+
68-
	local size = #array
68+
    bool OnGossipHello(Player* player, Creature* creature)
69-
    if(size == 0) then
69+
    {
70-
        return false
70+
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_BATTLE, "Add me to the queue", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
71-
    elseif(size > 1) then
71+
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Nevermind..", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
72-
        return math.random(1,size)
72+
        player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
73-
    elseif(size == 1) then
73+
        return true;
74-
        return 1
74+
    }
75-
    end
75+
76-
end
76+
    bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
77
    {
78-
local function sendPlayers()
78+
        if (sender == GOSSIP_SENDER_MAIN && action == GOSSIP_ACTION_INFO_DEF+1)
79-
	if(started == false) then
79+
        {
80-
		t1 = getRandom(p1)
80+
            que.push_back(player->GetGUID());
81-
		t2 = getRandom(p2)
81+
            ChatHandler(player->GetSession()).SendSysMessage("You are now added to the queue! Good luck!");
82-
		
82+
        }
83-
		if(t1 and t2) then
83+
	    player->CLOSE_GOSSIP_MENU();
84-
			p1[t1]:Teleport(m1,x1,y1,z1,0)
84+
    }
85-
			p2[t2]:Teleport(m2,x2,y2,z2,0)
85+
};
86-
			
86+
87-
			started = true
87+
class FightChecker : public WorldScript
88-
		end
88+
{
89-
	end
89+
public:
90-
end
90+
    static const char* rew_msg;
91
92-
local function addPlayer(player,unit)
92+
    FightChecker() : WorldScript("FightChecker")
93-
	local p1s = #p1
93+
    {
94-
	local p2s = #p2
94+
        std::ostringstream oss;
95-
	if (p1s > p2s)  then
95+
        oss << "Congratulations! You won " << REWARD << " honor!";
96-
		table.insert(p2, player)
96+
        rew_msg = oss.str().c_str();
97-
	elseif(p1s < p2s or p1s = p2s) then
97+
    }
98-
		table.insert(p1, player)
98+
99-
	end
99+
    static void checkArena()
100-
	player:SendBroadcastMessage("You are now added to the queue! Good luck!")
100+
    {
101-
end
101+
	    if(!p1 || !p2)
102
            return;
103-
local function Hello(Unit, Event, player)
103+
        Player* player1 = sObjectAccessor->FindPlayer(p1);
104-
	Unit:GossipCreateMenu(100, player, 0)
104+
        Player* player2 = sObjectAccessor->FindPlayer(p2);
105-
	
105+
        if (player1 && player1->isDead())
106-
	Unit:GossipMenuAddItem(6, "Add me to the queue!", 1)
106+
        {
107-
	Unit:GossipMenuAddItem(7, "Nevermind", 2)
107+
            ChatHandler(player2->GetSession()).SendSysMessage(rew_msg);
108-
	
108+
            ChatHandler(player1->GetSession()).SendSysMessage("You can do better than that.");
109-
	Unit:GossipSendMenu(player)
109+
            player2->ModifyHonorPoints(REWARD);
110-
end
110+
            player1->ResurrectPlayer(100);
111
        }
112-
local function Select(Unit, Event, player, id, intid, code, pMisc)
112+
        else if (player2 && player2->isDead())
113-
	if(intid == 1) then
113+
        {
114-
		addPlayer(player)
114+
            ChatHandler(player1->GetSession()).SendSysMessage(rew_msg);
115-
	end
115+
            ChatHandler(player2->GetSession()).SendSysMessage("You can do better than that.");
116-
	player:GossipComplete()
116+
            player1->ModifyHonorPoints(REWARD);
117-
end
117+
            player2->ResurrectPlayer(100);
118
        }
119-
-- Registers
119+
        else
120-
RegisterTimedEvent("sendPlayers", 30000, 0)
120+
            return;
121-
RegisterTimedEvent("checkArena",   5000, 0)
121+
        if (player1)
122-
RegisterUnitGossipEvent(NPC, 1, Hello)
122+
            player1->TeleportTo(player1->GetTeam() == HORDE ? hordeAA : allyAA);
123-
RegisterUnitGossipEvent(NPC, 2, Select)
123+
        if (player2)
124
            player2->TeleportTo(player2->GetTeam() == HORDE ? hordeAA : allyAA);
125
        p1 = 0;
126
        p2 = 0;
127
    }
128
129
    struct FightEvent : BasicEvent
130
    {
131
        typedef void (*callback)(void);
132
        FightEvent(callback func) : BasicEvent()
133
        {
134
            _func = func;
135
        }
136
        bool Execute(uint64, uint32)
137
        {
138
            if(_func)
139
                _func();
140
            return true;
141
        }
142
        callback _func;
143
    };
144
145
    void OnUpdate(uint32 diff)
146
    {
147
        processor.Update(diff);
148
    }
149
150
    void OnStartup()
151
    {
152
        processor.AddEvent(new FightEvent(sendPlayers), processor.CalculateTime(30000));
153
        processor.AddEvent(new FightEvent(checkArena), processor.CalculateTime(5000));
154
    }
155
156
    EventProcessor processor;
157
};
158
159
void AddSC_FightScript()
160
{
161
    new FightChecker();
162
    new FightMaster();
163
}
164
165
#undef REWARD