sampev = require 'samp.events'
local startTimeact = false
local startTime = 0
local startTimeactarmor = false
local startTimearmor = 0
function json(filePath)
local class, filePath = {}, getWorkingDirectory()..'/config/'..(filePath:find('(.+).json') and filePath or filePath..'.json')
if not doesDirectoryExist(getWorkingDirectory()..'/config') then createDirectory(getWorkingDirectory()..'/config') end
function class:save(tbl)
if tbl then
local F = io.open(filePath, 'w')
F:write(encodeJson(tbl) or {})
F:close()
return true, 'ok'
end
return false, 'table = nil'
end
function class:load(defaultTable)
if not doesFileExist(filePath) then class:save(defaultTable or {}) end
local F = io.open(filePath, 'r+')
local TABLE = decodeJson(F:read() or {})
F:close()
for def_k, def_v in next, defaultTable do if TABLE[def_k] == nil then TABLE[def_k] = def_v end end
return TABLE
end
return class
end
boolSetPosition = false
path = "renderText.json"
local settings = json(path):load({
x = 500,
y = 500
})
function sampev.onServerMessage(color, text)
local number = text:match('^%[Ошибка%] %{ffffff%}Для использования этого аксессуара должно пройти ещё (%d+) минут!')
if number then
local time = tonumber(number)
startTime = os.time() + time * 60
startTimeact = true
end
local armor = text:match('Вы автоматически надели бронежилет, поскольку у Вас (.*)')
if armor then
startTimearmor = os.time() + 30
startTimeactarmor = true
end
end
local font = renderCreateFont('Segoe UI', 13, 5)
function main()
while not isSampAvailable() do wait(0) end
sampRegisterChatCommand('setpos', function()
boolSetPosition = true
sampAddChatMessage("Нажмите ЛКМ, чтобы сохранить позицию", -1)
end)
while true do
wait(0)
if boolSetPosition then
local mouseX, mouseY = getCursorPos()
settings.x, settings.y = mouseX, mouseY
if isKeyJustPressed(1) then
json(path):save(settings)
boolSetPosition = false
sampAddChatMessage("Позиция сохранена", -1)
end
end
if startTimeact then
local timeRemaining = startTime - os.time()
if timeRemaining > 0 then
local minutes = math.floor(timeRemaining / 60)
local seconds = timeRemaining % 60
local timeString = string.format("%02d:%02d", minutes, seconds)
renderFontDrawText(font, 'Обрез: '..timeString, settings.x, settings.y, 0xFFe1e1e1, 0x90000000)
else
startTime = 0
renderFontDrawText(font, 'Обрез', settings.x, settings.y, 0xFFe1e1e1, 0x90000000)
startTimeact = false
end
end
if startTimeactarmor then
local timeRemainingarmor = startTimearmor - os.time()
if timeRemainingarmor > 0 then
local minutesarmor = math.floor(timeRemainingarmor / 60)
local secondsarmor = timeRemainingarmor % 60
local timeStringarmor = string.format("%02d:%02d", minutesarmor, secondsarmor)
renderFontDrawText(font, 'Бронежилет: '..timeStringarmor, settings.x, settings.y + 20, 0xFFe1e1e1, 0x90000000)
else
startTimearmor = 0
startTimeactarmor = false
renderFontDrawText(font, 'Бронежилет', settings.x, settings.y + 20, 0xFFe1e1e1, 0x90000000)
end
end
end
end