script_name = 'Example'
script_prefix = '{068aff}[Example] '
script_author = 'ASKIT'
script_version = '04.10.2021'
script_site = 'vk.com/moonstd'
require "lib.moonloader"
local sampev = require('lib.samp.events')
local imgui = require 'imgui'
local encoding = require 'encoding'
local inicfg = require 'inicfg'
local cfg = inicfg.load({
settings =
{
active = false,
toggle = false,
find_textdraw = 0,
find_string = 255
}
})
encoding.default = 'cp1251'
local u8 = encoding.UTF8
local timer_sec = 0
local timer_min = 0
local timer_hour = 0
---------------------
local font = renderCreateFont("Arial", 8, 5)
local resX, resY = getScreenResolution()
local mainWindowState = imgui.ImBool(false)
local active = imgui.ImBool(cfg.settings.active)
local toggle = imgui.ImBool(cfg.settings.toggle)
local find_textdraw = imgui.ImInt(cfg.settings.find_textdraw)
local find_string = imgui.ImBuffer(256)
---------------------
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
-- Команды
sampRegisterChatCommand("ex", cmd_ex)
-- Функции
finder()
renderTextdraws()
end
function cmd_ex(arg)
if arg == '' then
mainWindowState.v = not mainWindowState.v
imgui.Process = mainWindowState.v
elseif arg == 'reload' then
scriptReload()
end
end
function imgui.OnDrawFrame()
if mainWindowState.v then
imgui.SetNextWindowPos(imgui.ImVec2(resX/2, resY/2), 2, imgui.ImVec2(0.5, 0.5))
imgui.Begin(script_name..' '..script_version..' by '..script_author, mainWindowState, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.AlwaysAutoResize)
if imgui.Checkbox(u8'Активен', active) then
cfg.settings.active = active.v
inicfg.save(cfg)
end
if imgui.Checkbox(u8'Отобразить айди текстдравов', toggle) then
cfg.settings.toggle = toggle.v
inicfg.save(cfg)
end
imgui.Spacing()
imgui.Spacing()
imgui.PushItemWidth(150)
if imgui.InputInt(u8'Поиск текстдрава', find_textdraw, 0, 0) then
cfg.settings.find_textdraw = find_textdraw.v
inicfg.save(cfg)
end
imgui.PushItemWidth(150)
if imgui.InputText(u8'Поиск строки', find_string) then
cfg.settings.find_string = u8:decode(find_string.v)
inicfg.save(cfg)
end
imgui.End()
imgui.Process = mainWindowState.v
end
end
function finder()
lua_thread.create(function()
while true do wait(0)
if active.v and cfg.settings.find_textdraw ~= nil and cfg.settings.find_textdraw ~= 0 then
if sampTextdrawIsExists(cfg.settings.find_textdraw) then
wait(1000)
timer_sec = timer_sec + 1
if timer_sec == 60 then
timer_sec = 0
timer_min = timer_min + 1
if timer_min == 60 then
timer_min = 0
timer_hour = timer_hour + 1
end
end
end
end
end
end)
end
function sampev.onServerMessage(color, text)
if cfg.settings.active and text:find(cfg.settings.find_string) and text ~= nil then
print(timer_hour..':'..timer_min..':'..timer_sec)
timer_sec = 0
timer_min = 0
timer_hour = 0
end
end
function renderTextdraws()
lua_thread.create(function()
while true do wait(0)
if cfg.settings.toggle then
for a = 0, 2304 do
if sampTextdrawIsExists(a) then
x, y = sampTextdrawGetPos(a)
x1, y1 = convertGameScreenCoordsToWindowScreenCoords(x, y)
renderFontDrawText(font, a, x1, y1, 0xFFBEBEBE)
end
end
end
end
end)
end
function saveData()
inicfg.save({
settings =
{
active = data.settings.active,
toggle = data.settings.toggle,
find_textdraw = data.settings.find_textdraw,
find_string = data.settings.find_string
}
}, getWorkingDirectory().."Example.ini")
end
function scriptReload()
thisScript():reload()
end