stoneharry

Untitled

Sep 18th, 2011
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.75 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. -- Variable declaration and generally setting up the script
  8. --?!MAP= 631
  9.  
  10. local TirionNPCID = 38995
  11. local LichKingNPCID = 36597
  12.  
  13. -- For 3.3.5a
  14. local OBJECT_END = 0x0006
  15. local UNIT_NPC_FLAGS = OBJECT_END + 0x004C
  16. local UNIT_FIELD_FLAGS = OBJECT_END + 0x0035
  17. local UNIT_FIELD_BYTES_1 = OBJECT_END + 0x0044
  18. local UNIT_FLAG_NOT_SELECTABLE = 0x02000000
  19. local SMSG_INIT_WORLD_STATES = 0x2C2
  20. local SMSG_UPDATE_WORLD_STATE = 0x2C3
  21.  
  22. -- Unconfigurable Variables
  23.  
  24. local CheckForStart
  25. local WalkTowardsLichKingThenEmotes
  26. local SetBytesAndHandleVariable
  27. local KeepMoving
  28. local KillAll
  29. local CheckForFinalPhase
  30. local DeathCinematic
  31.  
  32. ICC = {}
  33. ICC.VAR = {}
  34.  
  35. ------------------------------------------------------------------
  36. -- The gossip used to start the encounter - Tirion ---------------
  37. -- Also set up events etc ----------------------------------------
  38. ------------------------------------------------------------------
  39.  
  40. local function OnGossipTalk(pUnit, Event, player)
  41.     local menu = GossipMenu(pUnit, 2975252, 1)
  42.     menu:AddItem(9, "We are prepared, Highlord. Let us battle for the fate of Azeroth! For the light of dawn!", 1, false)
  43.     menu:AddItem(0, "We are not yet prepared, Highlord.", 2, false)
  44.     menu:Send(player)
  45. end
  46.  
  47. local function OnGossipSelect(pUnit, Event, player, id, code)
  48.     if (id == 1) then
  49.         local id = MapMgr:GetInstanceID()
  50.         ICC[id] = ICC[id] or {VAR={}}
  51.         ICC[id].VAR.Tirion = pUnit
  52.         ICC[id].VAR.Ready = true
  53.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_NPC_FLAGS, 2) -- Quest flags disable gossip
  54.         ICC[id].VAR.Tirion:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable, used to prevent LK hitting him instead of players
  55.         -- Gossip complete
  56.     elseif (id == 2) then
  57.         -- Gossip complete
  58.     end
  59. end
  60.  
  61. RegisterUnitGossipEvent(TirionNPCID, 1, OnGossipTalk)
  62. RegisterUnitGossipEvent(TirionNPCID, 2, OnGossipSelect)
  63.  
  64. local function OnSpawnHandleStart(pUnit, Event)
  65.     pUnit:SetUInt32Value(UNIT_NPC_FLAGS, 1) -- Gossip Flags, for when the fight resets
  66.     pUnit:RegisterEvent(CheckForStart, 2500, 1) -- Setting repeat to 0 only calls once for some reason
  67. end
  68.  
  69. RegisterUnitEvent(TirionNPCID, 18, OnSpawnHandleStart)
  70.  
  71. local function OnSpawnHandleDefineAndBytes(pUnit, Event)
  72.     pUnit:RegisterEvent(SetBytesAndHandleVariable, 2000, 1)
  73. end
  74.  
  75. function SetBytesAndHandleVariable(pUnit)
  76.     local id = MapMgr:GetInstanceID()
  77.     ICC[id] = ICC[id] or {VAR={}}
  78.     ICC[id].VAR.Lich = pUnit
  79.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 1) -- Sit on the throne
  80.     ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 2) -- Unattackable
  81. end
  82.  
  83. RegisterUnitEvent(LichKingNPCID, 18, OnSpawnHandleDefineAndBytes)
  84.  
  85. ------------------------------------------------------------------
  86. -- Mini-cinematic at the start -----------------------------------
  87. ------------------------------------------------------------------
  88.  
  89. function CheckForStart(pUnit)
  90.     local id = MapMgr:GetInstanceID()
  91.     ICC[id] = ICC[id] or {VAR={}}
  92.     if (ICC[id].VAR.Ready and ICC[id].VAR.Lich ~= nil) then
  93.         ICC[id].VAR.Ready = false
  94.         ICC[id].VAR.i = 0
  95.         ICC[id].VAR.Tirion:GetAIInterface():MoveTo(489.14, -2124.45, 1040.9, 0) -- Closer to LK
  96.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 7500, 1)
  97.     else
  98.         pUnit:RegisterEvent(CheckForStart, 2500, 1)
  99.     end
  100. end
  101.  
  102. function WalkTowardsLichKingThenEmotes(pUnit)
  103.     local id = MapMgr:GetInstanceID()
  104.     if (ICC[id].VAR.i == 0) then
  105.         ICC[id].VAR.Tirion:EventAddEmote(375, 58500)
  106.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_BYTES_1, 0) -- Stand up
  107.         PlaySoundToSet(ICC[id].VAR.Tirion, 17349) -- Voice of message - Tirion since players are closer to him
  108.         PlaySoundToSet(ICC[id].VAR.Tirion, 17457) -- The music for this point
  109.         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?", 0)
  110.         ICC[id].VAR.Lich:GetAIInterface():StopMovement(0) -- Resets bytes bug
  111.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 4000, 1)
  112.     elseif (ICC[id].VAR.i == 1) then
  113.         ICC[id].VAR.Lich:GetAIInterface():StopMovement(0) -- Resets bytes bug
  114.         ICC[id].VAR.Lich:GetAIInterface():MoveTo(457.44, -2123.86, 1041.2, 0) -- Down from throne to floor
  115.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 10000, 1)
  116.     elseif (ICC[id].VAR.i == 2) then
  117.         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.", 0)
  118.         PlaySoundToSet(ICC[id].VAR.Tirion, 17390)
  119.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 2000, 1)
  120.     elseif (ICC[id].VAR.i == 3) then
  121.         ICC[id].VAR.Lich:GetAIInterface():MoveTo(462.01, -2124.146, 1040.9, 0) -- Forwards slightly to correct position
  122.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 8500, 1)
  123.     elseif (ICC[id].VAR.i == 4) then
  124.         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.", 0)
  125.         PlaySoundToSet(ICC[id].VAR.Tirion, 17350)
  126.         ICC[id].VAR.Lich:EventAddEmote(397, 4000)
  127.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 4500, 1)
  128.     elseif (ICC[id].VAR.i == 5) then
  129.         ICC[id].VAR.Lich:EventAddEmote(1, 6000)
  130.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 12000, 1)
  131.     elseif (ICC[id].VAR.i == 6) then
  132.         ICC[id].VAR.Lich:EventAddEmote(392, 3500)
  133.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 7500, 1)
  134.     elseif (ICC[id].VAR.i == 7) then
  135.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"So be it. Champions, attack!", 0)
  136.         PlaySoundToSet(ICC[id].VAR.Tirion, 17391)
  137.         ICC[id].VAR.Tirion:EventAddEmote(397, 2000)
  138.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 2000, 1)
  139.     elseif (ICC[id].VAR.i == 8) then
  140.         ICC[id].VAR.Tirion:GetAIInterface():setMoveRunFlag(true)
  141.         ICC[id].VAR.Tirion:GetAIInterface():MoveTo(472.88, -2124.2, 1040.9, 0) -- Run towards LK
  142.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 1000, 1)
  143.     elseif (ICC[id].VAR.i == 9) then
  144.         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.", 0)
  145.         PlaySoundToSet(ICC[id].VAR.Tirion, 17351)
  146.         ICC[id].VAR.Tirion:RegisterEvent(WalkTowardsLichKingThenEmotes, 500, 1)
  147.     elseif (ICC[id].VAR.i == 10) then
  148.         ICC[id].VAR.Lich:CastSpell(ICC[id].VAR.Tirion, 71614, false) -- Freeze
  149.         ICC[id].VAR.Lich:SetUInt32Value(UNIT_FIELD_FLAGS, 0) -- Attackable
  150.     end
  151.     ICC[id].VAR.i = ICC[id].VAR.i + 1
  152. end
  153.  
  154. ------------------------------------------------------------------
  155. -- The Fight -----------------------------------------------------
  156. ------------------------------------------------------------------
  157.  
  158. local function OnEnterCombatStuff(pUnit, Event)
  159.     local id = MapMgr:GetInstanceID()
  160.     -- This will only be nil if one enters combat with the lich king in less than 2.5 seconds of spawn
  161.     ICC[id].VAR.Lich:RegisterEvent(CheckForFinalPhase, 2500, 1) -- Repeat 0 only checks once for some reason
  162. end
  163.  
  164. function CheckForFinalPhase(pUnit)
  165.     local id = MapMgr:GetInstanceID()
  166.     if (ICC[id].VAR.Lich:GetHealthPct() < 11) then
  167.         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!", 0)
  168.         PlaySoundToSet(ICC[id].VAR.Lich, 17359)
  169.         ICC[id].VAR.Lich:GetAIInterface():setMoveRunFlag(true)
  170.         ICC[id].VAR.Lich:GetAIInterface():MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  171.         ICC[id].VAR.Lich:GetAIInterface().disable_combat = true
  172.         ICC[id].VAR.Lich:RegisterEvent(KeepMoving, 500, 10) -- Just to make sure he stays on the right tracks, though disabling combat above should work
  173.         ICC[id].VAR.Lich:RegisterEvent(KillAll, 5005, 1)
  174.     else
  175.         ICC[id].VAR.Lich:RegisterEvent(CheckForFinalPhase, 2500, 1)
  176.     end
  177. end
  178.  
  179. function KeepMoving(pUnit)
  180.     local id = MapMgr:GetInstanceID()
  181.     ICC[id].VAR.Lich:GetAIInterface():MoveTo(505.212, -2124.35, 1040.95, 0) -- Center of the room
  182. end
  183.  
  184. function KillAll(pUnit)
  185.     local id = MapMgr:GetInstanceID()
  186.     ICC[id].VAR.Lich:GetAIInterface().canmove = false
  187.     ICC[id].VAR.Lich:CastSpell(ICC[id].VAR.Lich, 70063, false) -- Wipe the raid - fury of frostmourne
  188.     ICC[id].VAR.i = 0
  189.     ICC[id].VAR.Lich:RegisterEvent(DeathCinematic, 10000, 1)
  190. end
  191.  
  192. RegisterUnitEvent(LichKingNPCID, 1, OnEnterCombatStuff)
  193.  
  194. ------------------------------------------------------------------
  195. -- Death Cinematic -----------------------------------------------
  196. ------------------------------------------------------------------
  197.  
  198. function DeathCinematic(pUnit)
  199.     local id = MapMgr:GetInstanceID()
  200.     if (ICC[id].VAR.i == 0) then
  201.         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...", 0)
  202.         PlaySoundToSet(ICC[id].VAR.Lich, 17353)
  203.         ICC[id].VAR.Lich:RegisterEvent(DeathCinematic, 25000, 1)
  204.     elseif (ICC[id].VAR.i == 1) then
  205.         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.", 0)
  206.         PlaySoundToSet(ICC[id].VAR.Lich, 17355)
  207.         ICC[id].VAR.Lich:CastSpell(ICC[id].VAR.Lich, 71769, false) -- Raise dead, will crash server if used
  208.         ICC[id].VAR.Lich:RegisterEvent(DeathCinematic, 24000, 1)
  209.     elseif (ICC[id].VAR.i == 2) then
  210.         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.", 0)
  211.         PlaySoundToSet(ICC[id].VAR.Lich, 17356)
  212.         ICC[id].VAR.Lich:RegisterEvent(DeathCinematic, 26000, 1)
  213.     elseif (ICC[id].VAR.i == 3) then
  214.         PlaySoundToSet(ICC[id].VAR.Lich, 17357)
  215.         ICC[id].VAR.Lich:SendChatMessage(14,0,"I delight in the irony.", 0)
  216.         ICC[id].VAR.Lich:RegisterEvent(DeathCinematic, 6000, 1)
  217.     elseif (ICC[id].VAR.i == 4) then
  218.         ICC[id].VAR.Tirion:SendChatMessage(14,0,"LIGHT, GRANT ME ONE FINAL BLESSING. GIVE ME THE STRENGTH... TO SHATTER THESE BONDS!", 0)
  219.         PlaySoundToSet(ICC[id].VAR.Tirion, 17392)
  220.         ICC[id].VAR.Lich:RegisterEvent(DeathCinematic, 9000, 1)
  221.     elseif (ICC[id].VAR.i == 5) then
  222.         ICC[id].VAR.Tirion:RemoveAura(71614) -- Ice block
  223.         -- Will have to have invisible npc cast the light visual spell on tirion then tirion to cast end bit
  224.         ICC[id].VAR.Tirion:CastSpell(ICC[id].VAR.Tirion, 71797, false) -- Light visual
  225.         ICC[id].VAR.Tirion:CastSpell(ICC[id].VAR.Tirion, 71614, true) -- IceBlock visual
  226.         ICC[id].VAR.Lich:RegisterEvent(DeathCinematic, 8000, 1)
  227.     elseif (ICC[id].VAR.i == 6) then
  228.         ICC[id].VAR.Tirion:RemoveAura(71614) -- Ice block
  229.         -- ICC[id].VAR.Tirion:EquipWeapons(50442, 0, 0) -- Glowing Ashbringer - no yet added to LuaBridge
  230.     end
  231.     ICC[id].VAR.i = ICC[id].VAR.i + 1
  232. end
  233.  
  234.  
  235.  
  236. ------------------------------------------------------------------
  237. -- Misc Stuff ----------------------------------------------------
  238. ------------------------------------------------------------------
  239.  
  240. -- Handle the ICC buffs and when to change worldstates
  241.  
  242. local function OnZoneChange(event, player, zone, oldzone)
  243.     local race = player:getRace()
  244.     if (zone == 4812) then
  245.         UpdateWorldstatesUI(player)
  246.         local id = MapMgr:GetInstanceID()
  247.         ICC[id] = ICC[id] or {VAR={}}
  248.         UpdateAttempts(player, id)
  249.         player:CastSpell(player, 69127, true) -- Chill of the Throne
  250.         player:CastSpell(player, 69127, true) -- Hack'y way of applying the correct aura types.
  251.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  252.             player:CastSpell(player, 73828, true) -- Strength of Wyrn
  253.         else
  254.             player:CastSpell(player, 73822, true) -- Hellscreem's warsong
  255.         end
  256.     elseif (oldzone == 4812) then
  257.         ResetWorldstatesUI(player)
  258.         player:RemoveAura(69127) -- Chill of the Throne
  259.         if (race == 1 or race == 3 or race == 4 or race == 7 or race == 11) then
  260.             player:RemoveAura(73828) -- Strength of Wyrn
  261.         else
  262.             player:RemoveAura(73822) -- Hellscreem's warsong
  263.         end
  264.     end
  265. end
  266.  
  267. RegisterServerHook(15, OnZoneChange)
  268.  
  269. -- Playing sounds to set
  270.  
  271. function PlaySoundToSet(object, ID)
  272.     local pack = LuaPacket(722, 4)
  273.     pack:WriteUint32(ID)
  274.     object:SendMessageToSet(pack, true)
  275. end
  276.  
  277. -- Handle the worldstates
  278.  
  279. function UpdateWorldstatesUI(player)
  280.     local pack = LuaPacket(SMSG_INIT_WORLD_STATES, 18)
  281.     pack:WriteUint32(631) -- Map
  282.     pack:WriteUint32(4859) -- Zone
  283.     pack:WriteUint32(0)
  284.     pack:WriteUInt16(2)
  285.     pack:WriteUint32(4940) -- ID
  286.     pack:WriteUint32(1) -- Value
  287.     TO_PLAYER(player):SendPacket(pack)
  288. end
  289.  
  290. function UpdateAttempts(player, id)
  291.     if ICC[id].VAR.Attempts == nil then
  292.         ICC[id].VAR.Attempts = 20
  293.     end
  294.     local pack = LuaPacket(SMSG_UPDATE_WORLD_STATE, 8)
  295.     pack:WriteUint32(4941) -- ID, X/
  296.     pack:WriteUint32(ICC[id].VAR.Attempts) -- Value
  297.     player:SendPacket(pack)
  298.     local pack = LuaPacket(SMSG_UPDATE_WORLD_STATE, 8)
  299.     pack:WriteUint32(4942) -- ID, /X
  300.     pack:WriteUint32(ICC[id].VAR.Attempts) -- Value
  301.     TO_PLAYER(player):SendPacket(pack)
  302. end
  303.  
  304. function ResetWorldstatesUI(player)
  305.     local pack = LuaPacket(SMSG_INIT_WORLD_STATES, 18)
  306.     pack:WriteUint32(0) -- Map
  307.     pack:WriteUint32(0) -- Zone
  308.     pack:WriteUint32(0)
  309.     pack:WriteUint16(0)
  310.     pack:WriteUint32(0) -- ID
  311.     pack:WriteUint32(0) -- Value
  312.     TO_PLAYER(player):SendPacket(pack)
  313. end
  314.  
  315. ------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment