Looks like it would probably work. Going to the tile and remembering it till finished will work.
But do you need to check distance to tile if you just teleported to it? Maybe if it failed to teleport? In that case you should be getting the nearest tile
after checking the distance.
Also, what happens if the distance is greater than 30?
Anyway, I worked out my way. It was a lot of fun. Your way might be simpler and adequate if it works so might be preferable but I'll post mine anyway.
Code: Select all
function createTileTable()
--=== Create table for tiles ===--
tiles = {}
local objectList = CObjectList();
objectList:update();
local objSize = objectList:size()
for i = 0,objSize do
local obj = objectList:getObject(i);
if obj.Id == 111811 or obj.Id == 111812 then
table.insert(tiles, table.copy(obj))
end
end
-- Sort function
local function sortfunc(a,b)
if SEsize(a.X,a.Z) == SEsize(b.X,b.Z) then
return NEsize(b.X,b.Z) > NEsize(a.X,a.Z)
else
return SEsize(b.X,b.Z) > SEsize(a.X,a.Z)
end
end
-- Sort tiles
table.sort(tiles, sortfunc)
end
local function SEsize(_x, _z)
local X1 = 2622.1403808594
local Z1 = 2900.1105957031
local X2 = 2471.7895507813
local Z2 = 2954.833984375
return math.floor(((_x-X1)*(Z2-Z1)-(X2-X1)*(_z-Z1))/math.sqrt((X2-X1)^2 + (Z2-Z1)^2) + 0.5)
end
local function NEsize(_x, _z)
local X1 = 2471.7895507813
local Z1 = 2954.833984375
local X2 = 2526.5126953125
local Z2 = 3105.1848144531
return math.floor(((_x-X1)*(Z2-Z1)-(X2-X1)*(_z-Z1))/math.sqrt((X2-X1)^2 + (Z2-Z1)^2) + 0.5)
end
So you run 'createTileTable()' and it creates a table of tiles objects in order, like so.
Code: Select all
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36
You could then create an order list to say what order you want to collect them
eg.
Code: Select all
orderlist = {1,4,7,10,13,16,19,22,25,28,31,34,2,5,8,11,14,17,20,23,26,29,32,35,3,6,9,12,15,18,21,24,27,30,33,36}
Beauty of this is it's easy to try a new pattern if you like. And do you want to know something else that's funny? I discovered that if you create a table like this, they remain in order. lol
Which means if you created your table like this
Code: Select all
--=== all 36 tiles and corresponding ID ===--
tilecoords = {
{x="2472", z="2955", id=111811},
{x="2504", z="3042", id=111812},
{x="2503", z="2942", id=111812},
{x="2534", z="3032", id=111811},
{x="2528", z="2932", id=111811},
{x="2564", z="3022", id=111812},
{x="2559", z="2921", id=111812},
{x="2593", z="3011", id=111811},
{x="2590", z="2912", id=111811},
{x="2624", z="3001", id=111812},
{x="2620", z="2896", id=111812},
{x="2652", z="2983", id=111811},
{x="2484", z="2981", id=111812},
{x="2518", z="3071", id=111811},
{x="2510", z="2969", id=111811},
{x="2545", z="3060", id=111812},
{x="2541", z="2959", id=111812},
{x="2576", z="3052", id=111811},
{x="2573", z="2951", id=111811},
{x="2607", z="3040", id=111812},
{x="2600", z="2937", id=111812},
{x="2634", z="3026", id=111811},
{x="2629", z="2926", id=111811},
{x="2663", z="3018", id=111812},
{x="2495", z="3014", id=111811},
{x="2525", z="3100", id=111812},
{x="2521", z="2995", id=111812},
{x="2557", z="3093", id=111811},
{x="2552", z="2990", id=111811},
{x="2584", z="3079", id=111812},
{x="2582", z="2978", id=111812},
{x="2615", z="3069", id=111811},
{x="2610", z="2970", id=111811},
{x="2645", z="3058", id=111812},
{x="2641", z="2959", id=111812},
{x="2674", z="3048", id=111811},
}
They probably would remain in order, no need to sort.
Anyway, you have your order list so you would do something like
Code: Select all
for i = 1,36 do
local tile = tiles[orderlist[i]]
-- then do what ever you want to it while checking aggro etc,etc..
end