script_name("Fast-Form")
script_author("Morse")
require "lib.moonloader"
require "lib.sampfuncs"
dlstatus = require('moonloader').download_status
local keys = require "vkeys"
local imgui = require "imgui"
local encoding = require "encoding"
local inicfg = require "inicfg"
local mainIni = inicfg.load(nil, directIni)
encoding.default = "CP1251"
u8 = encoding.UTF8
bFa, fa = pcall(require, "fAwesome5")
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
local fs80 = nil
local directIni = 'moonloader//config//Fast-Form.ini'
local mainIni = inicfg.load({
config =
{
autoclean = false,
zaderzkaform = "",
fastopen = "[]"
}
}, 'Fast-Form.ini')
if not doesFileExist('moonloader/config/Fast-Form.ini') then inicfg.save(mainIni, 'Fast-Form.ini') end
mForm = imgui.ImBool(false)
fOpen = imgui.ImBool(false)
clear = imgui.ImBool(mainIni.config.autoclean)
local alltext = imgui.ImBuffer(256)
local zaderzka = imgui.ImBuffer(tostring(mainIni.config.zaderzkaform), 256)
local rkeys = require 'rkeys'
imgui.HotKey = require('imgui_addons').HotKey
local tLastKeys = {}
local ActiveOpenMenu = {
v = decodeJson(mainIni.config.fastopen)
}
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
if checkData() then log('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Файлы для работы скрипта {32CD32}загружены!') else while true do wait(0) end end
if loadConfig() then log('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Настройки скрипта {32CD32}загружены!') end
if loadCmd() then log('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Команды скрипта {32CD32}загружены!') end
sampAddChatMessage("[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Запущен! Активация {32CD32}/sform", -1)
OpenMenu = rkeys.registerHotKey(ActiveOpenMenu.v, 1, false,
function()
if not sampIsChatInputActive() and not sampIsDialogActive() and not mForm.v then
mForm.v = false
fOpen.v = true
end
end)
while true do
wait(0)
imgui.Process = mForm.v or fOpen.v
end
end
function imgui.ToggleButton(str_id, bool)
local rBool = false
if LastActiveTime == nil then
LastActiveTime = {}
end
if LastActive == nil then
LastActive = {}
end
local function ImSaturate(f)
return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
end
local p = imgui.GetCursorScreenPos()
local draw_list = imgui.GetWindowDrawList()
local height = imgui.GetTextLineHeightWithSpacing()
local width = height * 1.55
local radius = height * 0.50
local ANIM_SPEED = 0.15
local butPos = imgui.GetCursorPos()
if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
bool.v = not bool.v
rBool = true
LastActiveTime[tostring(str_id)] = os.clock()
LastActive[tostring(str_id)] = true
end
imgui.SetCursorPos(imgui.ImVec2(butPos.x + width + 8, butPos.y + 2.5))
imgui.Text( str_id:gsub('##.+', '') )
local t = bool.v and 1.0 or 0.0
if LastActive[tostring(str_id)] then
local time = os.clock() - LastActiveTime[tostring(str_id)]
if time <= ANIM_SPEED then
local t_anim = ImSaturate(time / ANIM_SPEED)
t = bool.v and t_anim or 1.0 - t_anim
else
LastActive[tostring(str_id)] = false
end
end
local col_bg
if bool.v then
col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
else
col_bg = imgui.ImColor(100, 100, 100, 180):GetU32()
end
draw_list:AddRectFilled(imgui.ImVec2(p.x, p.y + (height / 6)), imgui.ImVec2(p.x + width - 1.0, p.y + (height - (height / 6))), col_bg, 5.0)
draw_list:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 0.75, imgui.GetColorU32(bool.v and imgui.ImVec4(0.675, 1.000, 0.000, 1.000) or imgui.ImColor(150, 150, 150, 255):GetVec4()))
return rBool
end
function imgui.Hint(text, delay, action)
if imgui.IsItemHovered() then
if go_hint == nil then go_hint = os.clock() + (delay and delay or 0.0) end
local alpha = (os.clock() - go_hint) * 5 -- скорость появления
if os.clock() >= go_hint then
imgui.PushStyleVar(imgui.StyleVar.WindowPadding, imgui.ImVec2(10, 10))
imgui.PushStyleVar(imgui.StyleVar.Alpha, (alpha <= 1.0 and alpha or 1.0))
imgui.PushStyleColor(imgui.Col.PopupBg, imgui.ImVec4(0.11, 0.11, 0.11, 1.00))
imgui.BeginTooltip()
imgui.PushTextWrapPos(450)
imgui.TextColored(imgui.GetStyle().Colors[imgui.Col.ButtonHovered], fa.ICON_FA_INFO_CIRCLE..u8' Подсказка:')
imgui.TextUnformatted(text)
if action ~= nil then
imgui.TextColored(imgui.GetStyle().Colors[imgui.Col.TextDisabled], '\n'..fa.ICON_FA_SHARE..' '..action)
end
if not imgui.IsItemVisible() and imgui.GetStyle().Alpha == 1.0 then go_hint = nil end
imgui.PopTextWrapPos()
imgui.EndTooltip()
imgui.PopStyleColor()
imgui.PopStyleVar(2)
end
end
end
function imgui.InvisButton(text, size)
imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0, 0, 0, 0))
imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0, 0, 0, 0))
imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0, 0, 0, 0))
local button = imgui.Button(text, size)
imgui.PopStyleColor(3)
return button
end
function checkData()
local bRes_Font = doesFileExist(getWorkingDirectory()..'\\Fast-Form\\fa-solid-900.ttf')
local bFa = doesFileExist(getWorkingDirectory()..'\\lib\\fAwesome5.lua')
if not bRes_Font or not bFa then
sampAddChatMessage('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Отсутвуют некоторые файлы. {8A2BE2}Начало загрузки...', -1)
createDirectory(getWorkingDirectory()..'\\Fast-Form')
lua_thread.create(function()
downloadFile('fa-solid-900', getWorkingDirectory()..'\\Fast-Form\\fa-solid-900.ttf', 'https://gitlab.com/uploads/-/system/personal_snippet/2014196/da3408954c85f58e0bc50cb069bfa600/fa-solid-900.ttf')
downloadFile('fAwesome5', getWorkingDirectory()..'\\lib\\fAwesome5.lua', 'https://gitlab.com/uploads/-/system/personal_snippet/2014196/7ca8bba8732c24ed34ac27821d1c46dd/fAwesome5.lua')
wait(50) sampAddChatMessage('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Все нужные для работы файлы загружены. {32CD32}Перезагружаюсь...', -1)
wait(500) thisScript():reload()
end)
return false
end
return true
end
function downloadFile(name, path, link)
if not doesFileExist(path) then
downloadUrlToFile(link, path, function(id, status, p1, p2)
if status == dlstatus.STATUS_ENDDOWNLOADDATA then
log('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Файл «{8A2BE2}'..name..'{E6E6FA}»{32CD32}загружен!')
end
end)
while not doesFileExist(path) do wait(0) end
end
end
function loadConfig()
if not doesFileExist('moonloader/config/Fast-Form.ini') then
inicfg.save(mainIni, 'Fast-Form.ini')
log('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Файл с настройками {FF0000}отсутсвует! {32CD32}Создан новый!')
end
return true
end
function loadCmd()
sampRegisterChatCommand("sform", function() mForm.v = not mForm.v end)
return true
end
function log(text)
sampfuncsLog(text)
end
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
if fa_font == nil then
if not doesFileExist('moonloader\\Fast-Form\\fa-solid-900.ttf') then
sampAddChatMessage('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Отсутсвует файл шрифта {8A2BE2}fa-solid-900.ttf {E6E6FA}в папке moonloader/Fast-Form', -1)
sampAddChatMessage('[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Запуск без него не возможен. Переустановите скрипт или обратитесь к разработчику. Скрипт отключён..', -1)
thisScript():unload()
return
end
local font_config = imgui.ImFontConfig()
font_config.MergeMode = true
fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/Fast-Form/fa-solid-900.ttf', 13.0, font_config, fa_glyph_ranges)
end
if fs80 == nil then fs80 = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 80.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) end
end
function imgui.OnDrawFrame()
if mForm.v then
local sw, sh = getScreenResolution()
imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(315, 130), imgui.Cond.FirstUseEver)
imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
imgui.Begin(fa.ICON_FA_CHECK_SQUARE .. " Fast-Form", mForm, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoScrollbar)
imgui.Text(u8"Очистка после выдачи")
imgui.SameLine(200)
if imgui.ToggleButton("##tb", clear) then
mainIni.config.autoclean = clear.v
inicfg.save(mainIni, 'Fast-Form.ini')
end
imgui.SameLine(270)
imgui.TextDisabled(fa.ICON_FA_INFO_CIRCLE)
imgui.Hint(u8"После нажатия кнопки 'Выдать' все поле ввода очистится")
imgui.Text(u8"Задержка между строками")
imgui.SameLine(200)
imgui.PushItemWidth(65)
imgui.InputText("##inp1", zaderzka)
imgui.SameLine(270)
imgui.TextDisabled(fa.ICON_FA_INFO_CIRCLE)
imgui.Hint(u8"Задержка между каждой строкой. Эта кнопка " .. fa.ICON_FA_SAVE .. u8" для сохранения задержки")
imgui.SameLine()
if imgui.InvisButton(fa.ICON_FA_SAVE .. '##ib', imgui.ImVec2(20, 20)) then
mainIni.config.zaderzkaform = zaderzka.v
inicfg.save(mainIni, 'Fast-Form.ini')
sampAddChatMessage("[{FF4500}Fast-Form{FFFFFF}] {E6E6FA}Задержка сохранена и будет использована в последующих действиях!", -1)
end
imgui.Text(u8"Клавиша открытия меню")
imgui.SameLine(200)
if imgui.HotKey("##hk", ActiveOpenMenu, tLastKeys, 65) then
rkeys.changeHotKey(OpenMenu, ActiveOpenMenu.v)
sampAddChatMessage("[{FF4500}Fast-Form{FFFFFF}] Клавиша изменена! Старое значение: {8A2BE2}" .. table.concat(rkeys.getKeysName(tLastKeys.v), " + ") .. "{ffffff} | Новое: {8A2BE2}" .. table.concat(rkeys.getKeysName(ActiveOpenMenu.v), " + "), -1)
mainIni.config.fastopen = encodeJson(ActiveOpenMenu.v)
inicfg.save(mainIni, 'Fast-Form.ini')
end
imgui.SameLine(270)
imgui.TextDisabled(fa.ICON_FA_INFO_CIRCLE)
imgui.Hint(u8"Клавиша на которую будет открыватся меню выдачи наказаний")
if imgui.Button(fa.ICON_FA_FOLDER_OPEN .. u8" Открыть меню выдачи", imgui.ImVec2(300, 25)) then
mForm.v = false
fOpen.v = true
end
imgui.End()
end
if fOpen.v then
local sw, sh = getScreenResolution()
imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(470, 370), imgui.Cond.FirstUseEver)
imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
imgui.Begin(fa.ICON_FA_PAPER_PLANE .. u8" Выдача наказаний", fOpen, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoScrollbar)
imgui.InputTextMultiline('##inp', alltext, imgui.ImVec2(453, 305))
if imgui.Button(fa.ICON_FA_GIFT .. u8" Выдать", imgui.ImVec2(453, 27)) then
lua_thread.create(function()
for line in alltext.v:gmatch('[^\r\n]+') do
sampSendChat(u8:decode(line))
wait(tonumber(zaderzka.v))
if clear.v then
alltext.v = ""
end
end
end)
end
imgui.End()
end
end
function theme()
imgui.SwitchContext()
local style = imgui.GetStyle()
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
local ImVec2 = imgui.ImVec2
style.WindowPadding = imgui.ImVec2(8, 8)
style.WindowRounding = 6
style.ChildWindowRounding = 5
style.FramePadding = imgui.ImVec2(5, 3)
style.FrameRounding = 3.0
style.ItemSpacing = imgui.ImVec2(5, 4)
style.ItemInnerSpacing = imgui.ImVec2(4, 4)
style.IndentSpacing = 21
style.ScrollbarSize = 10.0
style.ScrollbarRounding = 13
style.GrabMinSize = 8
style.GrabRounding = 1
style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
style.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)
colors[clr.Text] = ImVec4(0.95, 0.96, 0.98, 1.00);
colors[clr.TextDisabled] = ImVec4(0.29, 0.29, 0.29, 1.00);
colors[clr.WindowBg] = ImVec4(0.14, 0.14, 0.14, 1.00);
colors[clr.ChildWindowBg] = ImVec4(0.12, 0.12, 0.12, 1.00);
colors[clr.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94);
colors[clr.Border] = ImVec4(0.14, 0.14, 0.14, 1.00);
colors[clr.BorderShadow] = ImVec4(1.00, 1.00, 1.00, 0.10);
colors[clr.FrameBg] = ImVec4(0.22, 0.22, 0.22, 1.00);
colors[clr.FrameBgHovered] = ImVec4(0.18, 0.18, 0.18, 1.00);
colors[clr.FrameBgActive] = ImVec4(0.09, 0.12, 0.14, 1.00);
colors[clr.TitleBg] = ImVec4(0.14, 0.14, 0.14, 0.81);
colors[clr.TitleBgActive] = ImVec4(0.14, 0.14, 0.14, 1.00);
colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51);
colors[clr.MenuBarBg] = ImVec4(0.20, 0.20, 0.20, 1.00);
colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.39);
colors[clr.ScrollbarGrab] = ImVec4(0.36, 0.36, 0.36, 1.00);
colors[clr.ScrollbarGrabHovered] = ImVec4(0.18, 0.22, 0.25, 1.00);
colors[clr.ScrollbarGrabActive] = ImVec4(0.24, 0.24, 0.24, 1.00);
colors[clr.ComboBg] = ImVec4(0.24, 0.24, 0.24, 1.00);
colors[clr.CheckMark] = ImVec4(1.00, 0.28, 0.28, 1.00);
colors[clr.SliderGrab] = ImVec4(1.00, 0.28, 0.28, 1.00);
colors[clr.SliderGrabActive] = ImVec4(1.00, 0.28, 0.28, 1.00);
colors[clr.Button] = ImVec4(1.00, 0.28, 0.28, 1.00);
colors[clr.ButtonHovered] = ImVec4(1.00, 0.39, 0.39, 1.00);
colors[clr.ButtonActive] = ImVec4(1.00, 0.21, 0.21, 1.00);
colors[clr.Header] = ImVec4(1.00, 0.28, 0.28, 1.00);
colors[clr.HeaderHovered] = ImVec4(1.00, 0.39, 0.39, 1.00);
colors[clr.HeaderActive] = ImVec4(1.00, 0.21, 0.21, 1.00);
colors[clr.ResizeGrip] = ImVec4(1.00, 0.28, 0.28, 1.00);
colors[clr.ResizeGripHovered] = ImVec4(1.00, 0.39, 0.39, 1.00);
colors[clr.ResizeGripActive] = ImVec4(1.00, 0.19, 0.19, 1.00);
colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16);
colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39);
colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00);
colors[clr.PlotLines] = ImVec4(0.61, 0.61, 0.61, 1.00);
colors[clr.PlotLinesHovered] = ImVec4(1.00, 0.43, 0.35, 1.00);
colors[clr.PlotHistogram] = ImVec4(1.00, 0.21, 0.21, 1.00);
colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.18, 0.18, 1.00);
colors[clr.TextSelectedBg] = ImVec4(1.00, 0.32, 0.32, 1.00);
colors[clr.ModalWindowDarkening] = ImVec4(0.26, 0.26, 0.26, 0.60);
end
theme()