Code:
--[[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** ALGALON THE OBSERVER **
** SCRIPTED BY DASKIN **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
]]
print "Algalon the Observer loaded."
-- VARIABLE REGISTER --
local Alg
local BlackH
local LivConst
local DarkMatt
local CollapS
local Phase2
local phase = 0
local bigbangcast = 0
local CollapStars = {}
local starsdead = 0
-- Spells --
local QuantStrike = 64395
local PhasePunch = 64412
local CosSmash = 62311
local BigBang = 64443
local Ascend = 64487
local BlackExplo = 64122
local ArcBarrage = 64599
--########--
function table.find(t, v)
if type(t) == "table" and v then
for k, val in pairs(t) do
if v == val then
return k
end
end
end
return false
end
-- Collapsing Star HP --
function Algalon_OnSpawn (pUnit, Event)
Alg = pUnit
UNIT_FLAG_DEFAULT = Alg:GetUInt64Value(UNIT_FIELD_FLAGS)
end
function BlackH_OnSpawn (pUnit, Event)
print "blackH spawned"
BlackH = pUnit
BlackH:GetUInt64Value(UNIT_FIELD_FLAGS)
BlackH:RegisterEvent("BlackH_OnUse", 1, 0)
end
function StarsColl_OnSpawn (pUnit, Event)
CollapS = pUnit
CollHp = 100
--CollapS:GetGuid() = CollapS1
bx = CollapS:GetSpawnX()
by = CollapS:GetSpawnY()
bz = CollapS:GetSpawnZ()
bo = CollapS:GetSpawnO()
CollapS:SetCombatCapable(1)
CollapS:SetCombatMeleeCapable(1)
CollapS:RegisterEvent("CollapsingStar_HpLose", 500, 0)
CollapS:RegisterEvent("CollapsingStar_On100", 1, 0)
end
--[[function CollHp.lower (self, v)
self.CollHp = CollapS.CollHp - v
end]]
function CollapsingStar_HpLose (pUnit, Event)
if (CollHP ~= 0 and stardead == 0) then
for k, v in pairs (CollapStars) do
if (k == 1) then
CollHp = CollHp - 1
for i = 1, #CollapStars do
v:SetHealthPct(CollHP)
end
end
if (k == 2) then
CollHp = CollHp - 1
for i = 2, #CollapStars do
v:SetHealthPct(CollHP)
end
end
if (k == 3) then
CollHp = CollHp - 1
for i = 3, #CollapStars do
v:SetHealthPct(CollHP)
end
end
end
end
end
function CollapsingStar_On100 (pUnit, Event)
if (CollHp == 0) then
CollapS:CastSpell(BlackExplo)
CollapS:Kill(CollapS)
end
end
function CollapsingStar_OnDeath (pUnit, Event)
starsdead = starsdead + 1
if (starsdead == 1) and (starsspawned == 1) then
BlackHSpawn[1] = CollapS:SpawnCreature(32953, bx, by, bz, bo, 35, 0)
CollapStars[1]:Despawn(0, 0)
elseif (starsdead == 2) and (starsspawned == 2) then
BlackHSpawn[2] = CollapS:SpawnCreature(32953, bx, by, bz, bo, 35, 0)
CollapStars[2]:Despawn(0, 0)
elseif (starsdead == 3) then
BlackHSpawn[3] = CollapS:SpawnCreature(32953, bx, by, bz, bo, 35, 0)
CollapStars[3]:Despawn(0, 0)
end
blackholespawned = 1
print "blackholespawn?"
CollapS:RemoveEvents()
CollapS:Despawn(0,0)
end
function Phase2_OnSpawn (pUnit, Event)
Phase2 = pUnit
Phase2:AddPhase(2, 1)
Phase2:SetPhase(2, 1)
Phase2:SetUint64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE)
end
function LivingConst_OnSpawn (pUnit, Event)
LivConst = pUnit
end
function DarkMatt_OnSpawn (pUnit, Event)
Darkmatt = pUnit
Darkmatt:SetPhase(2, 1)
end
function BlackH_OnUse (pUnit, Event)
local plr = BlackH:GetClosestPlayer()
if plr:GetPhase() == 1 and (bigbangcast == 1) then
if plr:GetDistance() <= 5 then
plr:AddPhase(2, 1)
plr:SetPhase(2, 1)
end
end
end
function Alg_CosSmash (pUnit, Event) -- WRONG VISUAL. NONE WORK.
local plrcos = Alg:GetRandomPlayer(0)
xcos = plrcos:GetX()
ycos = plrcos:GetY()
zcos = plrcos:GetZ()
if (plrcos ~= Alg:GetMainTank()) and (plrcos ~= nil) then
Alg:FullCastSpellOnTarget(62263, plrcos)
Alg:RegisterEvent("Alg_CosSmashDmg", 5000, 1)
end
end
function Alg_CosSmashDmg (pUnit, Event) -- Cant find any working Cosmic Smash spells.
Alg:CastAoF(xcos, ycos, zcos, CosSmash) -- I'll leave this in if you can find a working spell.
end
function Alg_QuantStrike (pUnit, Event)
local plr = Alg:GetMainTank()
if (plr ~= nil) then
Alg:FullCastSpellOnTarget(QuantStrike, plr)
end
end
function Alg_PhasePunch (pUnit, Event)
local plr = Alg:GetMainTank()
if (plr ~= nil) then
Alg:FullCastSpellOnTarget(PhasePunch, plr)
end
end
function Alg_BigBang (pUnit, Event)
if (bigbangcast == 0) then
local chancesay = math.random(1, 2)
if (chancesay == 1) then
Alg:SendChatMessage(14, 0, "Witness the fury of cosmos!")
else
Alg:SendChatMessage(14, 0, "Behold the tools of creation!")
end
Alg:SendAreaTriggerMessage("Algalon begins to cast Big Bang!")
Alg:FullCastSpell(BigBang)
bigbangcast = 1
Alg:RegisterEvent("Alg_BigBangCasted", 8000, 1)
end
end
function Alg_BigBangCasted (pUnit, Event)
if (bigbangcast == 1) then
bigbangcast = 0
for k, v in pairs (Phase2:GetInRangePlayers()) do
if v:GetPhase() == 2 then
v:SetPhase(1, 1)
end
end
end
end
function Alg_Ascend (pUnit, Event)
local plrs = Alg:GetInRangePlayers()
for k, v in pairs (plrs) do
if Alg:GetInRangePlayersCount() == 0 or (ZerkTimer == 360) then
Alg:PlaySoundToSet(15394)
Alg:SendChatMessage(14, 0, "You are... out of time.")
algberserked = 1
Alg:FullCastSpell(Ascend)
Alg:SendAreaTriggerMessage("Algalon has enraged!")
end
end
end
function Alg_AscendMin (pUnit, Event)
Alg:PlaySoundToSet(15394)
Alg:SendChatMessage(14, 0, "You are... out of time.")
algberserked = 1
Alg:FullCastSpell(Ascend)
Alg:SendAreaTriggerMessage("Algalon has enraged!")
end
function Alg_ConstChecks (pUnit, Event)
if (blackholespawned == 1) then
local x = BlackH:GetX()
local y = BlackH:GetY()
local z = BlackH:GetZ()
--for k, v in pairs (BlackH:GetInRangeFriends()) do
local closeststar = BlackH:GetCreatureNearestCoords(x, y, z, 33052)
if closeststar:GetEntry() == 33052 and closeststar:GetDistance() <= 3 then
local closestar = closeststar:GetRawGUID()
local closestardespawn = closestar:GetUnitByRawGUID(closestar)
local x = closestar:GetX()
local y = closestar:GetY()
local z = closestar:GetZ()
local blackHclose = closeststar:GetCreatureNearestCoords(x, y, z, 32953)
if (blackHclose:GetEntry() == 32953) and (closestar:GetDistance() <= 3) then
local blackHdespawn = blackHclose:GetRawGUID()
local blackHdespawnn = blackHclose:GetUnitByRawGUID(blackHdespawn)
blackHdespawnn(0, 0)
closestardespawn:Despawn(0, 0)
end
end
--end
Alg:RegisterEvent("Phase2_CheckPlrs", 2000, 0)
end
end
--[[function Alg_ConstChecks (pUnit, Event)
if (starsdead == 1) then
BlackHSpawn[1]..
..
..
wtf.
end
end
]]
function Alg_ZerkTimer (pUnit, Event) -- 360 seconds == 6min
if (algengaged == 1) and (algberserked == 0) then
ZerkTimer = ZerkTimer + 1
end
end
local starsspawned = 0
--[[ for k, v in pairs (LivConst)
v:GetRawGUID()
if (v:GetX() == blackholex) and (v:GetY() == blackholey) and (v:GetZ() == blackholez) then
v:GetUnitByGuid(]]
function Alg_CollapSpawn (pUnit, Event)
Alg:SendChatMessage(14, 0, "The stars come to my aid.")
Alg:PlaySoundToSet(15392)
local ranx = math.random(1, 15)
local rany = math.random(5, 20)
local x = Alg:GetX() + ranx
local y = Alg:GetY() - rany
local z = Alg:GetZ()
local o = Alg:GetO()
local starsspawned = starsspawned + 1
if (starsspawned == 1) then
CollapStars[1] = Alg:SpawnCreature(32955, x, y, z, o, 14, 0)
elseif (starsspawned == 2) then
CollapStars[2] = Alg:SpawnCreature(32955, x, y, z, o, 14, 0)
elseif (starssapwned == 3) then
CollapStars[3] = Alg:SpawnCreature(32955, x, y, z, o, 14, 0)
elseif (starsspawned >= 4) then
starsspawned = 0
table.remove(t, 1)
table.remove(t, 2)
table.remove(t, 3)
end
--[[Alg:SpawnCreature(32955, x, y, z, o, 14, 0)
Alg:SpawnCreature(32955, x, y, z, o, 14, 0)
Alg:SpawnCreature(32955, x, y, z, o, 14, 0)]]
end
function Alg_LivingConstSpawn (pUnit, Event)
local ranx = math.random(1, 15)
local rany = math.random(5, 20)
local x = Alg:GetX() + ranx
local y = Alg:GetY() - rany
local z = Alg:GetZ()
local o = Alg:GetO()
Alg:SpawnCreature(33052, x, y, z, o, 14, 0)
Alg:SpawnCreature(33052, x, y, z, o, 14, 0)
Alg:SpawnCreature(33052, x, y, z, o, 14, 0)
Alg:SpawnCreature(33052, x, y, z, o, 14, 0)
end
function LivingConst_OnCombat (pUnit, Event)
local plr = LivConst:GetRandomPlayer(0)
if (plr ~= nil) then
LivConst:FullCastSpellOnTarget(ArcBarrage, plr)
end
end
function Phase2_SpawnMobs (pUnit, Event)
if (algengaged == 1) then
local ranx = math.random(1, 15)
local rany = math.random(5, 20)
local x = Phase2:GetX() + ranx
local y = Phase2:GetY() - rany
local z = Phase2:GetZ()
local o = Phase2:GetO()
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
Phase2:SpawnCreature(33089, x, y, z, o, 14, 0)
end
end
function Phase2_CheckPlrs (pUnit, Event)
local plrs = Phase2:GetInRangePlayers()
for k, v in pairs (plrs) do
if (v:GetPhase() == 2) and (blackholecast == 1) then
v:CastSpell(62169)
end
end
end
function Alg_OnCombat (pUnit, Event) -- Here we go
Alg:SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE)
--Alg:SetUInt64Vlaue(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_ATTACKABLE_9)
Alg:SetCombatCapable(1)
Alg:SendChatMessage(14, 0, "Trans-location complete. Commencing planetary analysis of Azeroth.")
algengaged = 1
Alg:RegisterEvent("Alg_Speech2", 6000, 1)
end
function Alg_Speech2 (pUnit, Event)
Alg:SendChatMessage(14, 0, "Stand back, mortals. I am not here to fight you.")
Alg:RegisterEvent("Alg_Speech3", 7000, 1)
end
function Alg_Speech3 (pUnit, Event)
Alg:SendChatMessage(14, 0, "It is in the universe's best interest to re-originate this planet should my analysis find systemic corruption. Do not interfere.")
Alg:RegisterEvent("Alg_CombatStart", 8000, 1)
end
function Alg_CombatStart (pUnit, Event)
zerkcheck = Alg
Alg:SetUInt64Value(UNIT_FIELD_FLAGS, UNIT_FLAG_DEFAULT)
Alg:SetCombatCapable(0)
Alg:PlaySoundToSet(15386)
Alg:SendChatMessage(14, 0, "Your actions are illogical. All possible results for this encounter have been calculated. The Pantheon will receive the Observer's message regardless of outcome.")
--Alg:SendChatMessage(14, 0, "See your world through my eyes: A universe so vast as to be immeasurable - incomprehensible even to your greatest minds.")
Alg:RegisterEvent("Alg_PhasePunch", 15000, 0) -- Cant find the Star thingy animation.
Alg:RegisterEvent("Alg_CosSmash", 25000, 0)
Alg:RegisterEvent("Alg_BigBang", 90000, 0)
Alg:RegisterEvent("Alg_QuantStrike", math.random(7000, 11000), 0)
Alg:RegisterEvent("Alg_CollapSpawn", 19000, 0)
Alg:RegisterEvent("Alg_LivingConstSpawn", 50000, 0)
Alg:RegisterEvent("Alg_ConstChecks", 1, 0)
Alg:RegisterEvent("Alg_ZerkTimer", 1000, 0) -- TESTING.
Alg:RegisterEvent("Alg_Ascend", 1, 0)
Alg:RegisterEvent("Alg_Phase2", 1, 0)
zerkcheck:RegisterEvent("Alg_AscendMin", 360000, 1)
end
function Alg_Phase2 (pUnit, Event)
if Alg:GetHealthPct() <= 20 then
--
Alg:RemoveEvents()
BlackH:Despawn(0, 0)
BlackH:RemoveEvents()
LivConst:Despawn(0, 0)
LivConst:RemoveEvents()
CollapS:Despawn(0, 0)
CollapS:RemoveEvents()
--
Alg:SendChatMessage(14, 0, "Beware!")
Alg:RegisterEvent("Alg_PhasePunch", 15000, 0)
Alg:RegisterEvent("Alg_QuantStrike", math.random(7000, 11000), 0)
Alg:RegisterEvent("Alg_CosSmash", 25000, 0)
Alg:RegisterEvent("Alg2_BlackHoleSpawn", 2000, 1)
Alg:RegisterEvent("Alg2_DarkMattSpawn", 30000, 0)
Alg:RegisterEvent("Alg_Defeat", 1, 0)
end
end
function Alg2_BlackHoleSpawn (pUnit, Event)
local x = Alg:GetX() + 5
local y = Alg:GetY() + 5
local z = Alg:GetZ()
local o = Alg:GetO()
local x2 = Alg:GetX() + 5
local y2 = Alg:GetY() - 5
local z2 = Alg:GetZ()
local o2 = Alg:GetO()
local x3 = Alg:GetX() - 5
local y3 = Alg:GetY() + 5
local z3 = Alg:GetZ()
local o3 = Alg:GetO()
local x4 = Alg:GetX() - 5
local y4 = Alg:GetY() - 5
local z4 = Alg:GetZ()
local o4 = Alg:GetO()
Alg:SpawnCreature(32953, x, y, z, o, 42, 0)
Alg:SpawnCreature(32953, x2, y2, z2, o2, 42, 0)
Alg:SpawnCreature(32953, x3, y3, z3, o3, 42, 0)
Alg:SpawnCreature(32953, x4, y4, z4, o4, 42, 0)
end
function Alg2_DarkMattSpawn (pUnit, Event)
local x = Alg:GetX() + 5
local y = Alg:GetY() + 5
local z = Alg:GetZ()
local o = Alg:GetO()
local x2 = Alg:GetX() + 5
local y2 = Alg:GetY() - 5
local z2 = Alg:GetZ()
local o2 = Alg:GetO()
local x3 = Alg:GetX() - 5
local y3 = Alg:GetY() + 5
local z3 = Alg:GetZ()
local o3 = Alg:GetO()
local x4 = Alg:GetX() - 5
local y4 = Alg:GetY() - 5
local z4 = Alg:GetZ()
local o4 = Alg:GetO()
Alg:SpawnCreature(33089, x, y, z, o, 42, 0)
Alg:SpawnCreature(33089, x2, y2, z2, o2, 42, 0)
Alg:SpawnCreature(33089, x3, y3, z3, o3, 42, 0)
Alg:SpawnCreature(33089, x4, y4, z4, o4, 42, 0)
end
function Alg_Defeat (pUnit, Event)
if Alg:GetHealthPct() <= 2 then
Alg:RemoveEvents()
BlackH:Despawn(0, 0)
BlackH:RemoveEvents()
LivConst:Despawn(0, 0)
LivConst:RemoveEvents()
CollapS:Despawn(0, 0)
CollapS:RemoveEvents()
Alg:SetHealthPct(100)
Alg:SetFaction(42)
Alg:PlaySoundToSet(15393)
Alg:SendChatMessage(12, 0, "I have seen worlds bathed in the Makers' flames. Their denizens fading without so much as a whimper. Entire planetary systems born and raised in the time that it takes your mortal hearts to beat once. Yet all throughout, my own heart, devoid of emotion... of empathy. I... have... felt... NOTHING! A million, million lives wasted. Had they all held within them your tenacity? Had they all loved life as you do?")
Alg:RegisterEvent("Alg_DefeatSpeech", 6000, 1)
end
end
function Alg_DefeatSpeech (pUnit, Event)
Alg:PlaySoundToSet(15401)
Alg:SendChatMessage(12, 0, "Perhaps it is your imperfection that which grants you free will. That allows you to persevere against cosmically calculated odds. You prevailed where the Titans' own perfect creations have failed.")
Alg:RegisterEvent("Alg_DefeatSpeech2", 5000, 1)
end
function Alg_DefeatSpeech2 (pUnit, Event)
Alg:PlaySoundToSet(15402)
Alg:SendChatMessage(12, 0, "I've rearranged the reply code. Your planet will be spared. I cannot be certain of my own calculations anymore.")
Alg:RegisterEvent("Alg_DefeatSpeech3", 3000, 1)
end
function Alg_DefeatSpeech3 (pUnit, Event)
Alg:SendChatMessage(12, 0, "I lack the strength to transmit the signal. You must hurry. Find a place of power close to the skies.")
Alg:RegisterEvent("Alg_DefeatSpeech4", 4000, 1)
end
function Alg_DefeatSpeech4 (pUnit, Event)
local plr = Alg:GetRandomPlayer()
local name = plr:GetName()
Alg:SendChatMessage(14, 0, "Do not worry about my fate"..name..". If the signal is not transmitted in time re-origination will proceed regardless. Save. Your. World.")
Alg:RegisterEvent("Alg_Loot", 2000, 1)
end
function Alg_KilledPlr (pUnit, Event)
local chance = math.random(1,2)
if (chance == 1) then
Alg:PlaySoundToSet(15387)
Alg:SendChatMessage(14, 0, "Loss of life, unavoidable.")
else
Alg:PlaySoundToSet(15388)
Alg:SendChatMessage(14, 0, "I do what I must..")
end
end
function Alg_OnDeath (pUnit, Event) -- Shouldnt happen
Alg:RemoveEvents()
BlackH:Despawn(0, 0)
BlackH:RemoveEvents()
LivConst:Despawn(0, 0)
LivConst:RemoveEvents()
CollapS:Despawn(0, 0)
CollapS:RemoveEvents()
phase = 0
bigbang = 0
end
function Alg_OnLeaveCombat (pUnit, Event)
phase = 0
bigbang = 0
Alg:RemoveEvents()
BlackH:Despawn(0, 0)
BlackH:RemoveEvents()
LivConst:Despawn(0, 0)
LivConst:RemoveEvents()
CollapS:Despawn(0, 0)
CollapS:RemoveEvents()
Alg:SendChatMessage(12, 0, "Analysis complete. There is partial corruption in the planet's life-support systems as well as complete corruption in most of the planet's defense mechanisms.")
Alg:RegisterEvent("Alg_LeaveCombat2", 5000, 1)
end
function Alg_LeaveCombat2 (pUnit, Event)
Alg:SendChatMessage(14, 0, "Begin uplink: Reply Code: 'Omega'. Planetary re-origination requested.")
Alg:RegisterEvent("Alg_LeaveCombat3", 4000, 1)
end
function Alg_LeaveCombat3 (pUnit, Event)
Alg:SendChatMessage(14, 0, "Farewell, mortals. Your bravery is admirable, for such flawed creatures.")
Alg:Despawn(0, 120000)
end
-- RegisterUnitEvents /cry --
-- IF ONSPAWN ISNT WORKING, USE 6 INSTEAD OF 18 --
RegisterUnitEvent(32953, 18, "BlackH_OnSpawn")
RegisterUnitEvent(32955, 4, "CollapsingStar_OnDeath")
RegisterUnitEvent(32871, 1, "Alg_OnCombat")
RegisterUnitEvent(33052, 1, "LivingConst_OnCombat")
--RegisterUnitEvent(entryid, 1, "_OnCombat")
--RegisterUnitEvent(entryid, 1, "_OnCombat")
RegisterUnitEvent(32871, 18, "Algalon_OnSpawn")
RegisterUnitEvent(33052, 18, "LivingConst_OnSpawn")
RegisterUnitEvent(33089, 18, "DarkMatt_OnSpawn")
RegisterUnitEvent(32955, 18, "StarsColl_OnSpawn")
RegisterUnitEvent(500033, 18, "Phase2_OnSpawn")
RegisterUnitEvent(32871, 2, "Alg_OnLeaveCombat")
RegisterUnitEvent(32871, 3, "Alg_KilledPlr")
RegisterUnitEvent(32871, 4, "Alg_OnDeath")