function onCastSpell(cid, var)
local c, t, tar, area, pos = {}, {}, {}, AREA_CROSS5X5, getThingPos(cid)
c.y = math.floor(#area/2)+1
local god = getPlayerFlagValue(cid, PLAYERFLAG_IGNOREPROTECTIONZONE)
for y = 1, #area do
for x = 1, #area[y] do
local n = area[y][x]
if n ~= 0 then
c.x = math.floor(table.getn(area[y])/2)+1
local p = {x = pos.x + x - c.x, y = pos.y + y - c.y, z = pos.z}
if isSightClear(pos, p, false) then
local g, skip = getThingfromPos(p, false)
if g.uid ~= 0 and not hasItemProperty(g.uid, CONST_PROP_BLOCKPROJECTILE) and (god or not getTileInfo(p).protection) and getTileItemByType(p, ITEM_TYPE_TELEPORT).uid == 0 then
local f = getItemInfo(g.itemid).floorChange
for i = 1, #f do
if f[i] then
skip = true
break
end
end
elseif g.uid ~= 0 then
skip = true
end
if not skip then
table.insert(t, p)
local n = getTileInfo(p).creatures
if n ~= 0 then
p.stackpos = 1
local v = getThingfromPos(p).uid
while v ~= 0 do
if v ~= cid and isCreature(v) then
table.insert(tar, v)
if n == #tar then
break
end
end
p.stackpos = p.stackpos + 1
v = getThingfromPos(p).uid
end
end
end
end
end
end
end
local lvl, mag = getPlayerLevel(cid), getPlayerMagLevel(cid)
local dmg = math.random(
lvl / 5 + mag * 6,
lvl / 5 + mag * 12
) * (math.max(0.1, 1 - (#tar * 0.1)))
for i = 1, #tar do
if isPlayer(tar[i]) then
local dmg = dmg / 2
if hasCondition(tar[i], CONDITION_MANASHIELD) then
local mana = getCreatureMana(tar[i])
doTargetCombatMana(cid, tar[i], -dmg, -dmg, CONST_ME_NONE)
if dmg > mana and getCreatureMana(tar[i]) == 0 then
dmg = dmg - mana
doTargetCombatHealth(cid, tar[i], COMBAT_ICEDAMAGE, -dmg, -dmg, CONST_ME_NONE)
end
else
doTargetCombatHealth(cid, tar[i], COMBAT_ICEDAMAGE, -dmg, -dmg, CONST_ME_NONE)
end
else
doTargetCombatHealth(cid, tar[i], COMBAT_ICEDAMAGE, -dmg, -dmg, CONST_ME_NONE)
end
end
for i = 1, #t do
doSendMagicEffect(t[i], CONST_ME_ICETORNADO)
end
return true
end