Skip to content
User Avatar
#3814
Auto-translated
}{0TT@6bI4
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

 

Still, it's not quite working. I wrote a script to save coordinates 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]))