Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. -- Include sc_default
  2. require "/sc_default"
  3.  
  4. function BattleGroundTSOnChat(event, player, msg, _, lang) -- Only for Debug Change this to Creature Gossip
  5. if (msg == "#test1") then
  6. OnBattleGroundTSHello(event, player)
  7. end
  8. end
  9.  
  10. function OnBattleGroundTSHello(event, player)
  11. local result = CharDBQuery("SELECT id FROM bg WHERE id = "..player:GetGUIDLow())
  12. player:GossipClearMenu()
  13. if (result) then
  14. player:GossipMenuAddItem(0, "Leave the Battle", 0, 2) -- Leave the queue
  15. else
  16. player:GossipMenuAddItem(0, "Join the Battle", 0, 3) -- Join the queue
  17. end
  18.  
  19. player:GossipMenuAddItem(0, "Nevermind..", 0, 1)
  20.  
  21. player:GossipSetText("Hello "..player:GetName().."")
  22. player:GossipSendMenu(0x7FFFFFFF, player, 100)
  23. end
  24.  
  25. function OnBattleGroundTSSelect(event, player, _, sender, intid, code)
  26. local result = CharDBQuery("SELECT id FROM bg WHERE id = "..player:GetGUIDLow())
  27. if (intid == 1) then -- Close the Gossip
  28. player:GossipComplete()
  29. elseif (intid == 2) then -- Leave the queue
  30. player:GossipComplete()
  31. CharDBQuery("delete from `bg` where id = ('"..player:GetGUIDLow().."');") -- Delete Player from queue
  32. player:RemoveEvents()
  33. player:SendBroadcastMessage("you leave the queue")
  34. elseif (intid == 3) then -- Join the queue
  35. if (result) then
  36. player:SendBroadcastMessage("you already in the queue") -- player already in the queue
  37. player:GossipComplete()
  38. else
  39. CharDBQuery("insert into `bg` (`id`) values ('"..player:GetGUIDLow().."');") -- Insert Player to the queue
  40. player:SendBroadcastMessage("you join the queue")
  41. player:RegisterEvent(BattleGroundTSCheck, 10000, 0) -- Check all 10 secounds the queue player count
  42. player:GossipComplete()
  43. end
  44. end
  45. end
  46.  
  47. function BattleGroundTSCheck(event, delay, pCall, player)
  48. local result = CharDBQuery("SELECT COUNT(*) FROM bg;") -- check the count from the queue
  49. local count = tonumber(result:GetInt64( 0 ))
  50.  
  51. if (count and count < 3) then
  52. player:SendBroadcastMessage("1") -- queue not much player
  53. else
  54. player:SendBroadcastMessage("2") -- queue start here the window for invite and teleport
  55. end
  56. end
  57.  
  58. RegisterPlayerEvent(18, BattleGroundTSOnChat) -- Register Evenet on Chat Command use
  59. RegisterPlayerGossipEvent(100, 2, OnBattleGroundTSSelect) -- Register Event for Gossip Select
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement