Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. function CreateQue()
  2. local que = {que = {}}
  3.  
  4. function que:Add(index)
  5. if (self:Has(index)) then
  6. return false
  7. end
  8. self.que[index] = true
  9. return true
  10. end
  11.  
  12. function que:Remove(index)
  13. if (not self:Has(index)) then
  14. return false
  15. end
  16. self.que[index] = nil
  17. return true
  18. end
  19.  
  20. function que:Has(index)
  21. return self.que[index] ~= nil
  22. end
  23.  
  24. function que:Get()
  25. return self.que
  26. end
  27.  
  28. local pairs = pairs
  29. function que:Count()
  30. local count = 0
  31. for k,v in pairs(self.que) do
  32. count = count + 1
  33. end
  34. return count
  35. end
  36.  
  37. return que
  38. end
  39.  
  40. function BattleGroundTSOnChat(event, player, msg, _, lang) -- Only for Debug Change this to Creature Gossip
  41. if (msg == "#test1") then
  42. OnBattleGroundTSHello(event, player)
  43. end
  44. end
  45.  
  46. function OnBattleGroundTSHello(event, player)
  47. local que = CreateQue()
  48. local plrguid = player:GetGUID()
  49. local IsInQueue = que:Has(plrguid)
  50. if IsInQueue then
  51. player:GossipMenuAddItem(0, "Leave the Battle", 0, 2) -- Leave the queue
  52. else
  53. player:GossipMenuAddItem(0, "Join the Battle", 0, 3) -- Join the queue
  54. end
  55.  
  56. player:GossipMenuAddItem(0, "Nevermind..", 0, 1)
  57.  
  58. player:GossipSetText("Hello "..player:GetName().."")
  59. player:GossipSendMenu(0x7FFFFFFF, player, 100)
  60. end
  61.  
  62. function OnBattleGroundTSSelect(event, player, _, sender, intid, code)
  63. local que = CreateQue()
  64. local plrguid = player:GetGUID()
  65. local added = que:Add(plrguid)
  66. local removed = que:Remove(plrguid)
  67. if (intid == 1) then -- Close the Gossip
  68. player:GossipComplete()
  69. elseif (intid == 2) then -- Leave the queue
  70. player:removed()
  71. player:GossipComplete()
  72. player:SendBroadcastMessage("you leave the queue")
  73. elseif (intid == 3) then -- Join the queue
  74. if (result) then
  75. player:SendBroadcastMessage("you already in the queue") -- player already in the queue
  76. player:GossipComplete()
  77. else
  78. player:added()
  79. player:SendBroadcastMessage("you join the queue")
  80. player:RegisterEvent(BattleGroundTSCheck, 10000, 0) -- Check all 10 secounds the queue player count
  81. player:GossipComplete()
  82. end
  83. end
  84. end
  85.  
  86. function BattleGroundTSCheck(event, delay, pCall, player)
  87. local count = que:Count()
  88. if (count < 3) then
  89. player:SendBroadcastMessage("1") -- queue not much player
  90. else
  91. player:SendBroadcastMessage("2") -- queue start here the window for invite and teleport
  92. end
  93. end
  94.  
  95. RegisterPlayerEvent(18, BattleGroundTSOnChat) -- Register Evenet on Chat Command use
  96. RegisterPlayerGossipEvent(100, 2, OnBattleGroundTSSelect) -- Register Event for Gossip Select
  97.  
  98.  
  99. -- 2014-11-23 15:26:00 lua_scripts/bg.lua:78: attempt to call method 'added' (a nil value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement