Olá galera.
Devido a um pedido, refiz a função getSearchString das sources do TFS em Lua, e vou aproveitar e postar ela aqui, caso alguém vá a precisar um dia.
function getSearchString(fromPos, toPos, isFromCreature, isToCreature)
isFromCreature = isFromCreature == nil and false or isFromCreature
isToCreature = isToCreature == nil and false or isToCreature
local DISTANCE_CLOSE,DISTANCE_FAR,DISTANCE_VERYFAR = 0,1,2
local LEVEL_HIGHER,LEVEL_LOWER,LEVEL_SAME = 1,-1,0
local DIR_N,DIR_S,DIR_E,DIR_W,DIR_NE,DIR_NW,DIR_SE,DIR_SW = 0,1,2,3,4,5,6,7,8
local distance
local direction
local level
local dx,dy,dz = fromPos.x - toPos.x,fromPos.y - toPos.y,fromPos.z - toPos.z
if dz > 0 then
level = LEVEL_HIGHER
elseif dz < 0 then
level = LEVEL_LOWER
else
level = LEVEL_SAME
end
if math.abs(dx) < 5 and math.abs(dy) < 5 then
distance = DISTANCE_BESIDE
else
tmp = dx * dx + dy * dy
if tmp < 10000 then
distance = DISTANCE_CLOSE
elseif tmp < 75625 then
distance = DISTANCE_FAR
else
distance = DISTANCE_VERYFAR
end
end
local tangent
if dx ~= 0 then
tangent = dy / dx
else
tangent = 10.
end
if math.abs(tangent) < 0.4142 then
if dx > 0 then
direction = DIR_W
else
direction = DIR_E
end
elseif math.abs(tangent) < 2.4142 then
if tangent > 0 then
if dy > 0 then
direction = DIR_NW
else
direction = DIR_SE
end
else
if dx > 0 then
direction = DIR_SW
else
direction = DIR_NE
end
end
else
if dy > 0 then
direction = DIR_N
else
direction = DIR_S
end
end
local ss = ""
if distance == DISTANCE_BESIDE then
if level == LEVEL_SAME then
ss = ss.."is "
if toIsCreature then
ss = ss.."standing "
end
ss = ss.."next to you"
elseif level == LEVEL_HIGHER then
ss = ss.."is above "
if fromIsCreature then
ss = ss.."you"
end
elseif level == LEVEL_LOWER then
ss = ss.."is below "
if fromIsCreature then
ss = ss.."you"
end
end
elseif distance == DISTANCE_CLOSE then
if level == LEVEL_SAME then
ss = ss.."is to the"
elseif level == LEVEL_HIGHER then
ss = ss.."is on a higher level to the "
elseif level == LEVEL_LOWER then
ss = ss.."is on a lower level to the "
end
elseif distance == DISTANCE_FAR then
ss = ss.."is far to the"
elseif distance == DISTANCE_VERYFAR then
ss = ss.."is very far to the"
end
if distance ~= DISTANCE_BESIDE then
ss = ss.." "
if direction == DIR_N then
ss = ss.."north"
elseif direction == DIR_S then
ss = ss.."south"
elseif direction == DIR_E then
ss = ss.."east"
elseif direction == DIR_W then
ss = ss.."west"
elseif direction == DIR_NE then
ss = ss.."north-east"
elseif direction == DIR_NW then
ss = ss.."north-west"
elseif direction == DIR_SE then
ss = ss.."south-east"
elseif direction == DIR_SW then
ss = ss.."south-west"
end
end
return ss
end
function useExiva(cid, pid)
return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, getCreatureName(pid)..getSearchString(getCreaturePosition(cid), getCreaturePosition(pid), true, true))
end
Explicando os parâmetros da função getSearchString(fromPos, toPos, isFromCreature, isToCreature):
fromPos = posição inicial toPos = posição do objeto procurado isFromCreature = a posição inicial é uma posição de uma criatura? (true / false) [default = false] isToCreature = a posição do objeto é uma posição de uma criatura? (true / false) [default = false]
E pra facilitar o uso, já aproveitei e fiz a função para usar o comando exiva: useExiva(cid, pid).
cid = o uid do player que usa pid = o uid do player procurado
Ambas as funções estão no code.
Bom uso.


