stoneharry

Untitled

Mar 16th, 2011
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.48 KB | None | 0 0
  1.  
  2. -- By Stoneharry
  3.  
  4. --dofile("scripts/que_handler.lua")
  5.  
  6. local Lives = 50 -- The amount of lives each team has
  7. local HordeLives = 50 -- The amount of lives to start with
  8. local AllianceLives = 50 -- The amount of lives to start with
  9.  
  10. local RequiredPlayers = 1 -- The amount of players required to start the battleground (THIS IS NOT PER TEAM, THIS IS TOTAL)
  11.  
  12. local RewardID = 0 -- Change this to a value to add 1 of them to all of the winning team - leave as 0 for no reward
  13.  
  14. local BroadcastKills = true -- Set this to false if you do not want kills to be broadcasted to the rest of the BG
  15.  
  16. -- Battleground Start Locations
  17. local AMap, AX, AY, AZ = 531, -8517, 2014, 107 -- Map, x, y, z for Alliance
  18. local HMap, HX, HY, HZ = 531, -8517, 2014, 107 -- Map x, y, z for Horde
  19.  
  20. -- Where to teleport once battleground ends
  21. local HomeMA, HomeXA, HomeYA, HomeZA = 1, 0, 0, 0 -- Map, x, y, Z for Alliance
  22. local HomeMH, HomeXH, HomeYH, HomeZH = 1, 0, 0, 0 -- Map, X, Y, Z for Horde
  23.  
  24. ----------------------------------------------------------------------------------------------------------
  25. -- Do Not Touch Below This Line Unless You Know What Your Doing P.S. Starting Letters With Caps Is Cool --
  26. ----------------------------------------------------------------------------------------------------------
  27.  
  28. -- Just don't touch
  29. local players = {}
  30. local Horde = {}
  31. local Alliance = {}
  32. local InGame = false
  33.  
  34. -- Do not touch unless you know what your doing
  35. local message = 4
  36. local CountDown = 60
  37.  
  38. -- Only touch this if you are not using 3.3.5a, find the right values in Opcodes.h
  39. local SMSG_INIT_WORLD_STATES = 0x2C2
  40. local SMSG_UPDATE_WORLD_STATE = 0x2C3
  41.  
  42. function ProcessQueForBattleground()
  43.     if InGame == false then
  44.         if table.getn(players) >= RequiredPlayers then
  45.             InGame = true
  46.             local team = 0
  47.             for place, plrs in pairs(players) do -- Randomly make players join alliance/horde teams rather than horde vs alliance
  48.                 -- Update people left
  49.                 local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
  50.                 pack:WriteULong(1) -- Map
  51.                 pack:WriteULong(1377) -- Zone
  52.                 pack:WriteULong(0)
  53.                 pack:WriteUShort(2)
  54.                 pack:WriteULong(0) -- ID
  55.                 pack:WriteULong(1) -- Value
  56.                 pack:WriteULong(0) -- ID
  57.                 pack:WriteULong(1) -- Value
  58.                 plrs:SendPacketToPlayer(pack)
  59.                 local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  60.                 pack:WriteULong(2317) -- ID, total
  61.                 pack:WriteULong(Lives) -- Value
  62.                 plrs:SendPacketToPlayer(pack)
  63.                 local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  64.                 pack:WriteULong(2314) -- ID
  65.                 pack:WriteULong(HordeLives) -- Amount, Horde
  66.                 plrs:SendPacketToPlayer(pack)      
  67.                 local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  68.                 pack:WriteULong(2313) -- ID
  69.                 pack:WriteULong(AllianceLives) -- Amount, Alliance
  70.                 plrs:SendPacketToPlayer(pack)
  71.                 --
  72.                 team = team + 1
  73.                 if team == 0 then
  74.                     plrs:SetFaction(team)
  75.                     plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
  76.                     plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
  77.                     table.insert(Alliance, plrs)
  78.                     plrs:Teleport(AMap, AX, AY, AZ)
  79.                 elseif team == 1 then
  80.                     plrs:SetFaction(team)
  81.                     plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Horde!")
  82.                     plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Horde!")
  83.                     table.insert(Horde, plrs)
  84.                     plrs:Teleport(HMap, HX, HY, HZ)
  85.                 elseif team == 2 then
  86.                     team = 0
  87.                     plrs:SetFaction(team)
  88.                     plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
  89.                     plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
  90.                     table.insert(Alliance, plrs)
  91.                     plrs:Teleport(AMap, AX, AY, AZ)
  92.                 end
  93.             end
  94.             CountDown = 60
  95.             RegisterTimedEvent("Game_Start_Battleground_Countdown", 10000, 6)
  96.         else
  97.             for place, plrs in pairs(players) do
  98.                 if plrs ~= nil then
  99.                     plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00Waiting for more players...")
  100.                 end
  101.             end
  102.         end
  103.     else
  104.         message = message + 1
  105.         if message == 5 then
  106.             message = 0
  107.             for place, plrs in pairs(players) do
  108.                 if plrs ~= nil then
  109.                     plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground is currently in progress!")
  110.                 end
  111.             end
  112.         end
  113.     end
  114. end
  115.  
  116. RegisterTimedEvent("ProcessQueForBattleground", 30000, 0)
  117.  
  118. function Game_Start_Battleground_Countdown()
  119.     CountDown = CountDown - 10
  120.     for place, plrs in pairs(players) do
  121.         if CountDown == 0 then
  122.             if plrs ~= nil then
  123.                 plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
  124.                 plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
  125.                 plrs:PlaySoundToPlayer(6077) -- War music
  126.                 -- Update people left
  127.                 local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
  128.                 pack:WriteULong(1) -- Map
  129.                 pack:WriteULong(1377) -- Zone
  130.                 pack:WriteULong(0)
  131.                 pack:WriteUShort(2)
  132.                 pack:WriteULong(0) -- ID
  133.                 pack:WriteULong(1) -- Value
  134.                 pack:WriteULong(0) -- ID
  135.                 pack:WriteULong(1) -- Value
  136.                 plrs:SendPacketToPlayer(pack)
  137.                 local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  138.                 pack:WriteULong(2317) -- ID, total
  139.                 pack:WriteULong(Lives) -- Value
  140.                 plrs:SendPacketToPlayer(pack)
  141.                 local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  142.                 pack:WriteULong(2314) -- ID
  143.                 pack:WriteULong(HordeLives) -- Amount, Horde
  144.                 plrs:SendPacketToPlayer(pack)      
  145.                 local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  146.                 pack:WriteULong(2313) -- ID
  147.                 pack:WriteULong(AllianceLives) -- Amount, Alliance
  148.                 plrs:SendPacketToPlayer(pack)
  149.                 --
  150.             end
  151.         else
  152.             if plrs ~= nil then
  153.                 plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
  154.                 plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
  155.             end
  156.         end
  157.     end
  158. end
  159.  
  160. function JoinQue(plr)
  161.     if InGame then
  162.         plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You can't join the que while the game is in progress!")
  163.         plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You can't join the que while the game is in progress!")     
  164.     else
  165.         local Disable = false
  166.         for place, plrs in pairs(players) do
  167.             if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
  168.                 Disable = true
  169.                 --break
  170.             end
  171.         end
  172.         if Disable then
  173.             plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
  174.             plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
  175.         else
  176.             table.insert(players, plr) -- Insert into players with value plr
  177.             plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground!")
  178.             plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground!")
  179.         end
  180.     end
  181. end
  182.  
  183. function ResetBG()
  184.     for place, plrs in pairs(players) do
  185.         if plrs ~= nil then
  186.             plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
  187.             plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
  188.             plrs:SetPlayerLock(0)
  189.             local race = plrs:GetPlayerRace()
  190.             if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
  191.                 plrs:SetFaction(1)
  192.                 plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
  193.             else
  194.                 plrs:SetFaction(2)
  195.                 plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
  196.             end
  197.         end
  198.     end
  199.     InGame = false
  200.     for place,plrs in pairs(players) do -- Clean old table rather than overwriting with a new table
  201.         players[place] = nil
  202.     end
  203.     for place,plrs in pairs(Horde) do -- Clean old table rather than overwriting with a new table
  204.         players[place] = nil
  205.     end
  206.     for place,plrs in pairs(Alliance) do -- Clean old table rather than overwriting with a new table
  207.         players[place] = nil
  208.     end
  209. end
  210.  
  211. function SERVER_HOOK_KILL_PLAYER_BG(event, plr, killer)
  212.     local playingBG = false
  213.     for place, plrs in pairs(players) do
  214.         if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
  215.             playingBG = true
  216.             --break
  217.         end
  218.     end
  219.     if playingBG then
  220.         for place, plrs in pairs(Alliance) do
  221.             if plrs:GetName() == plr:GetName() then
  222.                 playingBG = false -- They are Alliance
  223.             end
  224.         end
  225.         local Continue = true
  226.         if HordeLives == 1 then
  227.             for place, plrs in pairs(players) do
  228.                 plrs:SetCombatLock(1)
  229.                 plrs:SetHealth(plrs:GetMaxHealth())
  230.                 plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Horde have won!")
  231.                 plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Horde have won!")
  232.                 plrs:PlaySoundToPlayer(8454) -- Horde Victory
  233.             end
  234.             for place, plrs in pairs(Horde) do
  235.                 if RewardID ~= 0 then
  236.                     plrs:AddItem(RewardID, 1)
  237.                 end
  238.             end
  239.             RegisterTimedEvent("Reset_In_Five_BG", 5000, 1)
  240.         elseif AllianceLives == 1 then
  241.             for place, plrs in pairs(players) do
  242.                 plrs:SetCombatLock(1)
  243.                 plrs:SetHealth(plrs:GetMaxHealth())
  244.                 plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Alliance have won!")
  245.                 plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Alliance have won!")
  246.                 plrs:PlaySoundToPlayer(8455) -- Alliance Victory
  247.             end
  248.             for place, plrs in pairs(Alliance) do
  249.                 if RewardID ~= 0 then
  250.                     plrs:AddItem(RewardID, 1)
  251.                 end
  252.             end
  253.             RegisterTimedEvent("ResetBG", 5000, 1)
  254.         end
  255.         if Continue then
  256.             if PlayingBG then -- There Horde
  257.                 for place, plrs in pairs(players) do
  258.                     local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  259.                     pack:WriteULong(2314) -- ID
  260.                     HordeLives = HordeLives - 1
  261.                     pack:WriteULong(HordeLives) -- Amount, Horde
  262.                     plrs:SendPacketToPlayer(pack)
  263.                 end
  264.             else
  265.                 for place, plrs in pairs(players) do
  266.                     local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  267.                     pack:WriteULong(2313) -- ID
  268.                     AllianceLives = AllianceLives - 1
  269.                     pack:WriteULong(AllianceLives) -- Amount, Alliance
  270.                     plrs:SendPacketToPlayer(pack)
  271.                 end
  272.             end
  273.             if BroadcastKills then
  274.                 for place, plrs in pairs(players) do
  275.                     plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00"..killer:GetName().." has killed "..plr:GetName().."!")
  276.                 end
  277.             end
  278.         end
  279.     end
  280. end
  281.  
  282. RegisterServerHook(2, "SERVER_HOOK_KILL_PLAYER_BG")
  283.  
  284. -----------
  285. -- Debug --
  286. -----------
  287. --[[
  288.   The functions below should be removed, they are used for debugging the system.
  289. ]]
  290.  
  291. function OnChat_Hook_ToJoinBG(event, plr, message, pType, pLanguage, pMisc)
  292.     local message = string.lower(message)
  293.     if message == "#joinbg" then
  294.         JoinQue(plr)
  295.     elseif message == "#finbg" then
  296.         ResetBG()
  297.     end
  298.     if message == "test" then
  299.         if math.random(1,2) == 1 then
  300.             local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  301.             pack:WriteULong(2314) -- ID
  302.             HordeLives = HordeLives - 1
  303.             pack:WriteULong(HordeLives) -- Amount, Horde
  304.             plr:SendPacketToPlayer(pack)
  305.         else
  306.             local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  307.             pack:WriteULong(2313) -- ID
  308.             AllianceLives = AllianceLives - 1
  309.             pack:WriteULong(AllianceLives) -- Amount, Alliance
  310.             plr:SendPacketToPlayer(pack)
  311.         end
  312.     end
  313. end
  314.  
  315. RegisterServerHook(16, "OnChat_Hook_ToJoinBG")
Advertisement
Add Comment
Please, Sign In to add comment