- Версия MoonLoader
- .026-beta
Суть скрипта следующая.
Редактируется объявление игрока - сохраняется в json
Проблема такая: спустя некоторое время, отредактировав штук 20-30 объявлений начинает вылетать из игры со следующей ошибкой
Редактируется объявление игрока - сохраняется в json
Проблема такая: спустя некоторое время, отредактировав штук 20-30 объявлений начинает вылетать из игры со следующей ошибкой
Lua:
-- ..........МОДУЛИ..........
local imgui = require('mimgui')
local on = require('lib.samp.events')
require('lib.moonloader')
local sampev = require 'samp.events'
-- ..........ПЕРЕМЕННЫЕ..........
local changed = {}
local active_script = false
local automatic = true
-- encoding.default = 'CP1251'
-- u8 = encoding.UTF8
local skipdialog = false
-- ..........JSON.........
local json_file = getWorkingDirectory() .. '\\config\\ad.json'
-- ..........JSON чтение файла..........
function save_json()
local file = io.open(json_file, 'w')
if (file) then
file:write(encodeJson(changed))
file:close()
end
end
-- ..........JSON запись..........
function load_json()
local file = io.open(json_file, 'r')
if (file) then
changed = decodeJson(file:read("*a")) or {}
file:close()
end
end
function main()
while not isSampAvailable() do wait(0) end
sampAddChatMessage("Script edit ad startup!", 0xFFff0000)
end
-- Диалоги
function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
if dialogId == 20046 then
data = text:split("\n")
for i, item in ipairs(data) do
if item:find("Текст отправления")then
tstart = item:sub(item:find(":", 1)+2)
end
if item:find("Отредактированный текст") then
tend = item:sub(item:find(":", 1)+10)
end
end
changed[tstart] = tend
save_json()
lua_thread.create(function()
wait(300)
sampSendDialogResponse(20046, 0, 0, "")
-- save_json()
sampAddChatMessage("Сообщение сохранено!", 0xff00ff)
print(skipdialog)
end)
end
if dialogId == 20047 then
data = text:split("\n")
for i, item in ipairs(data) do
if not (item:find("отправл")==nil) then
tstart = item:sub(item:find(":", 1)+2, item:len())
end
if not (item:find("Отправит")==nil) then
nick = item:sub(item:find(":", 1)+2, item:len())
nick = nick:split(" ")[1]
end
end
load_json()
if changed[tstart] then
print("ЗАМЕНА НАЙДЕНА!!!")
lua_thread.create(answer, changed[tstart])
skipdialog = true
else
if automatic == true then
end
print("ЗАМЕНА НЕ НАЙДЕНА")
end
end
if dialogId == 20044 then
data = text:split("\n")
local index = -1
local found = false
for line in text:gmatch("[^\n]+") do -- Перебираем строки
print("Обрабатываем строку: " .. line)
if line:match("Не проверено") then
print("Найдена строка с 'Не проверено': " .. line)
print("Индекс: " .. index) -- Выводим индекс
lua_thread.create(function ()
wait(1000)
sampSendDialogResponse(20044, 1, index, "")
wait(1000)
end)
break -- Останавливаемся на первой найденной строке
end
index = index + 1 -- Увеличиваем индекс
end
else
end
if dialogId == 20045 and automatic == true then
if skipdialog then
sampSendDialogResponse(20045, 1, 0, "")
skipdialog = false
end
sampSendDialogResponse(20045, 1, 2, "")
end
end
function answer(info)
sampAddChatMessage("{ffffff}Найдено похожее сообщение. Нажмите {00ff00}Y{ffffff} чтобы ответить.", 0xffffff)
sampAddChatMessage(info, 0xff00ff)
lua_thread.create(function()
wait(100)
sampSendDialogResponse(20047, 1, 0, info)
sampSendDialogResponse(20045, 1, 0, "")
end)
end
function string.split(self, sep)
if sep == nil then return self end
if type(self) ~= "string" then self = tostring(self) end
local t={}
for str in string.gmatch(self, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end