stoneharry

Untitled

Mar 29th, 2011
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.69 KB | None | 0 0
  1. -------------------
  2. -- By Stoneharry --
  3. -------------------
  4. -- Variable Decleration
  5. -- Configuration
  6.  
  7. local HANDLER_CREATURE = 2623
  8. local AddA = 36431 -- 4 of them      Gate A
  9. local AddB = 36431 -- 10 of them     Gate A
  10. local AddC = 36431 -- 2 of them      Gate A and B
  11. local AddD = 36431 -- 20 of them     Gate A and B
  12. local AddE = 36431 -- 6 of them      Gate A
  13. local AddF = 36431 -- 15 of them     Gate B
  14. local AddG = 36431 -- 4 of them      Gate A and B
  15. local AddH = 36431 -- 20 of them     no gate
  16.  
  17. local locA, locB, locC = 4523, 2778, 404 -- Randomly moves to one of these two coords on spawn (make near middle)
  18. local locX, locY, locZ = 4522, 2760, 404
  19. local gateAX, gateAY, gateAZ, gateAID = 4522.24, 2740.8, 403.984, 197343 -- The coords then ID of each gate on each side of the room
  20. local gateBX, gateBY, gateBZ, gateBID = 4522.21, 2797.87, 403.984, 201376
  21. local behindGateAX, behindGateAY, behindGateAZ = 4522, 2734, 404 -- The coords behind gate A to spawn mobs
  22. local behindGateBX, behindGateBY, behindGateBZ = 4522, 2804, 404 -- The coords behind gate B to spawn mobs
  23.  
  24. -- Do not touch below unless you are not using 3.3.5a
  25.  
  26. local OBJECT_END = 0x0006
  27. local GAMEOBJECT_BYTES_1 = OBJECT_END + 0x000B
  28. local SMSG_INIT_WORLD_STATES = 0x2C2
  29. local SMSG_UPDATE_WORLD_STATE = 0x2C3
  30.  
  31. -- Do not touch below
  32.  
  33. local CanStart = false
  34. local Wave = 1
  35. local Dead = 0
  36. local gateA = nil
  37. local gateB = nil
  38. local Open = false
  39. local pack = nil
  40.  
  41. ---------------------------------------------------------
  42. -- Wave Handler -----------------------------------------
  43. ---------------------------------------------------------
  44.  
  45. function Invisible_NpcDEFENDMALL(pUnit, Event)
  46.     pUnit:RegisterEvent("Check_For_EventDEFENDMALL", 5000, 0)
  47. end
  48.  
  49. function Check_For_EventDEFENDMALL(pUnit)
  50.     if CanStart then
  51.         pUnit:RemoveEvents()
  52.         CanStart = false
  53.         Wave = 1
  54.         gateA = pUnit:GetGameObjectNearestCoords(gateAX, gateAY, gateAZ, gateAID)
  55.         gateB = pUnit:GetGameObjectNearestCoords(gateBX, gateBY, gateBZ, gateBID)
  56.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  57.             if plrs:GetPhase() == 2 then
  58.                 pUnit:SendChatMessageToPlayer(42,0,"The event has begun! Defend the room for all 8 waves.", plrs)
  59.                 pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- Waves remaining
  60.                 pack:WriteULong(534) -- Map
  61.                 pack:WriteULong(3606) -- Zone
  62.                 pack:WriteULong(0)
  63.                 pack:WriteUShort(2)
  64.                 pack:WriteULong(2842) -- ID
  65.                 pack:WriteULong(1) -- Value
  66.                 plrs:SendPacketToPlayer(pack)
  67.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  68.                 pack:WriteULong(2842) -- ID, total
  69.                 pack:WriteULong(Wave) -- Value
  70.                 plrs:SendPacketToPlayer(pack)
  71.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 1
  72.             end
  73.         end
  74.         pUnit:PlaySoundToSet(8887) -- Scary music
  75.         pUnit:RegisterEvent("Spawn_Adds_DEFENDMALL", 7000, 1)
  76.     end
  77. end
  78.  
  79. RegisterUnitEvent(HANDLER_CREATURE, 18, "Invisible_NpcDEFENDMALL")
  80.  
  81. function Spawn_Adds_DEFENDMALL(pUnit)
  82.     if gateA ~= nil then
  83.         gateA:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  84.         Open = true
  85.     end
  86.     local i = 0
  87.     while i ~= 4 do
  88.         i = i + 1
  89.         pUnit:SpawnCreature(AddA, behindGateAX, behindGateAY, behindGateAZ, 0, 15, 180000)
  90.     end
  91.     pUnit:RegisterEvent("CheckForDeadAddsOhLol", 5000, 0)
  92. end
  93.  
  94. function CheckForDeadAddsOhLol(pUnit)
  95.     if Open then
  96.         if gateA ~= nil then
  97.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  98.             Open = false
  99.         end
  100.     end
  101.     if Dead == 4 then
  102.         Dead = 0
  103.         Wave = Wave + 1
  104.         pUnit:RemoveEvents()
  105.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  106.             if plrs:GetPhase() == 2 then
  107.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  108.                 pack:WriteULong(2842) -- ID, total
  109.                 pack:WriteULong(Wave) -- Value
  110.                 plrs:SendPacketToPlayer(pack)
  111.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 2
  112.             end
  113.         end
  114.         if gateA ~= nil then
  115.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  116.             Open = true
  117.         end
  118.         local i = 0
  119.         while i ~= 10 do
  120.             i = i + 1
  121.             pUnit:SpawnCreature(AddB, behindGateAX, behindGateAY, behindGateAZ, 0, 15, 300000)
  122.         end
  123.         pUnit:RegisterEvent("Check_For_All_DeadDEFENDMALL", 5000, 0)
  124.     end
  125. end
  126.  
  127. function Check_For_All_DeadDEFENDMALL(pUnit)
  128.     if Open then
  129.         if gateA ~= nil then
  130.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  131.             Open = false
  132.         end
  133.     end
  134.     if Dead == 10 then
  135.         pUnit:RemoveEvents()
  136.         Dead = 0
  137.         Wave = Wave + 1
  138.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  139.             if plrs:GetPhase() == 2 then
  140.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  141.                 pack:WriteULong(2842) -- ID, total
  142.                 pack:WriteULong(Wave) -- Value
  143.                 plrs:SendPacketToPlayer(pack)
  144.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 3
  145.             end
  146.         end
  147.         if gateA ~= nil then
  148.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  149.             Open = true
  150.         end
  151.         if gateB ~= nil then
  152.             gateB:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  153.             Open = true
  154.         end
  155.         pUnit:SpawnCreature(AddC, behindGateAX, behindGateAY, behindGateAZ, 0, 15, 320000)
  156.         pUnit:SpawnCreature(AddC, behindGateBX, behindGateBY, behindGateBZ, 0, 15, 320000)
  157.         pUnit:RegisterEvent("Check_For_ADDCDEATHS_DEFENDMALL", 5000, 0)
  158.     end
  159. end
  160.  
  161. function Check_For_ADDCDEATHS_DEFENDMALL(pUnit)
  162.     if Open then
  163.         if gateA ~= nil then
  164.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  165.             Open = false
  166.         end
  167.         if gateB ~= nil then
  168.             gateB:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  169.             Open = false
  170.         end
  171.     end
  172.     if Dead == 2 then
  173.         pUnit:RemoveEvents()
  174.         Dead = 0
  175.         Wave = Wave + 1
  176.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  177.             if plrs:GetPhase() == 2 then
  178.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  179.                 pack:WriteULong(2842) -- ID, total
  180.                 pack:WriteULong(Wave) -- Value
  181.                 plrs:SendPacketToPlayer(pack)
  182.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 4
  183.             end
  184.         end
  185.         --pUnit:PlaySoundToSet(10763)
  186.         pUnit:RegisterEvent("Break_Break_GiveBreak_DEFENDMALL", 8000, 1)
  187.     end
  188. end
  189.  
  190. function Break_Break_GiveBreak_DEFENDMALL(pUnit)
  191.     local i = 0
  192.     while i ~= 20 do
  193.         i = i + 1
  194.         if math.random(1,2) == 1 then
  195.             pUnit:SpawnCreature(AddD, behindGateAX, behindGateAY, behindGateAZ , 0, 15, 180000)
  196.         else
  197.             pUnit:SpawnCreature(AddD, behindGateBX, behindGateBY, behindGateBZ , 0, 15, 180000)
  198.         end
  199.     end
  200.     if gateA ~= nil then
  201.         gateA:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  202.         Open = true
  203.     end
  204.     if gateB ~= nil then
  205.         gateB:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  206.         Open = true
  207.     end
  208.     pUnit:RegisterEvent("Check_For_mobDDeaths_Yarp", 7500, 0)
  209. end
  210.  
  211. function Check_For_mobDDeaths_Yarp(pUnit)
  212.     if Open then
  213.         if gateA ~= nil then
  214.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  215.             Open = false
  216.         end
  217.         if gateB ~= nil then
  218.             gateB:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  219.             Open = false
  220.         end
  221.     end
  222.     if Dead == 20 then
  223.         pUnit:RemoveEvents()
  224.         Wave = Wave + 1
  225.         Dead = 0
  226.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  227.             if plrs:GetPhase() == 2 then
  228.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  229.                 pack:WriteULong(2842) -- ID, total
  230.                 pack:WriteULong(Wave) -- Value
  231.                 plrs:SendPacketToPlayer(pack)
  232.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 5
  233.             end
  234.         end
  235.         pUnit:PlaySoundToSet(15119)
  236.         pUnit:RegisterEvent("WAIT_FOR_THE_RIGHT_MOMENT_DUN_DUN_DEFENDMALL", 7500, 1)
  237.     end
  238. end
  239.  
  240. function WAIT_FOR_THE_RIGHT_MOMENT_DUN_DUN_DEFENDMALL(pUnit)
  241.     local i = 0
  242.     while i ~= 6 do
  243.         i = i + 1
  244.         pUnit:SpawnCreature(AddE, behindGateAX, behindGateAY, behindGateAZ , 0, 15, 380000)
  245.     end
  246.     if gateA ~= nil then
  247.         gateA:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  248.         Open = true
  249.     end
  250.     pUnit:RegisterEvent("CHECK_FOR_DEAD_MALLEVENTgtoustwo", 7500, 0)
  251. end
  252.  
  253. function CHECK_FOR_DEAD_MALLEVENTgtoustwo(pUnit)
  254.     if Open then
  255.         if gateA ~= nil then
  256.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  257.             Open = false
  258.         end
  259.     end
  260.     if Dead == 6 then
  261.         pUnit:RemoveEvents()
  262.         Wave = Wave + 1
  263.         Dead = 0
  264.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  265.             if plrs:GetPhase() == 2 then
  266.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  267.                 pack:WriteULong(2842) -- ID, total
  268.                 pack:WriteULong(Wave) -- Value
  269.                 plrs:SendPacketToPlayer(pack)
  270.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 6
  271.             end
  272.         end
  273.         pUnit:RegisterEvent("WAIT_FOR_THE_RIGHT_MOMENT_DUN_DUN_DEFENDMALLtwo", 7500, 1)
  274.     end
  275. end
  276.  
  277. function WAIT_FOR_THE_RIGHT_MOMENT_DUN_DUN_DEFENDMALLtwo(pUnit)
  278.     local i = 0
  279.     while i ~= 15 do
  280.         i = i + 1
  281.         pUnit:SpawnCreature(AddF, behindGateBX, behindGateBY, behindGateBZ , 0, 15, 280000)
  282.     end
  283.     if gateB ~= nil then
  284.         gateB:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  285.         Open = true
  286.     end
  287.     pUnit:RegisterEvent("CHECK_FOR_DEAD_MALLEVENTaaassssffff", 7500, 0)
  288. end
  289.  
  290. function CHECK_FOR_DEAD_MALLEVENTaaassssffff(pUnit)
  291.     if Open then
  292.         if gateB ~= nil then
  293.             gateB:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  294.             Open = false
  295.         end
  296.     end
  297.     if Dead == 15 then
  298.         pUnit:RemoveEvents()
  299.         Wave = Wave + 1
  300.         Dead = 0
  301.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  302.             if plrs:GetPhase() == 2 then
  303.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  304.                 pack:WriteULong(2842) -- ID, total
  305.                 pack:WriteULong(Wave) -- Value
  306.                 plrs:SendPacketToPlayer(pack)
  307.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 7
  308.             end
  309.         end
  310.         pUnit:RegisterEvent("WAIT_FOR_THE_RIGHT_MOMENT_DUN_DUN_DEFENDMALLgaga", 7500, 1)
  311.     end
  312. end
  313.  
  314. function WAIT_FOR_THE_RIGHT_MOMENT_DUN_DUN_DEFENDMALLgaga(pUnit)
  315.     local i = 0
  316.     while i ~= 4 do
  317.         i = i + 1
  318.         if math.random(1,2) == 1 then
  319.             pUnit:SpawnCreature(AddG, behindGateAX, behindGateAY, behindGateAZ , 0, 15, 480000)
  320.         else
  321.             pUnit:SpawnCreature(AddG, behindGateBX, behindGateBY, behindGateBZ , 0, 15, 480000)
  322.         end
  323.     end
  324.     if gateA ~= nil then
  325.         gateA:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  326.         Open = true
  327.     end
  328.     if gateB ~= nil then
  329.         gateB:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open
  330.         Open = true
  331.     end
  332.     pUnit:RegisterEvent("Check_For_mobDDeaths_Yarpgggggh", 7500, 0)
  333. end
  334.  
  335. function Check_For_mobDDeaths_Yarpgggggh(pUnit)
  336.     if Open then
  337.         if gateA ~= nil then
  338.             gateA:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  339.             Open = false
  340.         end
  341.         if gateB ~= nil then
  342.             gateB:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close
  343.             Open = false
  344.         end
  345.     end
  346.     if Dead == 4 then
  347.         pUnit:RemoveEvents()
  348.         Wave = Wave + 1
  349.         Dead = 0
  350.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  351.             if plrs:GetPhase() == 2 then
  352.                 pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  353.                 pack:WriteULong(2842) -- ID, total
  354.                 pack:WriteULong(Wave) -- Value
  355.                 plrs:SendPacketToPlayer(pack)
  356.                 pUnit:SendChatMessageToPlayer(42, 0, "Wave "..Wave.."!", plrs) -- 8
  357.             end
  358.         end
  359.         pUnit:RegisterEvent("FINALWAVE_DEFENDMALL", 8000, 1)
  360.     end
  361. end
  362.  
  363. function FINALWAVE_DEFENDMALL(pUnit)
  364.     local i = 0
  365.     local pla = nil
  366.     while i ~= 20 do
  367.         i = i + 1
  368.         pla = pUnit:GetRandomPlayer(0)
  369.         if pla ~= nil then
  370.             pUnit:SpawnCreature(AddH, pla:GetX(), pla:GetY(), pla:GetZ(), 0, 15, 300000)
  371.         end
  372.     end
  373.     pUnit:RegisterEvent("WAVES_COMPLETE_BOSS_DUNDUN", 8000, 0)
  374. end
  375.  
  376. function WAVES_COMPLETE_BOSS_DUNDUN(pUnit)
  377.     if Dead == 20 then
  378.         pUnit:RemoveEvents()
  379.         Dead = 0
  380.         Wave = 1
  381.         local Grill = pUnit:GetGameObjectNearestCoords(4522, 2769, 404, 201755) -- x,y,z,id
  382.         if Grill ~= nil then
  383.             Grill:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open Trap
  384.             pUnit:PlaySoundToSet(16541)
  385.             Grill:Despawn(30000, 10000)
  386.         end
  387.         for place, plrs in pairs(pUnit:GetInRangePlayers()) do
  388.             if plrs:GetPhase() == 2 then
  389.                 pUnit:SendChatMessageToPlayer(42, 0, "The way to the boss is clear!", plrs)
  390.             end
  391.         end
  392.     end
  393. end
  394.  
  395. ---------------------------------------------------------
  396. -- Add Scripts ------------------------------------------
  397. ---------------------------------------------------------
  398.  
  399. function Adds_OnSpawn_ohlol(pUnit, Event)
  400.     pUnit:SetPhase(2)
  401.     pUnit:SetMovementFlags(1)
  402.     pUnit:RegisterEvent("SetFaction_Hostile_After_Gate", 2500, 1)
  403.     if pUnit:GetEntry() == AddC then
  404.         pUnit:RegisterEvent("Cast_ADDC_DEFENDMALL", math.random(6000, 12000), 0)
  405.     elseif pUnit:GetEntry() == AddG then
  406.         pUnit:RegisterEvent("CastSoekks_DEFENDMALL", math.random(2000, 12000), 1)
  407.     elseif pUnit:GetEntry() == AddH then
  408.         pUnit:RegisterEvent("SPawnVisual_teoaj", math.random(750, 1500), 1)
  409.     end
  410. end
  411.  
  412. function SetFaction_Hostile_After_Gate(pUnit)
  413.     pUnit:SetPhase(2) -- Just in case
  414.     pUnit:SetMovementFlags(1)
  415.     pUnit:SetFaction(21)
  416.     if math.random(1,2) == 1 then
  417.         pUnit:MoveTo(locA+math.random(0,2),locB-math.random(0,2),locC,0)
  418.     else
  419.         pUnit:MoveTo(locX-math.random(0,2),locY+math.random(0,2),locZ,0)
  420.     end
  421. end
  422.  
  423. function Adds_OnDead_Ohlol(pUnit)
  424.     pUnit:RemoveEvents()
  425.     Dead = Dead + 1
  426. end
  427.  
  428. function Cast_ADDC_DEFENDMALL(pUnit)
  429.     pUnit:FullCastSpell(36132) -- Normal damage + 300 for two strong adds
  430. end
  431.  
  432. function CastSoekks_DEFENDMALL(pUnit)
  433.     pUnit:CastSpell(15636) -- Avatar of flame
  434. end
  435.  
  436. function SPawnVisual_teoaj(pUnit)
  437.     pUnit:CastSpell(64446) -- Teleport visual
  438. end
  439.  
  440. RegisterUnitEvent(AddA, 18, "Adds_OnSpawn_ohlol")
  441. RegisterUnitEvent(AddB, 18, "Adds_OnSpawn_ohlol")
  442. RegisterUnitEvent(AddC, 18, "Adds_OnSpawn_ohlol")
  443. RegisterUnitEvent(AddD, 18, "Adds_OnSpawn_ohlol")
  444. RegisterUnitEvent(AddE, 18, "Adds_OnSpawn_ohlol")
  445. RegisterUnitEvent(AddF, 18, "Adds_OnSpawn_ohlol")
  446. RegisterUnitEvent(AddG, 18, "Adds_OnSpawn_ohlol")
  447. RegisterUnitEvent(AddH, 18, "Adds_OnSpawn_ohlol")
  448.  
  449. RegisterUnitEvent(AddA, 4, "Adds_OnDead_Ohlol")
  450. RegisterUnitEvent(AddB, 4, "Adds_OnDead_Ohlol")
  451. RegisterUnitEvent(AddC, 4, "Adds_OnDead_Ohlol")
  452. RegisterUnitEvent(AddD, 4, "Adds_OnDead_Ohlol")
  453. RegisterUnitEvent(AddE, 4, "Adds_OnDead_Ohlol")
  454. RegisterUnitEvent(AddF, 4, "Adds_OnDead_Ohlol")
  455. RegisterUnitEvent(AddG, 4, "Adds_OnDead_Ohlol")
  456. RegisterUnitEvent(AddH, 4, "Adds_OnDead_Ohlol")
  457.  
  458. ---------------------------------------------------------
  459. -- Boss -------------------------------------------------
  460. ---------------------------------------------------------
  461.  
  462. -- Not Started
  463.  
  464. ---------------------------------------------------------
  465.  
  466. --[[
  467.     Debug Below
  468.         Comment out later
  469. ]]
  470.  
  471. function OnChat_Hook_ToJoinBG(event, plr, message, pType, pLanguage, pMisc)
  472.     local message = string.lower(message)
  473.     if message == "test" then
  474.         local object = plr:GetGameObjectNearestCoords(4522, 2769, 404, 201755) -- x,y,z,id
  475.         if object ~= nil then
  476.             object:SetByte(GAMEOBJECT_BYTES_1,0,0) -- Open WORKSSSSS
  477.             plr:PlaySoundToSet(16541)
  478.         end
  479.     end
  480.     if message == "fix" then
  481.         local object = plr:GetGameObjectNearestCoords(4522, 2769, 404, 201755) -- x,y,z,id
  482.         if object ~= nil then
  483.             object:SetByte(GAMEOBJECT_BYTES_1,0,1) -- Close, buggy
  484.         end
  485.     end
  486.     if message == "#start" then
  487.         CanStart = true
  488.     end
  489. end
  490.  
  491. RegisterServerHook(16, "OnChat_Hook_ToJoinBG")
  492.  
  493. ---------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment