Ir para conteúdo
  • 0

Spell Teleport Aleatorio


Vasto Lord X

Pergunta

Eu Queria Uma Spell Que Teleporta-se o Player Aleatoriamente Numa Areá 4x4 .

 

Exemplo: To Preso Numa Trap Usa e Sou Teleportado Para Fora Dela Aleatoriamente Para Um Lugar Perto de Min Que Não Tem Parede Nem PZ Nem Água .

 

 

 

Nota : Eu Já Um Spell Desse Em Um NTO


@UP


@UP


@UP


@UP

 


@UP


@UP

Link para o comentário
Compartilhar em outros sites

10 respostass a esta questão

Posts Recomendados

  • 0

OK.

local teleport_area = {                         --Área com as posições que o jogador pode ser teleportado.
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}, 
    {0, 0, 1, 1, 1, 2, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
}
local exhaust_time = xxx                        --Exhaust, em segundos.

function onCastSpell(cid)
    local area_positions = getPosfromArea(cid, teleport_area)
    local position = area_positions[math.random(#area_positions)]
    
    if getPlayerStorageValue(cid, 2019) > os.time() then
        doPlayerSendCancel(cid, "Wait "..getPlayerStorageValue(cid, 2019) - os.time().." second(s) to use this spell again.")
        return true
    end
    
    if not isWalkable(position) or getTileInfo(position).protection then
        while not isWalkable(position) do
            position = area_positions[math.random(#area_positions)]
        end
    end
    
    doTeleportThing(cid, position)
    setPlayerStorageValue(cid, 2019, os.time() + exhaust_time)
    return true
end
Link para o comentário
Compartilhar em outros sites

  • 0

Em algum arquivo da lib, coloque as seguintes funções:

 

 

------------------ Function getPosfromArea(cid,area) by Dokmos ------------------
function getPosfromArea(cid,area)
    icenter = math.floor(table.getn(area)/2)+1
    jcenter = math.floor(table.getn(area[1])/2)+1
    center = area[icenter]
    ivar = table.getn(area)
    jvar = table.getn(area[1])
    i = table.getn(area)^2
    j = table.getn(area[1])^2

    local mydir = isCreature(getMasterTarget(cid)) and getCreatureDirectionToTarget(cid, getMasterTarget(cid)) or getCreatureLookDir(cid)
    setPlayerStorageValue(cid, 21101, -1)  --alterado v1.6

    if center[jcenter] == 3 then
        if mydir == 0 then
            signal = {-1,1,1,2}
        elseif mydir == 1 then
            signal = {1,-1,2,1}
        elseif mydir == 2 then
            signal = {1,-1,1,2}
        elseif mydir == 3 then
            signal = {-1,1,2,1}
        end
    else
        signal = {-1,1,1,2}
    end

    POSITIONS = {}  
    P = 0 

    repeat
        pvar = {0,0}
        I = area[ivar]
        J = I[jvar]
        i = i-1
        j = j-1
        if J == 1 then
            if jvar < jcenter then  
                pvar[signal[3]] = signal[1]*math.abs((jcenter-jvar)) 
            elseif jvar > jcenter then  
                pvar[signal[3]] = signal[2]*math.abs((jcenter-jvar)) 
            end

            if ivar < icenter then  
                pvar[signal[4]] = signal[1]*math.abs((icenter-ivar)) 
            elseif ivar > icenter then
                pvar[signal[4]] = signal[2]*math.abs((icenter-ivar))
            end
        end    
        if jvar > 1 then
            jvar = (jvar-1)
        elseif ivar > 1 then
            jvar = table.getn(area[1])
            ivar = (ivar-1)
        end  
        local pos = getThingPos(cid)
        local areapos = {x=pos.x+(pvar[1]),y=pos.y+(pvar[2]),z=pos.z}  

        if pos.x ~= areapos.x or pos.y ~= areapos.y then
            P = P+1
            POSITIONS[P] = areapos
        end 

    until i <= 0 and j <= 0

    return POSITIONS
end

function isWalkable(pos, creature, proj, pz)-- by Nord
    if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
    if getTopCreature(pos).uid > 0 and creature then return false end
    if getTileInfo(pos).protection and pz then return false, true end
    local n = not proj and 2 or 2
    for i = 0, 255 do
        pos.stackpos = i
        local tile = getTileThingByPos(pos)
        if tile.itemid ~= 0 and not isCreature(tile.uid) then
            if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
                return false
            end
        end
    end
    return true
end

 

 

 

Código da spell:

local teleport_area = {                         --Área com as posições que o jogador pode ser teleportado.
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0}, 
    {0, 0, 1, 1, 1, 2, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 
}

function onCastSpell(cid)
    local area_positions = getPosfromArea(cid, teleport_area)
    local position = area_positions[math.random(#area_positions)]
    
    if not isWalkable(position) or getTileInfo(position).protection then
        while not isWalkable(position) do
            position = area_positions[math.random(#area_positions)]
        end
    end
    
    doTeleportThing(cid, position)
    return true
end
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...