Ir para conteúdo

script que valida se o player tem um iten na bp e da acesso ao teleport (como os teleports da warzone)

Featured Replies

Postado

.Qual servidor ou website você utiliza como base? client 13+

 

Qual o motivo deste tópico? não estou conseguindo fazer com que o script faça a verificação do iten no inventario 

 

Está surgindo algum erro? Se sim coloque-o aqui. 

Citar

[2024-09-04 10:53:42.332] [error] Lua Script Error Detected
---------------------------------------
Interface: Scripts Interface
Script ID: C:\otserv\data-otservbr-global/scripts\movements\thais\arena.lua:callback
Error Description: ...v\data-otservbr-global/scripts\movements\thais\arena.lua:14: attempt to call method 'getInventory' (a nil value)
stack traceback:
        [C]: in function 'getInventory'
        ...v\data-otservbr-global/scripts\movements\thais\arena.lua:14: in function 'playerHasTitaniumToken'
        ...v\data-otservbr-global/scripts\movements\thais\arena.lua:34: in function <...v\data-otservbr-global/scripts\movements\thais\arena.lua:28>

 

Você tem o código disponível? Se tiver publique-o aqui: 

local teleports = {
    { teleportPosition = { x = 32399, y = 32202, z = 7 }, teleportDestination = Position(32395, 32194, 7)},
    { teleportPosition = { x = 32400, y = 32202, z = 7 }, teleportDestination = Position(32395, 32194, 7)}
}
local TI_TITANIUM_TOKEN = 28493
 
local arena = MoveEvent()
 
function playerHasTitaniumToken(player)
    if not player then
        return false
    end
 
    local inventory = player:getInventory()
    if not inventory then
        return false
    end
 
    for _, item in ipairs(inventory:getItems()) do
        if item:getId() == TI_TITANIUM_TOKEN then
            return true
        end
    end
 
    return false
end
 
function arena.onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end
   
    if playerHasTitaniumToken(player) then
        local playerPosition = player:getPosition()
        for _, teleport in ipairs(teleports) do
            local teleportPos = Position(teleport.teleportPosition)
            if playerPosition == teleportPos then
                player:teleportTo(teleport.teleportDestination)
                return true
            end
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Você precisa do Titanium Token para acessar este teleport.")
    end
 
    return true
end
 
for _, teleport in ipairs(teleports) do
    arena:position(Position(teleport.teleportPosition))
end
arena:register()

 

Você tem alguma imagem que possa auxiliar no problema? Se sim, coloque-a aqui. 

 

Postado
local config = {
    teleports = {
        { teleportPosition = { x = 32399, y = 32202, z = 7 }, teleportDestination = Position(32395, 32194, 7)},
        { teleportPosition = { x = 32400, y = 32202, z = 7 }, teleportDestination = Position(32395, 32194, 7)}
    },
    TI_TITANIUM_TOKEN = 28493
}

function playerHasTitaniumToken(player)
    if not player then
        return false
    end

    local inventory = player:getItems()
    if not inventory then
        return false
    end

    for _, item in ipairs(inventory) do
        if item:getId() == config.TI_TITANIUM_TOKEN then
            return true
        end
    end

    return false
end

local arena = MoveEvent()

function arena.onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end
   
    if playerHasTitaniumToken(player) then
        local playerPosition = player:getPosition()
        for _, teleport in ipairs(config.teleports) do
            local teleportPos = Position(teleport.teleportPosition)
            if playerPosition == teleportPos then
                player:teleportTo(teleport.teleportDestination)
                return true
            end
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Você precisa do Titanium Token para acessar este teleport.")
    end

    return true
end

for _, teleport in ipairs(config.teleports) do
    arena:position(Position(teleport.teleportPosition))
end
arena:register()

 

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 520.1k

Informação Importante

Confirmação de Termo