lib necessária (você pode adicionar no início do script, ou então criar um outro arquivo .lua com qualquer nome em data/lib e colocar isso dentro):
function newXYvar(x, y, voltas_horarias)
while voltas_horarias > 3 do
voltas_horarias = voltas_horarias - 4
end
if voltas_horarias <= 0 then
return x, y
elseif voltas_horarias == 1 then
return -y, x
elseif voltas_horarias == 2 then
return -x, -y
elseif voltas_horarias == 3 then
return y, -x
end
return 0, 0
end
function arrayToPositions(array, center, n_horario)
if not center or not center.x or not center.y or not center.z then return {} end
local voltas, mp, ret, iIs, x, y = n_horario and math.max(0, n_horario) or 0, {}, {}, {}, 1, 1
if voltas > 0 then
local maxC = 0
for lines = 1, #array do if maxC < #array[lines] then maxC = #array[lines] end end
if maxC < #array then maxC = #array end
for a = 1, maxC do iIs[a] = {} for b = 1, maxC do table.insert(iIs[a], 0) end end
end
while #mp == 0 do
local check = array[y][x]
if check > 1 then
mp = {x, y}
if voltas > 0 then iIs[y][x] = check end
if check == 3 then table.insert(ret, center) end
break
end
x = x + 1
if x > #array[y] then
y, x = y + 1, 1
if y > #array then break end
end
end
for ly, ny in pairs (array) do
for lx, nx in pairs (ny) do
if nx == 1 then
local dx, dy = lx - mp[1], ly - mp[2]
local newX, newY = newXYvar(dx, dy, voltas)
local newPos = {x = center.x + newX, y = center.y + newY, z = center.z}
table.insert(ret, newPos)
end
end
end
return ret
end
magia criano item:
elseif spell == "?" then
local itemId = 1990
local timeToRemove = 2500
local function damage(cid, area)
if not isCreature(cid) then return end
doAreaCombatHealth(cid, FIREDAMAGE, getThingPositionWithDebug(cid), area, -min, -max, 255)
local positions = arrayToPositions(area, getThingPositionWithDebug(cid))
for _, pos in pairs (positions) do
doCreateItem(itemId, 1, pos)
addEvent(function()
local i = getTileItemById(pos, itemId)
if i.uid > 0 then doRemoveItem(i.uid) end
end, timeToRemove)
end
end
local areas = {teste1, teste2, teste3, teste4, teste5}
for _, area in pairs (areas) do
addEvent(damage, 200 * (_ - 1), cid, area)
end
end
magia criando monstro (precisa ter o "backupPos" configurado):
elseif spell == "?" then
local monsterName = "Monster"
local timeToRemove = 2500
local function damage(cid, area)
if not isCreature(cid) then return end
doAreaCombatHealth(cid, FIREDAMAGE, getThingPositionWithDebug(cid), area, -min, -max, 255)
local positions = arrayToPositions(area, getThingPositionWithDebug(cid))
for _, pos in pairs (positions) do
local newMonster = doCreateMonster(monsterName, backupPos, false)
if newMonster > 1 then
doTeleportThing(newMonster, pos, false)
addEvent(function()
if isCreature(newMonster) then doRemoveCreature(newMonster) end
end, timeToRemove)
end
end
end
local areas = {teste1, teste2, teste3, teste4, teste5}
for _, area in pairs (areas) do
addEvent(damage, 200 * (_ - 1), cid, area)
end
end