Target¶
Your current target.
Forms¶
actor Target¶
- Returns your current target as an
actor.
Usage¶
local t = mq.TLO.Target
if t.ID() ~= 0 then
eq2.print(("%s (lvl %d, %.1fm) hp=%d%%")
:format(t.Name(), t.Level(), t.Distance(), t.PctHP()))
end
Checking for a target¶
mq.TLO.Target is always a table, even with nothing targeted — the resolution
happens per member. So the "do I have a target" test is on ID():
if mq.TLO.Target.ID() ~= 0 then ... end -- correct
if mq.TLO.Target then ... end -- always true, useless
Setting a target¶
eq2.target_by_id(spawn_id)¶
Targets a specific actor by its spawn id. Resolves the actor's client-local ghost
handle internally and calls the native target function. Returns true on
success, false on failure (unknown id, unresolved actor, hook not ready).
if eq2.target_by_id(spawn_id) then
eq2.print("targeted " .. mq.TLO.Target.Name())
end
This is the preferred way to target a specific actor. Unlike /target <name>,
which picks the nearest name match and can hit the wrong mob when duplicates
exist, target_by_id always selects the exact actor.
The older command-based approach still works:
eq2.cmd("/target Some Mob")
eq2.cmdf("/target_id %d", spawn_id)
Give the client a pulse to process it before reading back:
eq2.cmdf("/target_id %d", id)
eq2.delay(100)
if mq.TLO.Target.ID() == id then ... end
Distance¶
Target.Distance() is the distance from you to the target, and returns
0.0 on any failed read — so d > radius reads a lookup failure as "in melee".
Require d > 0:
local d = mq.TLO.Target.Distance()
if d > 0 and d < 5 then
eq2.cmd('/useability "Some Combat Art"')
end
Friend or foe¶
Attackable() means "combat-capable", which includes other players. It is not a
hostility test. For "should I be hitting this", combine it with
IsPlayer():
local t = mq.TLO.Target
local hostile = t.ID() ~= 0 and t.Attackable() and not t.IsPlayer()
See also¶
actor— the full member list.Spawn[key]Me