stoneharry

Untitled

May 5th, 2012
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.81 KB | None | 0 0
  1. ------------------------------------------------------------------
  2. --[[
  3.     This script was made by Stoneharry
  4.     This script may be edited and changed at will, but full credits must be provided.
  5.     Please respect the original author, thank you.
  6. ]]
  7.  
  8. ------------------------------------------------------------------
  9. --[[
  10.  
  11.     SQL Queries used while creating this script:
  12.  
  13.     UPDATE `worldmap_info` SET `viewingDistance` = '900' WHERE `entry` = '631';
  14.  
  15. ]]
  16. ------------------------------------------------------------------
  17.  
  18. -- Variable declaration and generally setting up the script
  19.  
  20. local TirionNPCID = 38995
  21. local LichKingNPCID = 36597
  22.  
  23. -- For 3.3.5a
  24. local OBJECT_END = 0x0006
  25. local UNIT_NPC_FLAGS = OBJECT_END + 0x004C
  26. local UNIT_FIELD_FLAGS = OBJECT_END + 0x0035
  27. local UNIT_FIELD_BYTES_1 = OBJECT_END + 0x0044
  28. local UNIT_FLAG_NOT_SELECTABLE = 0x02000000
  29. local SMSG_INIT_WORLD_STATES = 0x2C2
  30. local SMSG_UPDATE_WORLD_STATE = 0x2C3
  31. local GAMEOBJECT_FLAGS = OBJECT_END + 0x0003
  32.  
  33. -- Unconfigurable Variables
  34.  
  35. ICC = {}
  36. ICC.VAR = {}
  37.  
  38. ------------------------------------------------------------------
  39. -- The gossip used to start the encounter - Tirion ---------------
  40. -- Also set up events etc ----------------------------------------
  41. ------------------------------------------------------------------
  42.  
  43. function ICC.VAR.Tirion_OnGossipTalk(pUnit, Event, player)
  44.     pUnit:GossipCreateMenu(2975252, player, 0)
  45.     pUnit:GossipMenuAddItem(9, "We are prepared, Highlord. Let us battle for the fate of Azeroth! For the light of dawn!", 1, 0)
  46.     pUnit:GossipMenuAddItem(0, "We are not yet prepared, Highlord.", 2, 0)
  47.     pUnit:GossipSendMenu(player)
  48. end
  49.  
  50. function ICC.VAR.Tirion_OnGossipSelect(pUnit, Event, player, id, code)
  51.     if (id == 1) then
  52.         local id = pUnit:GetInstanceID()
  53.         ICC[id] = ICC[id] or {VAR={}}
  54.         ICC[id].VAR.Tirion = pUnit
  55.         ICC[id].VAR.Ready = true
  56.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_NPC_FLAGS, 2) -- Quest flags disable gossip
  57.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable, used to prevent LK hitting him instead of players
  58.     end
  59.     player:GossipComplete()
  60. end
  61.  
  62. RegisterUnitGossipEvent(TirionNPCID, 1, "ICC.VAR.Tirion_OnGossipTalk")
  63. RegisterUnitGossipEvent(TirionNPCID, 2, "ICC.VAR.Tirion_OnGossipSelect")
  64.  
  65. function ICC.VAR.OnSpawnHandleStart(pUnit, Event)
  66.     pUnit:SetUInt32Value(UNIT_NPC_FLAGS, 1) -- Gossip Flags, for when the fight resets
  67.     -- This function does not seem to get all the objects required
  68.     --[[for k,objects in pairs(pUnit:GetInRangeObjects()) do
  69.         if objects ~= nil then
  70.             local flags = objects:SetUInt32Value(GAMEOBJECT_FLAGS,0x1)
  71.             if flags ~= nil then
  72.                 if(bit_and(flags,0x1) == 0 or bit_and(flags, 0x2) ~= 0) then
  73.                     objects:SetUInt32Value(GAMEOBJECT_FLAGS,0x1)
  74.                 end
  75.             end
  76.         end
  77.     end]]
  78.     pUnit:RegisterEvent("ICC.VAR.CheckForStart", 2500, 0)
  79. end
  80.  
  81. RegisterUnitEvent(TirionNPCID, 18, "ICC.VAR.OnSpawnHandleStart")
  82.  
  83. function ICC.VAR.OnSpawnHandleDefineAndBytes(pUnit, Event)
  84.     pUnit:RegisterEvent("ICC.VAR.SetBytesAndHandleVariable", 2000, 1)
  85. end
  86.  
  87. function ICC.VAR.SetBytesAndHandleVariable(pUnit)
  88.     local id = pUnit:GetInstanceID()
  89.     ICC[id] = ICC[id] or {VAR={}}
  90.     ICC[id].VAR.Lich = pUnit
  91.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 1) -- Sit on the throne
  92.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable
  93. end
  94.  
  95. RegisterUnitEvent(LichKingNPCID, 18, "ICC.VAR.OnSpawnHandleDefineAndBytes")
  96.  
  97. ------------------------------------------------------------------
  98. -- Mini-cinematic at the start -----------------------------------
  99. ------------------------------------------------------------------
  100.  
  101. function ICC.VAR.CheckForStart(pUnit)
  102.     local id = pUnit:GetInstanceID()
  103.     ICC[id] = ICC[id] or {VAR={}}
  104.     if (ICC[id].VAR.Ready and ICC[id].VAR.Lich ~= nil) then
  105.         ICC[id].VAR.Ready = false
  106.         ICC[id].VAR.i = 0
  107.         ICC[id].VAR.Tirion:RemoveEvents()
  108.         ICC[id].VAR.Tirion:MoveTo(489.14, -2124.45, 1040.9, 0) -- Closer to LK
  109.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 7500, 1)
  110.     end
  111. end
  112.  
  113. function ICC.VAR.WalkTowardsLichKingThenEmotes(pUnit)
  114.     local id = pUnit:GetInstanceID()
  115.     if (ICC[id].VAR.i == 0) then
  116.         ICC[id].VAR.Tirion:Emote(375, 58500)
  117.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 0) -- Stand up
  118.         ICC[id].VAR.Tirion:PlaySoundToSet(17349) -- Voice of message - Tirion since players are closer to him
  119.         ICC[id].VAR.Tirion:PlaySoundToSet(17457) -- The music for this point
  120.         ICC[id].VAR.Lich:SendChatMessage(14, 0, "So... the Light's vaunted justice has finally arrived. Shall I lay down Frostmourne and throw myself at your mercy, Fordring?")
  121.         ICC[id].VAR.Lich:StopMovement(0) -- Resets bytes bug
  122.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 4000, 1)
  123.     elseif (ICC[id].VAR.i == 1) then
  124.         ICC[id].VAR.Lich:StopMovement(0) -- Resets bytes bug
  125.         ICC[id].VAR.Lich:MoveTo(457.44, -2123.86, 1041.2, 0) -- Down from throne to floor
  126.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 10000, 1)
  127.     elseif (ICC[id].VAR.i == 2) then
  128.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"We will grant you a swift death, Arthas. More than can be said for the thousands you've tortured and slain.")
  129.         ICC[id].VAR.Tirion:PlaySoundToSet(17390)
  130.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 2000, 1)
  131.     elseif (ICC[id].VAR.i == 3) then
  132.         ICC[id].VAR.Lich:MoveTo(462.01, -2124.146, 1040.9, 0) -- Forwards slightly to correct position
  133.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 8500, 1)
  134.     elseif (ICC[id].VAR.i == 4) then
  135.         ICC[id].VAR.Lich:SendChatMessage(14,0,"You will learn of that first hand. When my work is complete, you will beg for mercy -- and I will deny you. Your anguished cries will be testament to my unbridled power.")
  136.         ICC[id].VAR.Tirion:PlaySoundToSet(17350)
  137.         ICC[id].VAR.Lich:Emote(397, 4000)
  138.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 4500, 1)
  139.     elseif (ICC[id].VAR.i == 5) then
  140.         ICC[id].VAR.Lich:Emote(1, 6000)
  141.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 12000, 1)
  142.     elseif (ICC[id].VAR.i == 6) then
  143.         ICC[id].VAR.Lich:Emote(392, 3500)
  144.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 7500, 1)
  145.     elseif (ICC[id].VAR.i == 7) then
  146.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"So be it. Champions, attack!")
  147.         ICC[id].VAR.Tirion:PlaySoundToSet(17391)
  148.         ICC[id].VAR.Tirion:Emote(397, 2000)
  149.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 2000, 1)
  150.     elseif (ICC[id].VAR.i == 8) then
  151.         ICC[id].VAR.Tirion:SetMovementFlags(1) -- Run
  152.         ICC[id].VAR.Tirion:MoveTo(472.88, -2124.2, 1040.9, 0) -- Run towards LK
  153.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 1000, 1)
  154.     elseif (ICC[id].VAR.i == 9) then
  155.         ICC[id].VAR.Lich:SendChatMessage(14,0,"I'll keep you alive to witness the end, Fordring. I would not want the Light's greatest champion to miss seeing this wretched world remade in my image.")
  156.         ICC[id].VAR.Tirion:PlaySoundToSet(17351)
  157.         ICC[id].VAR.Tirion:RegisterEvent("ICC.VAR.WalkTowardsLichKingThenEmotes", 500, 1)
  158.     elseif (ICC[id].VAR.i == 10) then
  159.         ICC[id].VAR.Lich:CastSpellOnTarget(71614, ICC[id].VAR.Tirion) -- Freeze
  160.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 0) -- Attackable
  161.     end
  162.     ICC[id].VAR.i = ICC[id].VAR.i + 1
  163. end
  164.  
  165. ------------------------------------------------------------------
  166. -- The Fight -----------------------------------------------------
  167. ------------------------------------------------------------------
  168.  
  169. function ICC.VAR.OnEnterCombatStuff(pUnit, Event)
  170.     local id = pUnit:GetInstanceID()
  171.     ICC[id] = ICC[id] or {VAR={}}
  172.     if id == nil then id = 0 end
  173.     -- This will only be nil if one enters combat with the lich king in less than 2.5 seconds of spawn
  174.     if ICC[id].VAR.Lich ~= nil then
  175.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.CheckForFinalPhase", 2500, 0)
  176.     end
  177. end
  178.  
  179. function ICC.VAR.CheckForFinalPhase(pUnit)
  180.     local id = pUnit:GetInstanceID()
  181.     if (ICC[id].VAR.Lich:GetHealthPct() < 11) then
  182.         ICC[id].VAR.Lich:RemoveEvents()
  183.         ICC[id].VAR.Lich:SendChatMessage(14,0,"You gnats actually hurt me! Perhaps I've toyed with you long enough, now taste the vengeance of the grave!")
  184.         ICC[id].VAR.Lich:PlaySoundToSet(17359)
  185.         ICC[id].VAR.Lich:SetMovementFlags(1)
  186.         ICC[id].VAR.Lich:MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  187.         ICC[id].VAR.Lich:AIDisableCombat(true) -- Requires custom patch to work
  188.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.Lich_KeepMoving", 500, 2) -- Just to make sure he stays on the right tracks, though disabling combat above should work
  189.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.Lich_KillAll", 5005, 1)
  190.     end
  191. end
  192.  
  193. function ICC.VAR.Lich_KeepMoving(pUnit)
  194.     local id = pUnit:GetInstanceID()
  195.     ICC[id].VAR.Lich:MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  196. end
  197.  
  198. function ICC.VAR.Lich_KillAll(pUnit)
  199.     local id = pUnit:GetInstanceID()
  200.     ICC[id].VAR.Lich:Root()
  201.     ICC[id].VAR.ForceWiped = true
  202.     ICC[id].VAR.Lich:FullCastSpell(70063) -- Wipe the raid - fury of frostmourne
  203.     ICC[id].VAR.i = 0
  204.     ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 10000, 1)
  205. end
  206.  
  207. RegisterUnitEvent(LichKingNPCID, 1, "ICC.VAR.OnEnterCombatStuff")
  208.  
  209. function ICC.VAR.OnWipeEvents(pUnit, Event)
  210.     local id = pUnit:GetInstanceID()
  211.     ICC[id] = ICC[id] or {VAR={}}
  212.     if not ICC[id].VAR.ForceWiped then -- it didn't wipe via fury of frostmourne
  213.         ICC[id].VAR.Lich:RemoveEvents()
  214.         if Event == 2 then
  215.             pUnit:Despawn(2000, 10000)
  216.         elseif Event == 4 then
  217.             -- He died
  218.         end
  219.     end
  220. end
  221.  
  222. RegisterUnitEvent(LichKingNPCID, 2, "ICC.VAR.OnWipeEvents")
  223. RegisterUnitEvent(LichKingNPCID, 4, "ICC.VAR.OnWipeEvents")
  224.  
  225. ------------------------------------------------------------------
  226. -- Death Cinematic -----------------------------------------------
  227. ------------------------------------------------------------------
  228.  
  229. function ICC.VAR.DeathCinematic_Lich(pUnit)
  230.     local id = pUnit:GetInstanceID()
  231.     if (ICC[id].VAR.i == 0) then
  232.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable, used to prevent Tirion hitting LK during the Dragonball Z moment
  233.         ICC[id].VAR.Tirion:Root() -- Stop stop him resetting position
  234.         ICC[id].VAR.Lich:SendChatMessage(14,0,"No question remains unanswered. No doubts linger. You are Azeroth's greatest champions! You overcame every challenge I laid before you. My mightiest servants have fallen before your relentless onslaught, your unbridled fury...")
  235.         ICC[id].VAR.Lich:PlaySoundToSet(17353)
  236.         ICC[id].VAR.Lich:WipeTargetList() -- reset targets
  237.         ICC[id].VAR.Lich:SetFacing(0.01745329)
  238.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 25000, 1)
  239.     elseif (ICC[id].VAR.i == 1) then
  240.         ICC[id].VAR.Lich:SendChatMessage(14,0,"You trained them well, Fordring. You delivered the greatest fighting force this world has ever known... right into my hands -- exactly as I intended. You shall be rewarded for your unwitting sacrifice.")
  241.         ICC[id].VAR.Lich:PlaySoundToSet(17355) -- text
  242.         ICC[id].VAR.Lich:PlaySoundToSet(17460) -- final music
  243.         ICC[id].VAR.Lich:FullCastSpell(71769) -- visual to raise players
  244.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 24000, 1)
  245.     elseif (ICC[id].VAR.i == 2) then
  246.         ICC[id].VAR.Lich:SendChatMessage(14,0,"Watch now as I raise them from the dead to become masters of the Scourge. They will shroud this world in chaos and destruction. Azeroth's fall will come at their hands -- and you will be the first to die.")
  247.         ICC[id].VAR.Lich:PlaySoundToSet(17356)
  248.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 26000, 1)
  249.     elseif (ICC[id].VAR.i == 3) then
  250.         ICC[id].VAR.Lich:PlaySoundToSet(17357)
  251.         ICC[id].VAR.Lich:SendChatMessage(14,0,"I delight in the irony.", 0)
  252.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 6000, 1)
  253.     elseif (ICC[id].VAR.i == 4) then
  254.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"LIGHT, GRANT ME ONE FINAL BLESSING. GIVE ME THE STRENGTH... TO SHATTER THESE BONDS!")
  255.         ICC[id].VAR.Tirion:PlaySoundToSet(17392)
  256.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 9000, 1)
  257.     elseif (ICC[id].VAR.i == 5) then
  258.         --ICC[id].VAR.Tirion:RemoveAura(71614) -- Ice block
  259.         ICC[id].VAR.Tirion:CastSpell(71797) -- Light visual
  260.         --ICC[id].VAR.Tirion:CastSpell(71614) -- IceBlock visual
  261.         ICC[id].VAR.Lich:RegisterEvent("ICC.VAR.DeathCinematic_Lich", 8000, 1)
  262.     elseif (ICC[id].VAR.i == 6) then
  263.         ICC[id].VAR.Tirion:RemoveAura(71614) -- Ice block
  264.         ICC[id].VAR.Tirion:EquipWeapons(50442, 0, 0) -- Glowing Ashbringer
  265.     end
  266.     ICC[id].VAR.i = ICC[id].VAR.i + 1
  267. end
  268.  
  269.  
  270.  
  271. ------------------------------------------------------------------
  272. -- Misc Stuff ----------------------------------------------------
  273. ------------------------------------------------------------------
  274.  
  275. -- Handle the ICC buffs and when to change worldstates
  276.  
  277. function ICC.VAR.OnZoneChange(event, player, zone, oldzone)
  278.     local race = player:GetPlayerRace()
  279.     if (zone == 4812) then
  280.         UpdateWorldstatesUI(player)
  281.         local id = player:GetInstanceID()
  282.         ICC[id] = ICC[id] or {VAR={}}
  283.         UpdateAttempts(player, id)
  284.         player:CastSpell(69127) -- Chill of the Throne
  285.         player:CastSpell(69127) -- Hack'y way of applying the correct aura types.
  286.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  287.             player:CastSpell(73828) -- Strength of Wyrn
  288.         else
  289.             player:CastSpell(73822) -- Hellscreem's warsong
  290.         end
  291.     elseif (oldzone == 4812) then
  292.         ResetWorldstatesUI(player)
  293.         player:RemoveAura(69127) -- Chill of the Throne
  294.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  295.             player:RemoveAura(73828) -- Strength of Wyrn
  296.         else
  297.             player:RemoveAura(73822) -- Hellscreem's warsong
  298.         end
  299.     end
  300. end
  301.  
  302. RegisterServerHook(15, "ICC.VAR.OnZoneChange")
  303.  
  304. -- Handle the worldstates
  305.  
  306. function UpdateWorldstatesUI(player)
  307.     local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18)
  308.     pack:WriteULong(631) -- Map
  309.     pack:WriteULong(4859) -- Zone
  310.     pack:WriteULong(0)
  311.     pack:WriteUShort(2)
  312.     pack:WriteULong(4940) -- ID
  313.     pack:WriteULong(1) -- Value
  314.     player:SendPacketToPlayer(pack)
  315. end
  316.  
  317. function UpdateAttempts(player, id)
  318.     if ICC[id].VAR.Attempts == nil then
  319.         ICC[id].VAR.Attempts = 20
  320.     end
  321.     local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  322.     pack:WriteULong(4941) -- ID, X/
  323.     pack:WriteULong(ICC[id].VAR.Attempts) -- Value
  324.     player:SendPacketToPlayer(pack)
  325.     local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
  326.     pack:WriteULong(4942) -- ID, /X
  327.     pack:WriteULong(ICC[id].VAR.Attempts) -- Value
  328.     player:SendPacketToPlayer(pack)
  329. end
  330.  
  331. function ResetWorldstatesUI(player)
  332.     local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18)
  333.     pack:WriteULong(0) -- Map
  334.     pack:WriteULong(0) -- Zone
  335.     pack:WriteULong(0)
  336.     pack:WriteUShort(0)
  337.     pack:WriteULong(0) -- ID
  338.     pack:WriteULong(0) -- Value
  339.     player:SendPacketToPlayer(pack)
  340. end
  341.  
  342. ------------------------------------------------------------------
Add Comment
Please, Sign In to add comment