SHOW:
|
|
- or go back to the newest paste.
1 | - | local T = {Que} |
1 | + | local T = {Que = {}} |
2 | local Running = false | |
3 | ||
4 | function T.Exists(pPlayer) | |
5 | if(pPlayer and type(pPlayer) == "userdata" and pPlayer:GetName()) then | |
6 | return true | |
7 | end | |
8 | return false | |
9 | end | |
10 | ||
11 | function T.Hello(pUnit, event, pPlayer) | |
12 | pUnit:GossipCreateMenu(100, pPlayer, 0) | |
13 | pUnit:GossipMenuAddItem(0, "Queuers: "..(#T), 0, 0, '', 0) | |
14 | if(not T.Que[tostring(pPlayer)]) then | |
15 | - | pUnit:GossipMenuAddItem(0, "Join the queue", 1, 0, '', 100000) -- Joining fee 10gold |
15 | + | pUnit:GossipMenuAddItem(0, "Join the queue", 1, 0, '', 0) -- Joining fee 10gold |
16 | else | |
17 | pUnit:GossipMenuAddItem(0, "Leave the queue", 2, 0, 'Leave the queue? Bet will be refunded.', 0) | |
18 | end | |
19 | pUnit:GossipSendMenu(pPlayer) | |
20 | end | |
21 | ||
22 | function T.Teleport() | |
23 | if(#T < 2) then | |
24 | return | |
25 | end | |
26 | if(not T.Exists(T[1])) then | |
27 | table.remove(T, 1) | |
28 | T.Teleport() | |
29 | return | |
30 | end | |
31 | if(not T.Exists(T[2])) then | |
32 | table.remove(T, 2) | |
33 | T.Teleport() | |
34 | return | |
35 | end | |
36 | local x,y,z,o = T[1]:GetLocation() | |
37 | local map = T[1]:GetMapId() | |
38 | T.Loc1 = {map,x,y,z,o} | |
39 | local x,y,z,o = T[2]:GetLocation() | |
40 | local map = T[2]:GetMapId() | |
41 | T.Loc2 = {map,x,y,z,o} | |
42 | ||
43 | -- Fill in the coordinates! | |
44 | T[1]:Teleport(map, x, y, z, o) -- Teleport player 1 | |
45 | T[2]:Teleport(map, x, y, z, o) -- teleport player 2 | |
46 | ||
47 | -- Timer to automatically end the duel/arena/bg after 10 min (10 min = 600 sec = 600000 ms) | |
48 | T.Event = CreateLuaEvent(function() T.End(tostring(T[1]), tostring(T[2])) end, 600000, 1) | |
49 | ||
50 | Running = true | |
51 | end | |
52 | ||
53 | function T.Select(pUnit, event, pPlayer, id, intid, code) | |
54 | if(intid == 0) then | |
55 | T.Hello(pUnit, event, pPlayer) | |
56 | return | |
57 | elseif(intid == 1) then | |
58 | - | pPlayer:DealGoldCost(100000) -- take bet |
58 | + | |
59 | T.Que[tostring(pPlayer)] = true | |
60 | pPlayer:SendAreaTriggerMessage("You have been added to the queue") | |
61 | if(not Running and #T >= 2) then | |
62 | T.Teleport() | |
63 | end | |
64 | elseif(intid == 2) then | |
65 | local tstr = tostring(pPlayer) | |
66 | for k,v in ipairs(T) do | |
67 | if(tostring(v) == tstr) then | |
68 | table.remove(T, k) | |
69 | - | pPlayer:DealGoldMerit(100000) -- refund bet |
69 | + | |
70 | break | |
71 | end | |
72 | end | |
73 | pPlayer:SendAreaTriggerMessage("You have been removed from the queue") | |
74 | end | |
75 | pPlayer:GossipComplete() | |
76 | end | |
77 | ||
78 | function T.Kill(event, pKiller, pVictim) | |
79 | local strK, strV = tostring(pKiller), tostring(pVictim) | |
80 | if(not Running or strK == strV) then | |
81 | return | |
82 | end | |
83 | local str1, str2 = tostring(T[1]), tostring(T[2]) | |
84 | if((str1 == strK or str1 == strV) and (str2 == strK or str2 == strV)) then | |
85 | -- Rewards and such go here: | |
86 | pKiller:AddItem(121001, 1) | |
87 | ||
88 | - | pKiller:DealGoldMerit(200000) -- give 20 gold to winner (double the bet) |
88 | + | |
89 | DestroyLuaEvent(T.Event) | |
90 | pVictim:ResurrectPlayer() | |
91 | T.End(strK, strV) | |
92 | end | |
93 | end | |
94 | ||
95 | function T.End(str1, str2) | |
96 | T[1]:Teleport(T.Loc1[1], T.Loc1[2], T.Loc1[3], T.Loc1[4], T.Loc1[5]) -- Teleport player 1 back | |
97 | T[2]:Teleport(T.Loc2[1], T.Loc2[2], T.Loc2[3], T.Loc2[4], T.Loc2[5]) -- Teleport player 2 back | |
98 | table.remove(T, 1) | |
99 | table.remove(T, 1) | |
100 | T.Que[str1] = nil | |
101 | T.Que[str2] = nil | |
102 | Running = false | |
103 | T.Teleport() | |
104 | end | |
105 | ||
106 | local Entry = 12345 | |
107 | RegisterUnitGossipEvent(89102, 1, T.Hello) | |
108 | RegisterUnitGossipEvent(89102, 2, T.Select) | |
109 | RegisterServerHook(2, T.Kill) |