Ir para conteúdo

TFS 1.2 - Tile Invisível


Administrador

Posts Recomendados

  • Administrador

Script feito por Codex NG. Basicamente, este script vai permitir que você faça uma tile (invisível) no qual os jogadores podem pisar.

function newGround(pos, id)
    local tile = Tile(pos)
    if not tile then
        Game.createTile(pos)
        tile = Tile(pos)
        return tile
    end
  
    if not tile:getItemById(id) then
        return Game.createItem(id, 1, pos)
    end
    return false
end
local id = 415 -- tile id
-- position of the base tile that floats across the screen
local pos = {x = 148, y = 148, z = 6, stackpos = 0}
-- the distance the tile will travel
local distance = 5
function removeGround(pos, id)
    tile = Tile(pos)
    if not tile then
        return false
    end
    local ground = tile:getGround()
    --print(ground, tile.itemid == id, tile, id, ground)
    if ground then
        ground:remove()
    end
    return pos
end

function updatePosition(pos, dir, num, stack)
    if dir == 'n' then
        pos = {x = pos.x, y = pos.y + num, z = pos.z, stackpos = stack and stack or ( pos.stackpos and pos.stackpos or 0 ) }
    elseif dir == 'e' then
        pos = {x = pos.x + num, y = pos.y, z = pos.z, stackpos = stack and stack or ( pos.stackpos and pos.stackpos or 0 ) }
    elseif dir == 's' then
        pos = {x = pos.x, y = pos.y - num, z = pos.z, stackpos = stack and stack or ( pos.stackpos and pos.stackpos or 0 ) }
    elseif dir == 'w' then
        pos = {x = pos.x - num, y = pos.y, z = pos.z, stackpos = stack and stack or ( pos.stackpos and pos.stackpos or 0 ) }
    end
    return pos
end

function relocate(fromPos, toPos)
    if fromPos == toPos then
        return false
    end

    local fromTile = Tile(fromPos)
    if fromTile == nil then
        return false
    end

    if Tile(toPos) == nil then
        return false
    end

    for i = fromTile:getThingCount() - 1, 0, -1 do
        local thing = fromTile:getThing(i)
        if thing ~= nil then
            if thing:isItem() then
                if ItemType(thing:getId()):isMovable() then
                    thing:moveTo(toPos, true)
                end
            elseif thing:isCreature() then
                thing:teleportTo(toPos, true)
            end
        end
    end
    return true
end
local limit = 1
local d = true
local storage = 18050
-- position of the base tile that floats across the screen
local globalPos = {x = 148, y = 148, z = 6, stackpos = 0}
local trackPos = {}
function onThink(creature, interval)
    --if creature:getStorageValue(storage) == 0 then
        if limit <= distance and d then
            if limit > 1 then
                removeGround(pos, id)
            end
            if limit <= distance and #trackPos <= distance then
                trackPos[#trackPos + 1] = pos
            end
            --creature:sendTextMessage(MESSAGE_INFO_DESCR, ' forward x = '..pos.x ..', y = ' .. pos.y .. ', z = '..pos.z..'')
            local old = pos
            pos = updatePosition(pos, 'e', 1, 0)
            relocate(old, pos)
            newGround(pos, id)
            limit = limit + 1
        else
            pos.x = pos.x >= globalPos.x and pos.x or globalPos.x
            d = false
            --creature:sendTextMessage(MESSAGE_INFO_DESCR, ' reverse x = '..pos.x ..', y = ' .. pos.y .. ', z = '..pos.z..'')
            removeGround(pos, id)
            local old = pos
            pos = updatePosition(pos, 'w', 1, 0)
            relocate(old, pos)
            newGround(pos, id)
            limit = limit - 1
            if limit == 2 then
                d = true
            end
        end
    --else
        --reset()
        --creature:sendTextMessage(MESSAGE_INFO_DESCR, 'before x = '..pos.x ..', y = ' .. pos.y .. ', z = '..pos.z..'')
        --print('before',pos.x, pos.y, pos.z)
        --pos = globalPos
        --print('after',pos.x, pos.y, pos.z)
        --creature:sendTextMessage(MESSAGE_INFO_DESCR, 'after x = '..pos.x ..', y = ' .. pos.y .. ', z = '..pos.z..'')
    --end
    --MoveTile(1, 6, pos, id, true, 'e', 'w')
end

function reset()
    for i = 1, #trackPos do
        removeGround(trackPos[i], id)
    end
    return Game.createItem(id, 1, updatePosition(globalPos, 'e', 1, 0))
end

function MoveTile(from, to, pos, id, go, forward, reverse)
    local dir = {}
    dir.forward = forward
    dir.reverse = reverse
    if from <= to and go then
        if from > 1 then
            removeGround(pos, id)
        end
        local old = pos
        pos = updatePosition(pos, dir.forward, 1, 0)
        relocate(old, pos)
        newGround(pos, id)
        from = from + 1
    else
        go = false
        removeGround(pos, id)
        local old = pos
        pos = updatePosition(pos, dir.reverse, 1, 0)
        relocate(old, pos)
        newGround(pos, id)
        from = from - 1
        if from == 2 then
            go = true
        end
    end
end
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...