-- Coordenadas padrão para o ponto de destino
local defaultDestinationX, defaultDestinationY, defaultDestinationZ = 123, 456, 789
-- Variável para armazenar o jogador local
local localPlayer = getLocalPlayer()
-- Variável para controlar a visibilidade do painel
local isTeleportPanelVisible = false
-- Função para teleportar o jogador local até o jogador selecionado
function teleportLocalPlayerToSelectedPlayer()
-- Obter o jogador selecionado na lista
local selectedRow, selectedColumn = guiGridListGetSelectedItem(playerList)
if selectedRow and selectedRow ~= -1 then
local playerName = guiGridListGetItemText(playerList, selectedRow, 1)
-- Encontrar o jogador pelo nome
local selectedPlayer = getPlayerFromName(playerName)
if selectedPlayer then
-- Teleportar o jogador local até o jogador selecionado
setElementPosition(localPlayer, getElementPosition(selectedPlayer))
-- Fechar a janela após o teleporte
guiSetVisible(teleportWindow, false)
showCursor(false)
isTeleportPanelVisible = false
end
end
end
-- Função para criar o painel de teleporte
function createTeleportPanel()
-- Verificar se o painel já está visível
if isTeleportPanelVisible then
guiSetVisible(teleportWindow, false)
showCursor(false)
isTeleportPanelVisible = false
return
end
-- Obter a lista de jogadores online
local players = getElementsByType("player")
-- Criar a janela
local screenWidth, screenHeight = guiGetScreenSize()
local windowWidth, windowHeight = 300, 200
local windowX, windowY = (screenWidth - windowWidth) / 2, (screenHeight -
windowHeight) / 2
teleportWindow = guiCreateWindow(windowX, windowY, windowWidth, windowHeight,
"Teleportar Jogador", false)
-- Criar a lista de jogadores
playerList = guiCreateGridList(10, 30, windowWidth - 20, windowHeight - 70,
false, teleportWindow)
guiGridListAddColumn(playerList, "Jogadores Online", 0.9)
-- Adicionar os jogadores à lista
for _, player in ipairs(players) do
local row = guiGridListAddRow(playerList)
guiGridListSetItemText(playerList, row, 1, getPlayerName(player), false,
false)
end
-- Criar o botão de teleporte
local teleportButton = guiCreateButton(10, windowHeight - 30, windowWidth - 20,
20, "Teleportar", false, teleportWindow)
-- Adicionar um manipulador de evento para o botão
addEventHandler("onClientGUIClick", teleportButton,
teleportLocalPlayerToSelectedPlayer, false)
-- Tornar a janela visível
guiSetVisible(teleportWindow, true)
showCursor(true)
isTeleportPanelVisible = true
end
-- Adicionar um comando para abrir o painel de teleporte
addCommandHandler("teleport", createTeleportPanel)
-- Adicionar uma tecla para abrir/fechar o painel (F5 neste exemplo)
bindKey("F5", "down", function()
createTeleportPanel()
end)
-- Atualiza a lista de jogadores a cada 5 segundos
setTimer(updatePlayerList, 5000, 0)
updatePlayerList()