script_name('EditBoxSave') script_author("W331s") samp = require 'samp.events' local magicChar = { '\n', '\t', " " } local dialog = { isList = { [0] = false, [1] = false, [2] = true, [3] = false, [4] = true, [5] = true }, id = 0, style = 0, title = 0, text = 0, button = false, input = {}, list = {}, listCount = 0, key = "", enable = false } if not doesDirectoryExist(getGameDirectory()..'\\moonloader\\config') then createDirectory(getGameDirectory()..'\\moonloader\\config') end if not doesFileExist(getGameDirectory()..'\\moonloader\\config\\EditBoxSave.txt') then file = io.open(getGameDirectory()..'\\moonloader\\config\\EditBoxSave.txt', "a") io.close(file) end file = io.open(getGameDirectory()..'\\moonloader\\config\\EditBoxSave.txt', "r") if file ~= nil then dialog.input = { } for line in file:lines() do if #line ~= 0 then Z1, Z2 = string.match(line, "(.*):^:(.*)") dialog.input[Z1] = Z2 end end io.close(file) end function main() if not isSampLoaded() or not isSampfuncsLoaded() then return end while not isSampAvailable() do wait(100) end while true do wait(0) if dialog.enable then dialog.enable = false if dialog.isList[dialog.style] then sampSetCurrentDialogListItem(dialog.list[dialog.key]) end if dialog.style == 1 then sampSetCurrentDialogEditboxText(dialog.input[dialog.text]) end end end end function samp.onShowDialog(dialogId, style, title, button1, button2, text) if style == 1 then for i = 1, #magicChar do text = text:gsub(magicChar[i], '') end end dialog.key = dialogId..style..title dialog.style = style dialog.id = dialogId dialog.title = title dialog.text = text local dlist = -1 for w in string.gmatch(text, '[^\r\n]+') do dlist = dlist + 1 end if dialog.list[dialog.key] ~= nil and dialog.list[dialog.key] > dlist then dialog.list[dialog.key] = dialog.list[dialog.key] - (dialog.list[dialog.key] - dlist) end if button2 ~= nil then dialog.button = true else dialog.button = false end dialog.enable = true end function samp.onSendDialogResponse(dialogId, button, listboxId, input) if dialog.isList[dialog.style] then dialog.list[dialog.key] = listboxId else if dialog.button and dialog.style == 1 and dialog.input[dialog.text] ~= input and button == 1 and (dialog.title == "Ввод параметра" or dialog.title == "Редактирование объявления") then dialog.input[dialog.text] = input local txt = "" local txtq = "" for k,v in pairs(dialog.input) do txt = txt..k..":^:"..v.."\n" txtq = txtq..v.."\n" end os.remove(getGameDirectory()..'\\moonloader\\config\\EditBoxSave.txt') file = io.open(getGameDirectory()..'\\moonloader\\config\\EditBoxSave.txt', "a") file:write(txt) file:flush() io.close(file) end end end