So what Lua engine are you using? I'm going to answer this post assuming Eluna. ArcEmu is far behind because it has been dead for years now and is unstable and full of bugs in core areas of game functionality.
There are not methods for this available in the Eluna engine, or at least not in the version I am on. I am quite out of date. You could implement some, or I made some utility Lua functions to help with this sort of thing.
File name: Utility.ext
Code:
function Creature:IsCasting()
return self:HasUnitState(0x00008000)
end
function Player:IsCasting()
return self:HasUnitState(0x00008000)
end
function Creature:ChannelSpell(target, id)
self:SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, target:GetGUID());
self:SetUInt32Value(UNIT_CHANNEL_SPELL, id);
end
function Creature:StopChannel()
self:SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, 0);
self:SetUInt32Value(UNIT_CHANNEL_SPELL, 0);
end
function Creature:GetCreature(range, id)
return GetCreature(range, id, self)
end
function GetCreature(range, id, pUnit)
local t = pUnit:GetCreaturesInRange(range, id)
if not t or #t == 0 then
return nil
end
if #t > 1 then
for _,v in pairs(t) do
if v:GetPhaseMask() == pUnit:GetPhaseMask() then
return v
end
end
end
return t[1]
end
function Creature:IsFacing(target, compareAngle)
local x = target:GetX() - self:GetX()
local y = target:GetY() - self:GetY()
local angle = math.atan2(y, x)
if (angle < 0.0) then
angle = 2.0 * math.pi + angle
end
angle = angle - self:GetO()
while (angle > math.pi) do
angle = angle - 2.0 * math.pi
end
while (angle < -math.pi) do
angle = angle + 2.0 * math.pi
end
-- reduce or increase angle
--local compareAngle = (60 * math.pi) / 180 --math.pi
local left = -1.0 * (compareAngle / 2.0)
local right = (compareAngle / 2.0)
return (angle >= left) and (angle <= right)
end
function sendAddonMessage(plr, msg, packet)
local splitLength = 240
local splits = math.ceil(msg:len() / splitLength)
local send
local counter = 1
for i=1, msg:len(), splitLength do
send = string.format("%03d", packet)
send = send .. string.format("%02d", counter)
send = send .. string.format("%02d", splits)
if ((i + splitLength) > msg:len()) then
send = send .. msg:sub(i, msg:len())
else
send = send .. msg:sub(i, i + splitLength)
end
counter = counter + 1
if _DEBUG then print("[SENT] " .. send) end
plr:SendAddonMessage(send, "", 7, plr)
end
end
function scen_split(str)
local b = {}
local c = 1
local d = {}
string.gsub(str, "[%w%s-]", function(a)
if (a == "-") then
c = c + 1
else
if (not b[c]) then
b[c] = {}
end
table.insert(b[c], a)
end
end)
for k, v in pairs (b) do
table.insert(d, table.concat(v))
end
return d
end
Then in your other Lua scripts you can call:
Code:
local spellId = 11
local target = creature -- target can be self or any other unit reference
creature:ChannelSpell(target, spellId)
...
creature:StopChannel()
The script actually calls variables that need to be defined. I have a Constants.ext file but you can put it at the top of the same script if you want to.
Code:
OBJECT_END = 0x0006
UNIT_NPC_EMOTESTATE = OBJECT_END + 0x004D
UNIT_FIELD_BYTES_1 = OBJECT_END + 0x0044
UNIT_FIELD_BYTES_2 = OBJECT_END + 0x0074
UNIT_FIELD_FLAGS = OBJECT_END + 0x0035
UNIT_FIELD_FLAG_UNTARGETABLE = 33554434
UNIT_FIELD_FLAG_UNATTACKABLE = 2
UNIT_FIELD_FLAG_C_UNATTACKABLE = 770
UNIT_FIELD_CHANNEL_OBJECT = OBJECT_END + 0x000E
UNIT_CHANNEL_SPELL = OBJECT_END + 0x0010
GAMEOBJECT_BYTES_1 = OBJECT_END + 0x000B
There are more flags than this in the game, these are just the ones I have used so far on something I am working on.
Oh and you cannot store references to objects in member variables like that. You have to obtain the reference when you need it and not pass it between functions. Eluna will now actually detect you doing this and warn you from doing it while disabling the functionality. Other game engines had the potential to crash.
One way would be to use a function from my utility script:
Code:
function Creature:GetCreature(range, id)
Code:
local creature = unit:GetCreature(40, 10811)
But I am, pretty sure there's a better way (like storing the GUID and then getting creature by GUID) but I cannot find the method from a quick scan.