Advertisement
Guest User

Arena 1V1

a guest
Jan 16th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  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
  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
  59. table.insert(T, pPlayer)
  60. T.Que[tostring(pPlayer)] = true
  61. pPlayer:SendAreaTriggerMessage("You have been added to the queue")
  62. if(not Running and #T >= 2) then
  63. T.Teleport()
  64. end
  65. elseif(intid == 2) then
  66. local tstr = tostring(pPlayer)
  67. for k,v in ipairs(T) do
  68. if(tostring(v) == tstr) then
  69. pPlayer:DealGoldMerit(100000) -- refund bet
  70. table.remove(T, k)
  71. T.Que[tostring(pPlayer)] = nil
  72. break
  73. end
  74. end
  75. pPlayer:SendAreaTriggerMessage("You have been removed from the queue")
  76. end
  77. pPlayer:GossipComplete()
  78. end
  79.  
  80. function T.Kill(event, pKiller, pVictim)
  81. local strK, strV = tostring(pKiller), tostring(pVictim)
  82. if(not Running or strK == strV) then
  83. return
  84. end
  85. local str1, str2 = tostring(T[1]), tostring(T[2])
  86. if((str1 == strK or str1 == strV) and (str2 == strK or str2 == strV)) then
  87. -- Rewards and such go here:
  88. pKiller:DealGoldMerit(200000) -- give 20 gold to winner (double the bet)
  89.  
  90.  
  91. --
  92. DestroyLuaEvent(T.Event)
  93. T.End(strK, strV)
  94. end
  95. end
  96.  
  97. function T.End(str1, str2)
  98. T[1]:Teleport(T.Loc1[1], T.Loc1[2], T.Loc1[3], T.Loc1[4], T.Loc1[5]) -- Teleport player 1 back
  99. T[2]:Teleport(T.Loc2[1], T.Loc2[2], T.Loc2[3], T.Loc2[4], T.Loc2[5]) -- Teleport player 2 back
  100. table.remove(T, 1)
  101. table.remove(T, 1)
  102. T.Que[str1] = nil
  103. T.Que[str2] = nil
  104. Running = false
  105. T.Teleport()
  106. end
  107.  
  108. local Entry = 12345
  109. RegisterUnitGossipEvent(89102, 1, T.Hello)
  110. RegisterUnitGossipEvent(89102, 2, T.Select)
  111. RegisterServerHook(2, T.Kill)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement