Both in combat and on the adventure map, when a creature is spawned on an occupied tile, it will spawn on the nearest available tile.
Overall, there's nothing particularly complicated about it.function SaveCreaturePos(table, mob)
local x, y, z = GetObjectPosition(mob)
creature_coord_table[mob] = {x=x, y=y, floor=z}
end --Something like this
function SaveCoordinates( table )
local monster_list = {};
local k = 0;
for i=1,500 do
monster = "m"..i;
if IsObjectExists( monster ) then
k = k + 1;
monster_list[k] = monster;
local x, y, z = GetObjectPosition(monster_list[k])
creatures_positions[k] = {x=x, y=y, floor=z}
end;
end;
end;Then, in another function, I try to take a random position from this list and place a creature on it, but the game gives an error because x, y, and z are empty. In another function, I wrote the coordinate retrieval like this:
for k=1, length(creatures_positions) do
local x, y, z = random(length(creatures_positions[k]))