script_name('GPS')
script_author('хуй знает')
local sampev = require 'lib.samp.events'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local isRecording = false
local outputFile = nil
local mode = "airplane"
function main()
while not isSampAvailable() do wait(0) end
sampAddChatMessage(u8:decode("Маршрутоcоставитель запущен. Нажмите F5 для записи маршрута."), -1)
while true do
wait(0)
if wasKeyPressed(vk.F5) then
toggleRecording()
end
if isRecording then
local x, y, z = getCharCoordinates(PLAYER_PED)
writeToFile(string.format("%s: %.3f, %.3f, %.3f\n", mode, x, y, z))
wait(1000)
end
end
end
function toggleRecording()
isRecording = not isRecording
if isRecording then
local filename = os.date("route_%Y%m%d_%H%M%S.txt")
outputFile = io.open(filename, "w")
if outputFile then
sampAddChatMessage(u8:decode("Запись начата: " .. filename), -1)
else
sampAddChatMessage(u8:decode("Ошибка открытия файла."), -1)
isRecording = false
end
else
if outputFile then
outputFile:close()
outputFile = nil
sampAddChatMessage(u8:decode("Запись остановлена."), -1)
end
end
end
function writeToFile(text)
if outputFile then
outputFile:write(text)
outputFile:flush()
end
end
function isKeyPressed(key)
return isKeyDown(key)
end