Code:
local NPC_ID = 50000
--A would be the table of the unit, each instance of this unit is unique.
--If it wasn't and you had two of this unit in the world they could interfere with each other.
A = {}
-- V would be the units table, you can store variables for this instance of the unit.
A.V = {}
--Table of messages, each message is defined in the table as a number
local AVmessages = {
{12, "More fools to challenge me?"}, -- Would be 1
{14, "See you In Hell"}, -- would be 2 ect.
{14, "Any one else?"},
{14, "I... will... return!"}
}
-- The function is created in the table V, which is in the table A.
function A.V.Arg_Events(pUnit, Event)
--[[
-- Use code below if we want to store variables across functions
-- The id is used to define which unit we are going to assign a variable to, the example below uses the instance ID.
-- Instance id's are randomly generated and assigned to a group whenever they enter the instance.
-- We get the instance id and assign it to the variable "id".
-- If the unit isn't in an instance we give it the id 1(I don't know why Stoneharry does this,
-- as that could potentially collide if there were more of than one of this boss in the world.
local id = pUnit:GetInstanceID() or 1
A[id] = A[id] or {V={}} -- Essentially we just check whether this unit is already stored, if it is not we make create and or clean the table V
-- unitReference is a variable created, to refer the unit, so incase we want to do something for this unit in another function
-- We call the id and use the id's unit reference.
A[id].V.unitReference = pUnit
]]
pUnit:SendChatMessage(AVmessages[Event][1], 0, AVmessages[Event][2])
-- This literally just removes the need for multiple functions for onDeath and onCombat etc., as we just check which event is registered
-- Look at the code where Stoneharry registers the Event to see how it works.
-- Checking if the registered event is 1(onCombat) if it is then register the following functions:
if Event == 1 then
pUnit:RegisterEvent("A.V.Argatros_accelerate", 20000, 5)
pUnit:RegisterEvent("A.V.Argatros_burst", 10000, 40)
pUnit:RegisterEvent("A.V.Argatros_kick", 30000, 5)
pUnit:RegisterEvent("A.V.Argatros_steal", 13000, 20)
pUnit:RegisterEvent("A.V.Argatros_nova", 25000, 5)
pUnit:RegisterEvent("A.V.Argatros_aegis", 40000, 20)
pUnit:RegisterEvent("A.V.Argatros_cc", 60000, 4)
pUnit:RegisterEvent("A.V.Argatros_static", 65000, 4)
pUnit:RegisterEvent("A.V.Argatros_attenuation", 77000, 2)
-- If the event id 2 or 4(onLeaveCombat or onDied) remove any events assigned to the unit, so it won't try to use the different spells.
elseif Event == 2 or Event == 4 then
pUnit:RemoveEvents()
end
end
-- As the function is registered to the V table(this particular units table) in the A table it will only happen for this unit, if it wasn't
-- it would be global and happen to every instance of the unit in the world / instance.
-- This goes for every function below.
function A.V.Argatros_accelerate(pUnit)
-- As this does not happen to a particular target we do not need to evaluate the target.
-- We would need to evaluate the unit(just like we do for the player (check the next code's comment),
-- if we did not remove the events on this units death, as it would try to cast these spells while dead or after it left combat.
--
pUnit:CastSpell(52635)
end
function A.V.Argatros_burst(pUnit)
pUnit:CastSpell(38539)
end
function A.V.Argatros_kick(pUnit)
-- Where you before just did a cast on a random player nearby Stoneharry has made a function to evaluate the picked target.
-- so instead of FullCastSpellOnTarget we call a function, that might do this for us.
castOnPlayerTarget(24671, pUnit)
end
function A.V.Argatros_steal(pUnit)
castOnPlayerTarget(71839, pUnit)
end
function A.V.Argatros_nova(pUnit)
pUnit:CastSpell(59363)
end
function A.V.Argatros_cc(pUnit)
castOnPlayerTarget(64156, pUnit)
end
function A.V.Argatros_acid(pUnit)
castOnPlayerTarget(59419, pUnit)
end
function A.V.Argatros_aegis(pUnit)
pUnit:CastSpell(20620)
end
function A.V.Argatros_static(pUnit)
castOnPlayerTarget(59795, pUnit)
end
function A.V.Argatros_attenuation(pUnit)
pUnit:CastSpell(50627)
end
-- Essentially this is magic!
--The function can take two arguments id and the pUnit, where id would be the spell and pUnit would be the unit trying to cast the spell.
function castOnPlayerTarget(id, pUnit)
--If the call does not contain an id or the unit is nil or the unit is casting / dead then do nothing.
if not id or not pUnit or pUnit:IsCasting() or pUnit:IsDead() then
return -- This ends the function, so the rest won't be called.
end
-- We define "plr" as the random player which is gotten by the GetRandomPlayer method.
local plr = pUnit:GetRandomPlayer(0)
--If the method does not return a player or the player is dead then do nothing.
if not plr or plr:IsDead() then
return
end
else -- If all the checks above pass then cast the spell with the id and on the player.
pUnit:FullCastSpellOnTarget(id, plr)
end
--For events 1,2,3,4 do
for i=1,4 do
RegisterUnitEvent(NPC_ID, i, "A.V.Arg_Events") --Call the function A.V.Arg_Events.
end
--[[
On a final note the big difference between this script and yours is that this does not collide.
Your script would suffice if there was only 1 of your units present in the world at any time, where this script
is able to tell the difference between them and only call different functions for each unique instance of the unit.
Hope this commenting helps out a little.
]]