• 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!

Lua Spells that teleport player to target

Helliot1

Owner of Empire Online
Joined
Jul 26, 2017
Messages
315
Solutions
1
Reaction score
58
Hello, I have a problem here, I saw a spell that teleport you to a player that are in screen, but I'm using OTX3, and get a error when I use this spell

How I can fix it ??

Lua:
Lua Script Error: [Spell Interface]
data/spells/scripts/barbarian/blind rush.lua:onCastSpell
data/spells/scripts/barbarian/blind rush.lua:30: attempt to call global 'getPosByDir' (a nil value)
stack traceback:
        [C]: in function 'getPosByDir'
        data/spells/scripts/barbarian/blind rush.lua:30: in function <data/spells/scripts/barbarian/blind rush.lua:10>

This is the Script

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function getDamage(cid, level, magic)
return -(level * 5 + magic * 12), -(level * 5 + magic * 12 + 55)
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "getDamage")

function onCastSpell(cid, var)

    local target = getCreatureTarget(cid)
    if target <= 1 then
        doPlayerSendCancel(cid, "You need a target.")
    return false
    end
  
    if not isSightClear(getThingPos(cid), getThingPos(target), false) then
        doPlayerSendCancel(cid, "You can't reach that place.")
    return false
    end
  
    local targetPos = getThingPos(target)
    local directions = {0, 1, 2, 3, 4, 5, 6, 7}
    local teleportPos = {}
    for _ = 1, #directions do
        local random = math.random(#directions)
        local dir = directions[random]
        table.remove(directions, random)
        local newPos = getPosByDir(targetPos, dir)
        if doTileQueryAdd(cid, newPos, 0, false) == 1 then
            teleportPos = newPos
            break
        end
    end
  
    if teleportPos.x and doTileQueryAdd(cid, teleportPos, 0, false) == 1 then
        doCombat(cid, combat, var)
        doTeleportThing(cid, teleportPos, false)
    return true
    end
  
    doPlayerSendCancel(cid, "You cannot teleport there.")
return false
end
 
Hello, I have a problem here, I saw a spell that teleport you to a player that are in screen, but I'm using OTX3, and get a error when I use this spell

How I can fix it ??

Lua:
Lua Script Error: [Spell Interface]
data/spells/scripts/barbarian/blind rush.lua:onCastSpell
data/spells/scripts/barbarian/blind rush.lua:30: attempt to call global 'getPosByDir' (a nil value)
stack traceback:
        [C]: in function 'getPosByDir'
        data/spells/scripts/barbarian/blind rush.lua:30: in function <data/spells/scripts/barbarian/blind rush.lua:10>

This is the Script

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function getDamage(cid, level, magic)
return -(level * 5 + magic * 12), -(level * 5 + magic * 12 + 55)
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "getDamage")

function onCastSpell(cid, var)

    local target = getCreatureTarget(cid)
    if target <= 1 then
        doPlayerSendCancel(cid, "You need a target.")
    return false
    end
 
    if not isSightClear(getThingPos(cid), getThingPos(target), false) then
        doPlayerSendCancel(cid, "You can't reach that place.")
    return false
    end
 
    local targetPos = getThingPos(target)
    local directions = {0, 1, 2, 3, 4, 5, 6, 7}
    local teleportPos = {}
    for _ = 1, #directions do
        local random = math.random(#directions)
        local dir = directions[random]
        table.remove(directions, random)
        local newPos = getPosByDir(targetPos, dir)
        if doTileQueryAdd(cid, newPos, 0, false) == 1 then
            teleportPos = newPos
            break
        end
    end
 
    if teleportPos.x and doTileQueryAdd(cid, teleportPos, 0, false) == 1 then
        doCombat(cid, combat, var)
        doTeleportThing(cid, teleportPos, false)
    return true
    end
 
    doPlayerSendCancel(cid, "You cannot teleport there.")
return false
end

You're trying to call the function getPosByDir that either doesn't exist or isn't visible to that script, check if you have this function anywhere, if not, write it or replace it.
I don't know whether this function that I found in my libs is the same as what that one does, but it appears to fit, try putting it in your libs and using it here instead of getPosByDir

Lua:
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
 
Back
Top