function getDistance(cid)
local tile = {{20, 1},{40, 2},{60, 3},{80, 4},{100, 5}}
table.sort(tile, function(a, b) return a[1] > b[1] end)
for _, t in ipairs(tile) do
if(getPlayerLevel(cid) >= t[1]) then
return t[2]
end
end
return tile[1][2]
end
function onCastSpell(cid, var)
local dist = getDistance(cid)
local areaPosition = {
{x=getCreaturePosition(cid).x-dist, y=getCreaturePosition(cid).y-dist, z=getCreaturePosition(cid).z, stackpos = 255},
{x=getCreaturePosition(cid).x+dist, y=getCreaturePosition(cid).y+dist, z=getCreaturePosition(cid).z, stackpos = 255}
}
local players = getPlayersOnline()
local dmg = math.random(10, getPlayerLevel(cid)+10)
for i= 1, dist do
for _, pid in ipairs(players) do
if isInRange(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then
local tp = getCreaturePosition(pid)
if (tp.x < getCreaturePosition(cid).x) and (tp.y < getCreaturePosition(cid).y) then
tp.x = tp.x-1
tp.y = tp.y-1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
elseif (tp.x < getCreaturePosition(cid).x) and (tp.y > getCreaturePosition(cid).y) then
tp.x = tp.x-1
tp.y = tp.y+1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
elseif (tp.x < getCreaturePosition(cid).x) and (tp.y == getCreaturePosition(cid).y) then
tp.x = tp.x-1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
elseif (tp.x > getCreaturePosition(cid).x) and (tp.y < getCreaturePosition(cid).y) then
tp.x = tp.x+1
tp.y = tp.y-1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
elseif (tp.x > getCreaturePosition(cid).x) and (tp.y > getCreaturePosition(cid).y) then
tp.x = tp.x+1
tp.y = tp.y+1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
elseif (tp.x > getCreaturePosition(cid).x) and (tp.y == getCreaturePosition(cid).y) then
tp.x = tp.x+1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
elseif (tp.x == getCreaturePosition(cid).x) and (tp.y < getCreaturePosition(cid).y) then
tp.y = tp.y-1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
elseif (tp.x == getCreaturePosition(cid).x) and (tp.y > getCreaturePosition(cid).y) then
tp.y = tp.y+1
if isWalkable(tp, true) and not getTileInfo(tp).protection then
doSendMagicEffect(getCreaturePosition(pid), 34)
doTeleportThing(pid, tp, true)
doTargetCombatHealth(cid, pid, COMBAT_PHYSICALDAMAGE, -dmg, -dmg, CONST_ME_BLOCKHIT)
doSendMagicEffect(getCreaturePosition(pid), 34)
else
doSendMagicEffect(getCreaturePosition(pid), CONST_ME_POFF)
end
end
end
end
end
return true
end