First, I'm sorry if my use of LUA is not Correct. I haven't used it much.
In this Situation, you might be better off doing the Macro for Select Next Hostile. Really No reason to Use the New Targeting System for attacking things by selecting Next Mobile.
Would be Much easier to just build an array for the "types" you wish to attack then use something similar to these subs to locate the nearest monster and attack it.
function finddist(x,y)
dx = math.abs(UO.CharPosX - x)
dy = math.abs(UO.CharPosY - y)
return math.max(dx, dy)
end
function attack(types)
local closest = nil
local fdist = 13
for i = 1,UO.ScanItems(true) do
local id,type,kind,contid,x,y,z,stack,rep,col = UO.GetItem(i)
dist = finddist(x,y)
for c = 1,#types do
if type == types[c] and dist<fdist do
fdist = dist
closest = id
end
end
end
if closest ~= nil do
UO.LTargetID = id
UO.LTargetKind = 1
UO.Macro(27,0)
end
end