Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Include sc_default
- require "/sc_default"
- function BattleGroundTSOnChat(event, player, msg, _, lang) -- Only for Debug Change this to Creature Gossip
- if (msg == "#test1") then
- OnBattleGroundTSHello(event, player)
- end
- end
- function OnBattleGroundTSHello(event, player)
- local result = CharDBQuery("SELECT id FROM bg WHERE id = "..player:GetGUIDLow())
- player:GossipClearMenu()
- if (result) then
- player:GossipMenuAddItem(0, "Leave the Battle", 0, 2) -- Leave the queue
- else
- player:GossipMenuAddItem(0, "Join the Battle", 0, 3) -- Join the queue
- end
- player:GossipMenuAddItem(0, "Nevermind..", 0, 1)
- player:GossipSetText("Hello "..player:GetName().."")
- player:GossipSendMenu(0x7FFFFFFF, player, 100)
- end
- function OnBattleGroundTSSelect(event, player, _, sender, intid, code)
- local result = CharDBQuery("SELECT id FROM bg WHERE id = "..player:GetGUIDLow())
- if (intid == 1) then -- Close the Gossip
- player:GossipComplete()
- elseif (intid == 2) then -- Leave the queue
- player:GossipComplete()
- CharDBQuery("delete from `bg` where id = ('"..player:GetGUIDLow().."');") -- Delete Player from queue
- player:RemoveEvents()
- player:SendBroadcastMessage("you leave the queue")
- elseif (intid == 3) then -- Join the queue
- if (result) then
- player:SendBroadcastMessage("you already in the queue") -- player already in the queue
- player:GossipComplete()
- else
- CharDBQuery("insert into `bg` (`id`) values ('"..player:GetGUIDLow().."');") -- Insert Player to the queue
- player:SendBroadcastMessage("you join the queue")
- player:RegisterEvent(BattleGroundTSCheck, 10000, 0) -- Check all 10 secounds the queue player count
- player:GossipComplete()
- end
- end
- end
- function BattleGroundTSCheck(event, delay, pCall, player)
- local result = CharDBQuery("SELECT COUNT(*) FROM bg;") -- check the count from the queue
- local count = tonumber(result:GetInt64( 0 ))
- if (count and count < 3) then
- player:SendBroadcastMessage("1") -- queue not much player
- else
- player:SendBroadcastMessage("2") -- queue start here the window for invite and teleport
- end
- end
- RegisterPlayerEvent(18, BattleGroundTSOnChat) -- Register Evenet on Chat Command use
- RegisterPlayerGossipEvent(100, 2, OnBattleGroundTSSelect) -- Register Event for Gossip Select
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement