Как записывать координаты игрока в файл?

oxxxym1ron

Новичок
Автор темы
10
1
Версия SA-MP
  1. 0.3.7-R3
Мне нужно, чтобы координаты сохранялись в файл построчно, но этого почему-то не происходит, он просто обновляет строку на новую координаты, но не переносит их на новую. В чем может быть проблема?
Вот так это выглядит:
Скриншот 25-01-2025 122604.jpg

Код:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("coord", function() coord = not coord sampAddChatMessage('cooord write' ..(coord and 'On' or 'Off'), -1) end)
    while true do
        wait(0)
        if coord then
            local x, y, z = getCharCoordinates(PLAYER_PED)
            sampAddChatMessage(x .. str .. y .. str .. z, -1)
            local file = io.open(getGameDirectory().."//moonloader//info//coord.txt", "r+")
            file:write(x .. str .. y .. str .. z, "\n")
            file:close()
        end
    end
end
 
Последнее редактирование:
Решение
Мне нужно, чтобы координаты сохранялись в файл построчно, но этого почему-то не происходит, он просто обновляет строку на новую координаты, но не переносит их на новую. В чем может быть проблема?
Вот так это выглядит:
Посмотреть вложение 262407

Код:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("coord", function() coord = not coord sampAddChatMessage('cooord write' ..(coord and 'On' or 'Off'), -1) end)
    while true do
        wait(0)
        if coord then
            local x, y, z = getCharCoordinates(PLAYER_PED)
            sampAddChatMessage(x .. str .. y .. str .. z, -1)
            local file = io.open(getGameDirectory().."//moonloader//info//coord.txt", "r+")
            file:write(x .. str...

VanoKLR

Известный
959
589
Мне нужно, чтобы координаты сохранялись в файл построчно, но этого почему-то не происходит, он просто обновляет строку на новую координаты, но не переносит их на новую. В чем может быть проблема?
Вот так это выглядит:
Посмотреть вложение 262407

Код:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("coord", function() coord = not coord sampAddChatMessage('cooord write' ..(coord and 'On' or 'Off'), -1) end)
    while true do
        wait(0)
        if coord then
            local x, y, z = getCharCoordinates(PLAYER_PED)
            sampAddChatMessage(x .. str .. y .. str .. z, -1)
            local file = io.open(getGameDirectory().."//moonloader//info//coord.txt", "r+")
            file:write(x .. str .. y .. str .. z, "\n")
            file:close()
        end
    end
end
режимы открытия файлов:
"r" – режим чтения файла;
"w" – режим записи в файл с удалением содержимого файла (перезапись);
"a" – режим записи в файл с добавлением к содержимому файла
Замени r+ на a+
 
  • Нравится
Реакции: oxxxym1ron