• 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 Area teleport problem (spell)

Syryniss

Member
Joined
Feb 13, 2014
Messages
206
Reaction score
20
Hi. I wanted to make an 1x1 area spell which teleports all players in range to some place and then teleport them back after a while. I made script that was working, but was teleporting all players to 1 spot and I wanted to improve it, so teleported players are in the same distance from caster as they were before teleport. I hope you got what I mean, anyway after this change it stopped working, it teleports only caster. I know I made mistake somewhere in onCastSpell function, but I don't know where, so if anyone could help me, here it is :
Code:
local function doTeleportBack(cid, tid, pPos, pos)
     if isPlayer(cid) then
         doTeleportThing(cid, pos, false)
     end
     if isPlayer(tid) then
         doTeleportThing(tid, pPos, false)
     end
   
     doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
    doSendMagicEffect(pPos, CONST_ME_POFF)
    return true
end


function onCastSpell(cid, var)

    local area1 = { x=1100, y=44, z=7 }
    local pos = getCreaturePosition(cid)

for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1, false)) do
        if(isPlayer(tid) and getPlayerAccess(tid) <= 1) then
            local pPos = getCreaturePosition(tid)
                if pPos == { x=pos.x, y=pos.y + 1, z=pos.z } then
                    doTeleportThing(tid, { x=area1.x, y=area1.y + 1, z=area1.z }, false)
                elseif pPos == { x=pos.x, y=pos.y - 1, z=pos.z } then
                    doTeleportThing(tid, { x=area1.x, y=area1.y - 1, z=area1.z }, false)
                elseif pPos == { x=pos.x + 1, y=pos.y , z=pos.z } then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y, z=area1.z }, false)
                elseif pPos == { x=pos.x - 1, y=pos.y , z=pos.z } then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y, z=area1.z }, false)
                elseif pPos == { x=pos.x + 1, y=pos.y + 1, z=pos.z } then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos == { x=pos.x - 1, y=pos.y - 1, z=pos.z } then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y - 1, z=area1.z }, false)
                elseif pPos == { x=pos.x - 1, y=pos.y + 1, z=pos.z } then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos == { x=pos.x + 1, y=pos.y - 1, z=pos.z } then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y - 1, z=area1.z }, false)
                end
            doTeleportThing(cid, area1, false)
            addEvent(doTeleportBack, 4 * 1000, cid, tid, pPos, pos)
        end
    end
    return true
    end
 
Last edited:
Okey, I got it now. The last thing I wanted to do is randomize areas where players get teleported by this skill. I have never used random function, so I will probably need some help with that. Now it looks like this :
Code:
local function doTeleportBack(cid, tid, pPos, pos)
     if isPlayer(cid) then
         doTeleportThing(cid, pos, false)
     end
     if isPlayer(tid) then
         doTeleportThing(tid, pPos, false)
     end
     
     doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
    doSendMagicEffect(pPos, CONST_ME_POFF)
    return true
end


function onCastSpell(cid, var)

    local teleports = {
    area3 = { x=1100, y=44, z=7 },
    area4 = { x=87, y=466, z=7 }
    }
   
    local area1 = math.random(#teleports)
    local pos = getCreaturePosition(cid)

for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1, false)) do
        if(isPlayer(tid) and getPlayerAccess(tid) <= 1) then
            local pPos = getCreaturePosition(tid)
                if pPos.x == pos.x and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x, y=area1.y - 1, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y, z=area1.z }, false)
                elseif pPos.x == pos.x -1 and pPos.y == pos.y and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x - 1 and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y - 1, z=area1.z }, false)
                elseif pPos.x == pos.x - 1 and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y - 1, z=area1.z }, false)
                end
            doTeleportThing(cid, area1, false)
            addEvent(doTeleportBack, 5 * 1000, cid, tid, pPos, pos)
        end
    end
    return true
    end

The error I get with that:
Code:
[20/02/2014 14:44:13] [Error - Spell Interface] 
[20/02/2014 14:44:13] data/spells/scripts/naruto/teleport.lua:onCastSpell
[20/02/2014 14:44:13] Description: 
[20/02/2014 14:44:13] data/spells/scripts/teleport.lua:22: bad argument #1 to 'random' (interval is empty)
[20/02/2014 14:44:13] stack traceback:
[20/02/2014 14:44:13]     [C]: in function 'random'
[20/02/2014 14:44:13]     data/spells/scripts/teleport.lua:22: in function <data/spells/scripts/teleport.lua:15>
 
Code:
local function doTeleportBack(cid, tid, pPos, pos)
    if isPlayer(cid) then
        doTeleportThing(cid, pos, false)
    end
    if isPlayer(tid) then
        doTeleportThing(tid, pPos, false)
    end
   
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
    doSendMagicEffect(pPos, CONST_ME_POFF)
    return true
end


function onCastSpell(cid, var)

    local teleports = {{ x=1100, y=44, z=7 }, { x=87, y=466, z=7 }}

 
    local area1 = teleports[math.random(1,#teleports)]
    local pos = getCreaturePosition(cid)

for i, tid in ipairs(getSpectators(getCreaturePosition(cid), 1, 1, false)) do
        if(isPlayer(tid) and getPlayerAccess(tid) <= 1) then
            local pPos = getCreaturePosition(tid)
                if pPos.x == pos.x and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x, y=area1.y - 1, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y, z=area1.z }, false)
                elseif pPos.x == pos.x -1 and pPos.y == pos.y and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x - 1 and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y - 1, z=area1.z }, false)
                elseif pPos.x == pos.x - 1 and pPos.y == pos.y + 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x - 1, y=area1.y + 1, z=area1.z }, false)
                elseif pPos.x == pos.x + 1 and pPos.y == pos.y - 1 and pPos.z == pos.z then
                    doTeleportThing(tid, { x=area1.x + 1, y=area1.y - 1, z=area1.z }, false)
                end
            doTeleportThing(cid, area1, false)
            addEvent(doTeleportBack, 5 * 1000, cid, tid, pPos, pos)
        end
    end
    return true
    end
 
Back
Top