• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Magic wall rune

freddzor11

Member
Joined
May 25, 2009
Messages
695
Reaction score
5
Hello! I got a small problem here... I use this magic wall rune script right now and that's good because you cannot magic wall inside zombie etc but now I can't even magic wall in town now, could someone fix this magicwall script?

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, 1497)
local ctfArena = {
frompos = {x=720, y=985, z=7},
topos = {x=756, y=1012, z=7},
}
local warArena = {
frompos = {x=716, y=937, z=7},
topos = {x=726, y=947, z=7},
}

function onCastSpell(cid, var)
if not isInArea(getPlayerPosition(cid), ctfArena.frompos, ctfArena.topos) and not isInArea(getPlayerPosition(cid), warArena.frompos, warArena.topos) and not isInArea(getPlayerPosition(cid), satanQuest.frompos, satanQuest.topos) then
return doCombat(cid, combat, var)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You may not use this rune here.")
end
end
 
Code:
[Error - Spell Interface]
data/spells/scripts/support/magic wall rune.lua:onCastSpell
Description:
data/lib/032-position.lua:2: attempt to compare nil with number
stack traceback:
        data/lib/032-position.lua:2: in function 'isInRange'
        data/spells/scripts/support/magic wall rune.lua:15: in function <data/sp
ells/scripts/support/magic wall rune.lua:12>

my magic wall script
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITBYFIRE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_FIRE)
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, 1492)

local t = {
{{x=716, y=937, z=7}, {x=726, y=947, z=7}},
{{x=720, y=985, z=7}, {x=756, y=1012, z=7}}
}

function onCastSpell(cid, var)
local pos = getThingPos(cid)
for i = 1, #t do
if isInRange(pos, unpack(t)) then
doPlayerSendCancel(cid, "You cannot use this spell in this area.")
doSendMagicEffect(pos, CONST_ME_POFF)
return false
end
end

return doCombat(cid, combat, var)
end

lib/032-position
Code:
function isInRange(position, fromPosition, toPosition)
    return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

function getDistanceBetween(firstPosition, secondPosition)
    local x, y = math.abs(firstPosition.x - secondPosition.x), math.abs(firstPosition.y - secondPosition.y)
    local diff = math.max(x, y)
    if(firstPosition.z ~= secondPosition.z) then
        diff = diff + 9 + 6
    end

    return diff
end

function getDirectionTo(pos1, pos2)
    local dir = NORTH
    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end
    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end
    else
        if(pos1.y > pos2.y) then
            dir = NORTH
        elseif(pos1.y < pos2.y) then
            dir = SOUTH
        end
    end
    return dir
end

function getCreatureLookPosition(cid)
    return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid))
end

function getPosByDir(fromPosition, direction, size)
    local n = size or 1

    local pos = fromPosition
    if(direction == NORTH) then
        pos.y = pos.y - n
    elseif(direction == SOUTH) then
        pos.y = pos.y + n
    elseif(direction == WEST) then
        pos.x = pos.x - n
    elseif(direction == EAST) then
        pos.x = pos.x + n
    elseif(direction == NORTHWEST) then
        pos.y = pos.y - n
        pos.x = pos.x - n
    elseif(direction == NORTHEAST) then
        pos.y = pos.y - n
        pos.x = pos.x + n
    elseif(direction == SOUTHWEST) then
        pos.y = pos.y + n
        pos.x = pos.x - n
    elseif(direction == SOUTHEAST) then
        pos.y = pos.y + n
        pos.x = pos.x + n
    end

    return pos
end

function doComparePositions(pos, posEx)
    return pos.x == posEx.x and pos.y == posEx.y and pos.z == posEx.z
end

function getArea(pos, rangeX, rangeY)
    local t = {}
    for i = (pos.x - rangeX), (pos.x + rangeX) do
        for j = (pos.y - rangeY), (pos.y + rangeY) do
            table.insert(t, {x = i, y = j, z = pos.z})
        end
    end

    return t
end
 
PHP:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
function MagicWallTime(pos, delay)
doSendAnimatedText(pos, delay, 215)
if delay ~= 1 then addEvent(MagicWallTime, 1000, pos, delay -1) end
end
function onCastSpell(cid, var)
local pos = variantToPosition(var)
if getTileInfo(getThingPos(cid)).protection or getTileInfo(pos).protection then
return not doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE)
end
local pos,duration = variantToPosition(var),20
MagicWallTime(pos,duration)
local v = getTileItemByType(pos, ITEM_TYPE_MAGICFIELD).uid
if v ~= 0 then
doRemoveItem(v)
end

v = doCreateItemEx(1497)
if doTileAddItemEx(pos, v) == 1 and getTileItemByType(pos, ITEM_TYPE_MAGICFIELD).uid ~= 0 then
doDecayItem(v)
return doCombat(cid, combat, var)
else
return not doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHROOM)
end
end

i any one can change that to make it not throw magic wall in no pvp zone
 
Change your 032-position script to this..
Code:
function isInRange(position, fromPosition, toPosition)
  return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z
      and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

function getDistanceBetween(fromPosition, toPosition)
  local x, y = math.abs(fromPosition.x - toPosition.x), math.abs(fromPosition.y - toPosition.y)
  local diff = math.max(x, y)
  if(fromPosition.z ~= toPosition.z) then
      diff = diff + 9 + 6
  end

  return diff
end

function getDirectionTo(pos1, pos2)
  local dir = SOUTH
  if(pos1.x > pos2.x) then
      dir = WEST
      if(pos1.y > pos2.y) then
        dir = NORTHWEST
      elseif(pos1.y < pos2.y) then
        dir = SOUTHWEST
      end
  elseif(pos1.x < pos2.x) then
      dir = EAST
      if(pos1.y > pos2.y) then
        dir = NORTHEAST
      elseif(pos1.y < pos2.y) then
        dir = SOUTHEAST
      end
  elseif(pos1.y > pos2.y) then
      dir = NORTH
  elseif(pos1.y < pos2.y) then
      dir = SOUTH
  end

  return dir
end

function getCreatureLookPosition(cid)
  return getPositionByDirection(getThingPosition(cid), getCreatureLookDirection(cid))
end

function getPositionByDirection(position, direction, size)
  local n = size or 1
  if(direction == NORTH) then
      position.y = position.y - n
  elseif(direction == SOUTH) then
      position.y = position.y + n
  elseif(direction == WEST) then
      position.x = position.x - n
  elseif(direction == EAST) then
      position.x = position.x + n
  elseif(direction == NORTHWEST) then
      position.y = position.y - n
      position.x = position.x - n
  elseif(direction == NORTHEAST) then
      position.y = position.y - n
      position.x = position.x + n
  elseif(direction == SOUTHWEST) then
      position.y = position.y + n
      position.x = position.x - n
  elseif(direction == SOUTHEAST) then
      position.y = position.y + n
      position.x = position.x + n
  end

  return position
end

function doComparePositions(position, positionEx)
  return position.x == positionEx.x and position.y == positionEx.y and position.z == positionEx.z
end

function getArea(position, x, y)
  local t = {}
  for i = (position.x - x), (position.x + x) do
      for j = (position.y - y), (position.y + y) do
        table.insert(t, {x = i, y = j, z = position.z})
      end
  end

  return t
end

function Position(x, y, z, stackpos)
  local position = {x = 0, y = 0, z = 0}
  if(isNumeric(x .. y .. z)) then
      position = {x = x, y = y, z = z}
      if(isNumeric(stackpos)) then
        position.stackpos = stackpos
      end
  end

  return position
end

function isValidPosition(position)
  return (isNumeric(position.x .. position.y .. position.z) and position.x > 0
      and position.y > 0 and position.z >= 0 and position.z <= 15)
end
 
PHP:
if getTileInfo(getThingPos(cid)).protection or getTileInfo(pos).protection then
return not doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE)
end

this line any one can change it to no pvp zone not protection zone
 
PHP:
if getTileInfo(getThingPos(cid)).protection or getTileInfo(pos).protection then
return not doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE)
end

this line any one can change it to no pvp zone not protection zone
Why would you post that twice?
 
could u give us the fixed mw

It's doesn't work in non-pvp area
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)

function onCastSpell(cid, var)
    local pos = variantToPosition(var)
    if getTileInfo(getThingPos(cid)).protection then
        return not doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE)
    else
        local s = getTileInfo(pos)
        if s.protection then
            return not doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINPROTECTIONZONE)
        elseif s.nopvp then
            return not doPlayerSendCancel(cid, 'You can\'t use this rune here.')
        end
    end

    local v = getTileItemByType(pos, ITEM_TYPE_MAGICFIELD).uid
    if v ~= 0 then
        doRemoveItem(v)
    end

    v = doCreateItemEx(1497)
    if doTileAddItemEx(pos, v) == 1 and getTileItemByType(pos, ITEM_TYPE_MAGICFIELD).uid ~= 0 then
        doDecayItem(v)
        return doCombat(cid, combat, var)
    else
        return not doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHROOM)
    end
end
 
Back
Top