function shuffleTable(tab)
local n, order, res = #tab, {}, {}
for i = 1,n do
order[i] = {rnd = math.random(), idx = i}
end
table.sort(order, function(a,b) return a.rnd < b.rnd end)
for i = 1,n do
res[i] = tab[order[i].idx]
end
return res
end
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_NONE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_NONE)
local chance = 99
local locations = {
{x = 31676, y = 32316, z = 11},
{x = 31695, y = 32298, z = 12},
{x = 31679, y = 32299, z = 12},
}
function onCastSpell(cid, var)
if math.random(100) <= chance then
locations = shuffleTable(locations)
for i = 1, #locations do
local tile = Tile(locations[i])
if tile and tile:getCreatureCount() == 0 and not tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) then
creature:teleportTo(locations[i], false)
break
end
end
end
end