luigilc
Lua Learner
add this where? before then?
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)
local pos = getCreaturePosition(cid)
tp.x = tp.x + math.max(math.min(1, tp.x - pos.x), -1)
tp.y = tp.y + math.max(math.min(1, tp.y - pos.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
return true
end
local startLevelDistance = 40 -- at this level he will get his first distance advance (2 distance), until that it will remain as minDistance
local levelPerDistance = 20 -- each 20 level he gets another distance
local minDistance = 1 -- the distance you start with
local maxDistance = 5 -- At level 140 (startLevelDistance + levelPerDistance * maxDistance) he will have his max distance (5 in this case).
function onCastSpell(cid, var)
local dist = math.max(minDistance, math.min(maxDistance, math.floor((getPlayerLevel(cid) - startLevelDistance) / levelPerDistance) + minDistance))
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)
local pos = getCreaturePosition(cid)
tp.x = tp.x + math.max(math.min(1, tp.x - pos.x), -1)
tp.y = tp.y + math.max(math.min(1, tp.y - pos.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
return true
end
local startLevelDistance = 40 -- at this level he will get his first distance advance (2 distance), until that it will remain as minDistance
local levelPerDistance = 20 -- each 20 level he gets another distance
local minDistance = 1 -- the distance you start with
local maxDistance = 5 -- At level 140 (startLevelDistance + levelPerDistance * maxDistance) he will have his max distance (5 in this case).
function onCastSpell(cid, var)
local dist = math.max(minDistance, math.min(maxDistance, math.floor((getPlayerLevel(cid) - startLevelDistance) / levelPerDistance) + minDistance))
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 dmg = math.random(10, getPlayerLevel(cid)+10)
local monsters = {}
pos=getCreaturePosition(cid)
for x=1,9 do
for y=1,9 do
getpos={x=pos.x-5+x,y=pos.y-5+y,z=pos.z,stackpos=STACKPOS_TOP_CREATURE}
if isCreature(getTopCreature(getpos).uid) == TRUE then
table.insert(monsters, getTopCreature(getpos).uid)
end
end
end
for i= 1, dist do
for _, pid in ipairs(monsters) do
if isInRange(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then
local tp = getCreaturePosition(pid)
local pos = getCreaturePosition(cid)
tp.x = tp.x + math.max(math.min(1, tp.x - pos.x), -1)
tp.y = tp.y + math.max(math.min(1, tp.y - pos.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
return true
end
well I did it based on second colandus' version of the script, for repel all creatures (players, npcs, monsters, ...)
Lua:local startLevelDistance = 40 -- at this level he will get his first distance advance (2 distance), until that it will remain as minDistance local levelPerDistance = 20 -- each 20 level he gets another distance local minDistance = 1 -- the distance you start with local maxDistance = 5 -- At level 140 (startLevelDistance + levelPerDistance * maxDistance) he will have his max distance (5 in this case). function onCastSpell(cid, var) local dist = math.max(minDistance, math.min(maxDistance, math.floor((getPlayerLevel(cid) - startLevelDistance) / levelPerDistance) + minDistance)) 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 dmg = math.random(10, getPlayerLevel(cid)+10) local monsters = {} pos=getCreaturePosition(cid) for x=1,9 do for y=1,9 do getpos={x=pos.x-5+x,y=pos.y-5+y,z=pos.z,stackpos=STACKPOS_TOP_CREATURE} if isCreature(getTopCreature(getpos).uid) == TRUE then table.insert(monsters, getTopCreature(getpos).uid) end end end for i= 1, dist do for _, pid in ipairs(monsters) do if isInRange(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then local tp = getCreaturePosition(pid) local pos = getCreaturePosition(cid) tp.x = tp.x + math.max(math.min(1, tp.x - pos.x), -1) tp.y = tp.y + math.max(math.min(1, tp.y - pos.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 return true end
try adding
orLua:if not isNpc
Lua:if isNpc == FALSE