Jump to content

"output" cordenadas para txt


Recommended Posts


function getpos (source)
x,y,z = getElementPosition(source)
interior = getElementInterior(source)
Dim = getElementDimension(source)
zone = getZoneName(x, y, z, false)
city = getZoneName(x, y, z, true)
r1,r2,r3 = getElementRotation(source)
outputChatBox("Your Rotation is: "..tostring(r1)..", "..tostring(r2)..", "..tostring(r3)..".", source, 0, 255, 0)
outputChatBox("You are at: "..tostring(x)..", "..tostring(y)..", "..tostring(z)..".", source, 0, 255, 0)
if fileHandle then   
    fileSetPos( fileHandle, fileGetSize( fileHandle ) )
    fileWrite(fileHandle, ""..tostring(x)..", "..tostring(y)..", "..tostring(z)..". rotation: "..tostring(r1)..", "..tostring(r2)..", "..tostring(r3)..".")     -- write a text line
    fileFlush(fileHandle)                       
    fileClose(fileHandle)                             
end
end
addCommandHandler("getpos", getpos)

Alguma ideia de como fazer funcionar? ele funciona uma vez porem quando executa o comando novamente não funciona como o esperado, gostaria que ele listasse as pos em tabela no txt

Link to comment
  • Scripting Moderators

Hi, welcome to the forums!

Your thread has been moved to the Portuguese section so you can get better help in your native language!
Make sure to always use English when posting outside this language-specific section!

Link to comment
5 hours ago, Duff1995 said:

function getpos (source)
x,y,z = getElementPosition(source)
interior = getElementInterior(source)
Dim = getElementDimension(source)
zone = getZoneName(x, y, z, false)
city = getZoneName(x, y, z, true)
r1,r2,r3 = getElementRotation(source)
outputChatBox("Your Rotation is: "..tostring(r1)..", "..tostring(r2)..", "..tostring(r3)..".", source, 0, 255, 0)
outputChatBox("You are at: "..tostring(x)..", "..tostring(y)..", "..tostring(z)..".", source, 0, 255, 0)
if fileHandle then   
    fileSetPos( fileHandle, fileGetSize( fileHandle ) )
    fileWrite(fileHandle, ""..tostring(x)..", "..tostring(y)..", "..tostring(z)..". rotation: "..tostring(r1)..", "..tostring(r2)..", "..tostring(r3)..".")     -- write a text line
    fileFlush(fileHandle)                       
    fileClose(fileHandle)                             
end
end
addCommandHandler("getpos", getpos)

Alguma ideia de como fazer funcionar? ele funciona uma vez porem quando executa o comando novamente não funciona como o esperado, gostaria que ele listasse as pos em tabela no txt

function getpos (source)
    x,y,z = getElementPosition(source)
    interior = getElementInterior(source)
    Dim = getElementDimension(source)
    zone = getZoneName(x, y, z, false)
    city = getZoneName(x, y, z, true)
    r1,r2,r3 = getElementRotation(source)
    outputChatBox("Your Rotation is: "..tostring(r1)..", "..tostring(r2)..", "..tostring(r3)..".", source, 0, 255, 0)
    outputChatBox("You are at: "..tostring(x)..", "..tostring(y)..", "..tostring(z)..".", source, 0, 255, 0)
    if not fileExists('arquivo.txt') then -- Aqui verificaremos se o arquivo existe
        archive = fileCreate('arquivo.txt') -- Aqui criamos e atribuimo archive como variavel para indicar o arquivo no primeiro momento
    else
        archive = fileOpen('arquivo.txt') -- se o arquivo ja existir, ou seja, se você ja tiver digitado o /getpos 1 vez, iremos ler o arquivo e atribuir o arquivo para a variavel 'archive'
        fileRead(archive, fileGetSize(archive)) -- quando usamos o fileRead() automaticamente levamos o 'cursor' de digitação pra onde queremos, no caso o segundo parametrô recebe fileGetSize() que vai retornar a quantidade de byte do arquivo, e indicar o 'cursor' pra la
    end

    fileWrite(archive, ""..tostring(x)..", "..tostring(y)..", "..tostring(z)..". rotation: "..tostring(r1)..", "..tostring(r2)..", "..tostring(r3).."\n") -- o /n é para dar 'enter' dentro do arquivo, se não tiver ele vai escrevendo pra frente infinito. Aqui ele escreve as coordenadas e da um enter no arquivo, se preparando para o prox /getpos
    fileClose(archive) -- Aqui o arquivo é salvo e atualizado
end

 

Segue o codigo comentado para estudo e funcionando. Se houver alguma dúvida, não deixe de perguntar.

Caso queira que as linhas virem tabela tbm, para facilitar encontrar os dados faça essa modificação no fileWrite do seu arquivo

 

fileWrite(archive, "{"..tostring(x)..", "..tostring(y)..", "..tostring(z)..". rotation: "..tostring(r1)..", "..tostring(r2)..", "..tostring(r3).."}\n")

Garanto que no futuro quando for manipular, irá ser mais facil em grande quantidades.

Edited by Rougue90
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...