Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local T = {Que = {}}
- local Running = false
- function T.Exists(pPlayer)
- if(pPlayer and type(pPlayer) == "userdata" and pPlayer:GetName()) then
- return true
- end
- return false
- end
- function T.Hello(pUnit, event, pPlayer)
- pUnit:GossipCreateMenu(100, pPlayer, 0)
- pUnit:GossipMenuAddItem(0, "Queuers: "..(#T), 0, 0, '', 0)
- if(not T.Que[tostring(pPlayer)]) then
- pUnit:GossipMenuAddItem(0, "Join the queue", 1, 0, '', 100000) -- Joining fee 10gold
- else
- pUnit:GossipMenuAddItem(0, "Leave the queue", 2, 0, 'Leave the queue? Bet will be refunded.', 0)
- end
- pUnit:GossipSendMenu(pPlayer)
- end
- function T.Teleport()
- if(#T < 2) then
- return
- end
- if(not T.Exists(T[1])) then
- table.remove(T, 1)
- T.Teleport()
- return
- end
- if(not T.Exists(T[2])) then
- table.remove(T, 2)
- T.Teleport()
- return
- end
- local x,y,z,o = T[1]:GetLocation()
- local map = T[1]:GetMapId()
- T.Loc1 = {map,x,y,z,o}
- local x,y,z,o = T[2]:GetLocation()
- local map = T[2]:GetMapId()
- T.Loc2 = {map,x,y,z,o}
- -- Fill in the coordinates!
- T[1]:Teleport(map, x, y, z, o) -- Teleport player 1
- T[2]:Teleport(map, x, y, z, o) -- teleport player 2
- -- Timer to automatically end the duel/arena/bg after 10 min (10 min = 600 sec = 600000 ms)
- T.Event = CreateLuaEvent(function() T.End(tostring(T[1]), tostring(T[2])) end, 600000, 1)
- Running = true
- end
- function T.Select(pUnit, event, pPlayer, id, intid, code)
- if(intid == 0) then
- T.Hello(pUnit, event, pPlayer)
- return
- elseif(intid == 1) then
- pPlayer:DealGoldCost(100000) -- take bet
- table.insert(T, pPlayer)
- T.Que[tostring(pPlayer)] = true
- pPlayer:SendAreaTriggerMessage("You have been added to the queue")
- if(not Running and #T >= 2) then
- T.Teleport()
- end
- elseif(intid == 2) then
- local tstr = tostring(pPlayer)
- for k,v in ipairs(T) do
- if(tostring(v) == tstr) then
- pPlayer:DealGoldMerit(100000) -- refund bet
- table.remove(T, k)
- T.Que[tostring(pPlayer)] = nil
- break
- end
- end
- pPlayer:SendAreaTriggerMessage("You have been removed from the queue")
- end
- pPlayer:GossipComplete()
- end
- function T.Kill(event, pKiller, pVictim)
- local strK, strV = tostring(pKiller), tostring(pVictim)
- if(not Running or strK == strV) then
- return
- end
- local str1, str2 = tostring(T[1]), tostring(T[2])
- if((str1 == strK or str1 == strV) and (str2 == strK or str2 == strV)) then
- -- Rewards and such go here:
- pKiller:DealGoldMerit(200000) -- give 20 gold to winner (double the bet)
- --
- DestroyLuaEvent(T.Event)
- T.End(strK, strV)
- end
- end
- function T.End(str1, str2)
- T[1]:Teleport(T.Loc1[1], T.Loc1[2], T.Loc1[3], T.Loc1[4], T.Loc1[5]) -- Teleport player 1 back
- T[2]:Teleport(T.Loc2[1], T.Loc2[2], T.Loc2[3], T.Loc2[4], T.Loc2[5]) -- Teleport player 2 back
- table.remove(T, 1)
- table.remove(T, 1)
- T.Que[str1] = nil
- T.Que[str2] = nil
- Running = false
- T.Teleport()
- end
- local Entry = 12345
- RegisterUnitGossipEvent(Entry, 1, T.Hello)
- RegisterUnitGossipEvent(Entry, 2, T.Select)
- RegisterServerHook(2, T.Kill)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement