луа таймеры

maqura

Новичок
Автор темы
8
2
Версия MoonLoader
.026-beta
ку, короч есть луашный тамер на все кд
так вот, попробовал я по аналогии добавить кд на арбалет траксы, и у меня не получилось нихуя
помогите пжпж

[Информация] {ffffff}Вы активировали Арбалет Траксы! Первая пуля ослепит игрока на 20 секунд.

Код:
local wm = require 'lib.windows.message'
local sampev = require('lib.samp.events')
local inicfg = require 'inicfg'
local directIni = 'boosttime.ini'
local ini = inicfg.load(inicfg.load({
    main = {
        x = 50,
        y = 400,
    },
}, directIni))
inicfg.save(ini, directIni)

local timers = {}
local changePos = false
local sX, sY = getScreenResolution()
local font_size = sY / 72
local font = renderCreateFont('Courier New', font_size, 5)

addEventHandler("onWindowMessage", function(msg, wp, lp)
    if changePos then
        if msg == wm.WM_LBUTTONDOWN then
            consumeWindowMessage(true, false)
        end
        if msg == wm.WM_LBUTTONUP then
            changePos = false
            showCursor(false)
            inicfg.save(ini, directIni)
        end
    end
end)

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('timerpos', function()
        changePos = true
        showCursor(true)
    end)
    while true do
        wait(0)
        renderTimers()
    end
end

function renderTimers()
    if changePos then
        local posX, posY = getCursorPos()
        ini.main.x = posX
        ini.main.y = posY
    end
    local yOffsetCurrent = ini.main.y

    for name, timer in pairs(timers) do
        local remainingTime = math.ceil(timer.duration - (os.clock() - timer.startTime))
        if remainingTime > 0 then
            local text = string.format("%s: %s", name, remainingTime < 60 and remainingTime or (string.format("%02d:%02d", math.floor(remainingTime / 60), remainingTime % 60)))
            local height = renderGetFontDrawHeight(font)
            local boxWidth = (renderGetFontDrawTextLength(font, text)) + 10
            renderDrawBox(ini.main.x, yOffsetCurrent - 5, boxWidth, height + 10, 0xaa000000)
            renderFontDrawText(font, text, ini.main.x + 5, yOffsetCurrent, 0xFFFFFFFF)
            yOffsetCurrent = yOffsetCurrent + height + font_size
        else
            timers[name] = nil
        end
    end
end

function sampev.onServerMessage(color, text)
    if text:find('Вы надели бронежилет') then
        timers['Бронежилет'] = {startTime = os.clock(), duration = 60}
    elseif text:find('Вы автоматически надели бронежилет') then
        timers['Бронежилет'] = {startTime = os.clock(), duration = 30}
    elseif text:find('Вы выпили алкоголь') then
        timers['Пиво'] = {startTime = os.clock(), duration = 600}
    elseif text:find('Время действия маски (%d+) минут, после исхода времени ее придётся выбросить') then
        local min = text:match('Время действия маски (%d+) минут, после исхода времени ее придётся выбросить')
        timers['Маска'] = {startTime = os.clock(), duration = tonumber(min) * 60}
    elseif text:find('Вы успешно выкинули маску') then
        timers['Маска'] = {startTime = os.clock(), duration = 0}
    end
end

function sampev.onSendGiveDamage(playerID, damage, weapon, bodyPart)
    if weapon == 88 then
        timers['Меч'] = {startTime = os.clock(), duration = 10}
    end
end


up
 
Последнее редактирование: