update module utf-8 & bump version 27.01.2023

master
rubin 2 years ago
parent c777b80c98
commit ee97e47872
  1. 884
      auto-ad.lua
  2. 4
      changelog
  3. 2
      version

@ -1,443 +1,443 @@
script_name("auto-ad") script_name("auto-ad")
script_author("Serhiy_Rubin") script_author("Serhiy_Rubin")
script_version("22.01.2023") script_version("27.01.2023")
sampev = require("samp.events") sampev = require("samp.events")
inicfg = require "inicfg" inicfg = require "inicfg"
dlstatus = require("moonloader").download_status dlstatus = require("moonloader").download_status
antiflood = 0 antiflood = 0
ad = { ad = {
status = false, status = false,
text = "1", text = "1",
radio = 0, radio = 0,
radio_save = 0, radio_save = 0,
mode = 1, mode = 1,
one = false, one = false,
af_5sec = 0, af_5sec = 0,
status_2_wait = false status_2_wait = false
} }
function ad.sender() function ad.sender()
if not ad.status then return end if not ad.status then return end
if ad.mode == 1 then if ad.mode == 1 then
--> Переключает на нужное радио если пользователь выбрал такое в меню --> Переключает на нужное радио если пользователь выбрал такое в меню
if ad.radio ~= 0 and ad.radio_save == 0 or (ad.radio_save ~= 0 and ad.radio_save ~= ad.radio) then if ad.radio ~= 0 and ad.radio_save == 0 or (ad.radio_save ~= 0 and ad.radio_save ~= ad.radio) then
if os.clock() * 1000 - antiflood > 750 then if os.clock() * 1000 - antiflood > 750 then
sampSendChat("/radio "..ad.radio) sampSendChat("/radio "..ad.radio)
end end
end end
--> Отправка каждые 5 сек --> Отправка каждые 5 сек
if os.clock() * 1000 - ad.af_5sec > 5000 and not ad.status_2_wait then if os.clock() * 1000 - ad.af_5sec > 5000 and not ad.status_2_wait then
if os.clock() * 1000 - antiflood > 750 then if os.clock() * 1000 - antiflood > 750 then
sampSendChat("/ad "..ad.text) sampSendChat("/ad "..ad.text)
end end
end end
end end
end end
function main() function main()
while not isSampfuncsLoaded() do wait(100) end while not isSampfuncsLoaded() do wait(100) end
repeat wait(0) until isSampAvailable() repeat wait(0) until isSampAvailable()
lua_thread.create(script_update.main) lua_thread.create(script_update.main)
sampRegisterChatCommand("aad", menu.show) sampRegisterChatCommand("aad", menu.show)
while true do while true do
wait(0) wait(0)
menu.handler() menu.handler()
ad.sender() ad.sender()
end end
end end
--> Events --> Events
text_to_int = { text_to_int = {
["SF"] = 1, ["SF"] = 1,
["LS"] = 2, ["LS"] = 2,
["LV"] = 3 ["LV"] = 3
} }
function sampev.onServerMessage(color, message) function sampev.onServerMessage(color, message)
if message:find("Волна переключена на (.+) News") then if message:find("Волна переключена на (.+) News") then
local text = message:match("Волна переключена на (.+) News") local text = message:match("Волна переключена на (.+) News")
ad.radio = text_to_int[text] ad.radio = text_to_int[text]
ad.radio_save = ad.radio ad.radio_save = ad.radio
end end
if message:find("Объявления можно дать через 5 секунд") then if message:find("Объявления можно дать через 5 секунд") then
ad.af_5sec = os.clock() * 1000 ad.af_5sec = os.clock() * 1000
end end
if message:find("Отредактировал сотрудник News (..)") then if message:find("Отредактировал сотрудник News (..)") then
if ad.status then if ad.status then
local text = message:match("Отредактировал сотрудник News (..)") local text = message:match("Отредактировал сотрудник News (..)")
if ad.mode == 2 then if ad.mode == 2 then
lua_thread.create(function(radio) lua_thread.create(function(radio)
wait(30) wait(30)
if ad.radio_save ~= radio then if ad.radio_save ~= radio then
sampSendChat("/radio "..radio) sampSendChat("/radio "..radio)
wait(300) wait(300)
end end
sampSendChat("/ad "..ad.text) sampSendChat("/ad "..ad.text)
end, text_to_int[text]) end, text_to_int[text])
elseif ad.mode == 1 and ad.status_2_wait then elseif ad.mode == 1 and ad.status_2_wait then
if text_to_int[text] == ad.radio or ad.radio == 0 then if text_to_int[text] == ad.radio or ad.radio == 0 then
lua_thread.create(function() lua_thread.create(function()
wait(30) wait(30)
repeat repeat
wait(0) wait(0)
until os.clock() * 1000 - antiflood > 200 until os.clock() * 1000 - antiflood > 200
sampSendChat("/ad "..ad.text) sampSendChat("/ad "..ad.text)
end) end)
end end
end end
end end
end end
if message:find("Ваша очередь объявлений заполнена. Попробуйте позже") or message:find("Очередь объявлений заполнена. Попробуйте позже") then if message:find("Ваша очередь объявлений заполнена. Попробуйте позже") or message:find("Очередь объявлений заполнена. Попробуйте позже") then
if ad.status and ad.mode == 1 then if ad.status and ad.mode == 1 then
ad.status_2_wait = true ad.status_2_wait = true
end end
end end
if message:find("Вы не выбрали через какую радиостанцию подавать объявление") and ad.status then if message:find("Вы не выбрали через какую радиостанцию подавать объявление") and ad.status then
ad.status = false ad.status = false
end end
end end
function sampev.onShowDialog(dialogId, style, title, button1, button2, text) function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
if title:find("Подтверждение") and text:find("Вы собираетесь отправить объявление") then if title:find("Подтверждение") and text:find("Вы собираетесь отправить объявление") then
if ad.status then if ad.status then
sampSendDialogResponse(dialogId,1,0,"") sampSendDialogResponse(dialogId,1,0,"")
if ad.one then if ad.one then
ad.status = false ad.status = false
end end
ad.af_5sec = os.clock() * 1000 ad.af_5sec = os.clock() * 1000
return false return false
end end
end end
end end
function sampev.onSendChat() function sampev.onSendChat()
antiflood = os.clock() * 1000 antiflood = os.clock() * 1000
end end
function sampev.onSendCommand() function sampev.onSendCommand()
antiflood = os.clock() * 1000 antiflood = os.clock() * 1000
end end
--> Menu --> Menu
menu = { menu = {
id = 1921, id = 1921,
id_edit = 1922, id_edit = 1922,
list = {}, list = {},
func = {} func = {}
} }
function menu.handler() function menu.handler()
local result, button, list, input = sampHasDialogRespond(menu.id) local result, button, list, input = sampHasDialogRespond(menu.id)
if result and button == 1 then if result and button == 1 then
if menu.func[list+1] ~= nil then if menu.func[list+1] ~= nil then
menu.func[list+1](button, list, input) menu.func[list+1](button, list, input)
end end
end end
local result, button, list, input = sampHasDialogRespond(menu.id_edit) local result, button, list, input = sampHasDialogRespond(menu.id_edit)
if result then if result then
if button == 1 then if button == 1 then
ad.text = input ad.text = input
menu.show() menu.show()
end end
menu.show() menu.show()
end end
end end
function menu.show() function menu.show()
menu.list = {} menu.list = {}
menu.func = {} menu.func = {}
menu.list[#menu.list+1] = string.format("Скрипт: %s", (ad.status and "{06940f}ON" or "{d10000}OFF")) menu.list[#menu.list+1] = string.format("Скрипт: %s", (ad.status and "{06940f}ON" or "{d10000}OFF"))
menu.func[#menu.func+1] = function(button, list, input) menu.func[#menu.func+1] = function(button, list, input)
ad.status = not ad.status ad.status = not ad.status
ad.status_2_wait = false ad.status_2_wait = false
menu.show() menu.show()
end end
local mode_text = { local mode_text = {
[1] = "Каждые 5 секунд", [1] = "Каждые 5 секунд",
[2] = "Переключать /radio + /ad" [2] = "Переключать /radio + /ad"
} }
menu.list[#menu.list+1] = string.format("Отправка: %s", mode_text[ad.mode]) menu.list[#menu.list+1] = string.format("Отправка: %s", mode_text[ad.mode])
menu.func[#menu.func+1] = function(button, list, input) menu.func[#menu.func+1] = function(button, list, input)
ad.mode = ad.mode + 1 ad.mode = ad.mode + 1
if ad.mode >= 3 then if ad.mode >= 3 then
ad.mode = 1 ad.mode = 1
end end
ad.status_2_wait = false ad.status_2_wait = false
menu.show() menu.show()
end end
menu.list[#menu.list+1] = string.format("Отключить после подачи: %s", (ad.one and "{06940f}ON" or "{d10000}OFF")) menu.list[#menu.list+1] = string.format("Отключить после подачи: %s", (ad.one and "{06940f}ON" or "{d10000}OFF"))
menu.func[#menu.func+1] = function(button, list, input) menu.func[#menu.func+1] = function(button, list, input)
ad.one = not ad.one ad.one = not ad.one
menu.show() menu.show()
end end
local radio_list = { local radio_list = {
[0] = "Не выбрано", [0] = "Не выбрано",
[1] = "SF", [1] = "SF",
[2] = "LS", [2] = "LS",
[3] = "LV" [3] = "LV"
} }
menu.list[#menu.list+1] = string.format("Радиостанция: %s", radio_list[ad.radio]) menu.list[#menu.list+1] = string.format("Радиостанция: %s", radio_list[ad.radio])
menu.func[#menu.func+1] = function(button, list, input) menu.func[#menu.func+1] = function(button, list, input)
ad.radio = ad.radio + 1 ad.radio = ad.radio + 1
if ad.radio >= 4 then if ad.radio >= 4 then
ad.radio = 1 ad.radio = 1
end end
menu.show() menu.show()
end end
menu.list[#menu.list+1] = string.format("Текст: %s", ad.text) menu.list[#menu.list+1] = string.format("Текст: %s", ad.text)
menu.func[#menu.func+1] = function(button, list, input) menu.func[#menu.func+1] = function(button, list, input)
sampShowDialog(menu.id_edit,"Auto-AD","Введите текст объявления без команды /ad","Выбрать","Назад",1) sampShowDialog(menu.id_edit,"Auto-AD","Введите текст объявления без команды /ad","Выбрать","Назад",1)
lua_thread.create(function() lua_thread.create(function()
repeat repeat
wait(0) wait(0)
until sampIsDialogActive() until sampIsDialogActive()
sampSetCurrentDialogEditboxText(ad.text) sampSetCurrentDialogEditboxText(ad.text)
end) end)
return return
end end
local text = "" local text = ""
for i = 1, #menu.list do for i = 1, #menu.list do
text = string.format("%s%s\n", text, menu.list[i]) text = string.format("%s%s\n", text, menu.list[i])
end end
sampShowDialog(menu.id,"Auto-AD",text,"Выбрать","Закрыть",2) sampShowDialog(menu.id,"Auto-AD",text,"Выбрать","Закрыть",2)
end end
-->> UPDATE -->> UPDATE
function openURL(url, fpath) function openURL(url, fpath)
local text = "" local text = ""
local file_download = false local file_download = false
local download_final = false local download_final = false
if doesFileExist(fpath) then if doesFileExist(fpath) then
os.remove(fpath) os.remove(fpath)
end end
downloadUrlToFile(url, fpath, function(id, status, p1, p2) downloadUrlToFile(url, fpath, function(id, status, p1, p2)
if status == dlstatus.STATUS_ENDDOWNLOADDATA then if status == dlstatus.STATUS_ENDDOWNLOADDATA then
file_download = true file_download = true
end end
if status == dlstatus.STATUSEX_ENDDOWNLOAD then if status == dlstatus.STATUSEX_ENDDOWNLOAD then
download_final = true download_final = true
end end
end end
) )
repeat repeat
wait(1000) wait(1000)
until download_final or file_download until download_final or file_download
if file_download then if file_download then
local f = io.open(fpath, "r") local f = io.open(fpath, "r")
if f then if f then
text = f:read("*a") text = f:read("*a")
io.close(f) io.close(f)
end end
os.remove(fpath) os.remove(fpath)
end end
if (text:find("Not found") and not text:find('"Not found"')) or text == "" then if (text:find("Not found") and not text:find('"Not found"')) or text == "" then
text = "" text = ""
addChatMessage("Не удалось скачать обновление по ссылке:") addChatMessage("Не удалось скачать обновление по ссылке:")
addChatMessage(url) addChatMessage(url)
end end
return text return text
end end
function addChatMessage(text) function addChatMessage(text)
local tag = string.format("{667dff}[%s]{FFFFFF} ", thisScript().name) local tag = string.format("{667dff}[%s]{FFFFFF} ", thisScript().name)
sampAddChatMessage(tag..text, 0xFFFFFFFF) sampAddChatMessage(tag..text, 0xFFFFFFFF)
end end
script_update = { script_update = {
version_url = "http://git.deadpoo.net/rubin/Auto-AD/raw/branch/master/version", version_url = "http://git.deadpoo.net/rubin/Auto-AD/raw/branch/master/version",
script_url = "http://git.deadpoo.net/rubin/Auto-AD/raw/branch/master/auto-ad.lua", script_url = "http://git.deadpoo.net/rubin/Auto-AD/raw/branch/master/auto-ad.lua",
changelog_url = "http://git.deadpoo.net/rubin/Auto-AD/raw/branch/master/changelog", changelog_url = "http://git.deadpoo.net/rubin/Auto-AD/raw/branch/master/changelog",
address_ini = "rubin-mods-updates.ini", address_ini = "rubin-mods-updates.ini",
main = function() main = function()
local name = thisScript().name local name = thisScript().name
local ini = inicfg.load({ local ini = inicfg.load({
[name] = { [name] = {
check_update = true, check_update = true,
auto_update = true, auto_update = true,
server_version = "" server_version = ""
} }
}, script_update.address_ini) }, script_update.address_ini)
ini[name].version_url = script_update.version_url ini[name].version_url = script_update.version_url
ini[name].script_url = script_update.script_url ini[name].script_url = script_update.script_url
ini[name].changelog_url = script_update.changelog_url ini[name].changelog_url = script_update.changelog_url
ini[name].version = thisScript().version ini[name].version = thisScript().version
ini[name].script_name = thisScript().name ini[name].script_name = thisScript().name
local command = (thisScript().name:gsub(" ", "").."-update"):lower() local command = (thisScript().name:gsub(" ", "").."-update"):lower()
sampRegisterChatCommand(command, script_update.command) sampRegisterChatCommand(command, script_update.command)
if ini[name].check_update or ini[name].auto_update then if ini[name].check_update or ini[name].auto_update then
local fpath = os.tmpname() local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.version_url, fpath) local result, text = pcall(openURL, script_update.version_url, fpath)
if result then if result then
ini[name].server_version = text ini[name].server_version = text
if text ~= "" and not string.find(text, thisScript().version) then if text ~= "" and not string.find(text, thisScript().version) then
addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) ) addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) )
if ini[name].auto_update then if ini[name].auto_update then
addChatMessage( string.format("Автообновление скрипта включено. Процесс запущен!") ) addChatMessage( string.format("Автообновление скрипта включено. Процесс запущен!") )
script_update.command() script_update.command()
else else
addChatMessage( string.format("Автообновление скрипта выключено. Обновить самому: /%s", command) ) addChatMessage( string.format("Автообновление скрипта выключено. Обновить самому: /%s", command) )
end end
end end
end end
end end
inicfg.save(ini, script_update.address_ini) inicfg.save(ini, script_update.address_ini)
script_update.menu.init() script_update.menu.init()
end, end,
command = function() command = function()
lua_thread.create(function() lua_thread.create(function()
local fpath = os.tmpname() local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.version_url, fpath) local result, text = pcall(openURL, script_update.version_url, fpath)
if result then if result then
if text ~= "" and not string.find(text, thisScript().version) then if text ~= "" and not string.find(text, thisScript().version) then
addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) ) addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) )
local fpath = os.tmpname() local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.script_url, fpath) local result, text = pcall(openURL, script_update.script_url, fpath)
if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then
local file, error = io.open(thisScript().path, "w") local file, error = io.open(thisScript().path, "w")
if file ~= nil then if file ~= nil then
file:write(text) file:write(text)
file:flush() file:flush()
io.close(file) io.close(file)
addChatMessage("Обновление завершено, скрипт перезагружен!") addChatMessage("Обновление завершено, скрипт перезагружен!")
wait(500) wait(500)
thisScript():reload() thisScript():reload()
end end
end end
else else
addChatMessage("У Вас установлена последняя версия!") addChatMessage("У Вас установлена последняя версия!")
end end
end end
end) end)
end, end,
menu = { menu = {
text = {}, text = {},
dialog = {}, dialog = {},
init = function() init = function()
if not sampIsChatCommandDefined("rubin-mods") then if not sampIsChatCommandDefined("rubin-mods") then
sampAddChatMessage("{667dff}[RUBIN MODS]{FFFFFF} Управление обновлениями скриптов: /rubin-mods", 0xFFFFFFFF) sampAddChatMessage("{667dff}[RUBIN MODS]{FFFFFF} Управление обновлениями скриптов: /rubin-mods", 0xFFFFFFFF)
sampRegisterChatCommand("rubin-mods",script_update.menu.show) sampRegisterChatCommand("rubin-mods",script_update.menu.show)
while true do while true do
wait(0) wait(0)
local result, button, list, input = sampHasDialogRespond(2160) local result, button, list, input = sampHasDialogRespond(2160)
if result and button == 1 then if result and button == 1 then
if script_update.menu.text[list+1] ~= nil and script_update.menu.dialog[list+1] ~= nil then if script_update.menu.text[list+1] ~= nil and script_update.menu.dialog[list+1] ~= nil then
script_update.menu.dialog[list+1](script_update.menu.ini[list+1]) script_update.menu.dialog[list+1](script_update.menu.ini[list+1])
end end
end end
local result, button, list, input = sampHasDialogRespond(2162) local result, button, list, input = sampHasDialogRespond(2162)
if result then if result then
if button == 1 then if button == 1 then
if script_update.menu2.text[list+1] ~= nil and script_update.menu2.dialog[list+1] ~= nil then if script_update.menu2.text[list+1] ~= nil and script_update.menu2.dialog[list+1] ~= nil then
script_update.menu2.dialog[list+1]() script_update.menu2.dialog[list+1]()
end end
else else
script_update.menu.show() script_update.menu.show()
end end
end end
local result, button, list, input = sampHasDialogRespond(2161) local result, button, list, input = sampHasDialogRespond(2161)
if result then if result then
script_update.menu2.show(script_update.menu2.data) script_update.menu2.show(script_update.menu2.data)
end end
end end
end end
end, end,
show = function() show = function()
script_update.menu.text = {} script_update.menu.text = {}
script_update.menu.dialog = {} script_update.menu.dialog = {}
script_update.menu.ini = {} script_update.menu.ini = {}
local ini = inicfg.load({}, script_update.address_ini) local ini = inicfg.load({}, script_update.address_ini)
for k,v in pairs(ini) do for k,v in pairs(ini) do
script_update.menu.ini[#script_update.menu.ini+1] = v script_update.menu.ini[#script_update.menu.ini+1] = v
script_update.menu.text[#script_update.menu.text+1] = string.format("%s\t%s%s", k, (v.version == v.server_version and "{59fc30}" or "{ff0000}"),v.version) script_update.menu.text[#script_update.menu.text+1] = string.format("%s\t%s%s", k, (v.version == v.server_version and "{59fc30}" or "{ff0000}"),v.version)
script_update.menu.dialog[#script_update.menu.dialog+1] = function(data) script_update.menu.dialog[#script_update.menu.dialog+1] = function(data)
script_update.menu2.show(data) script_update.menu2.show(data)
end end
end end
local text = "" local text = ""
for i = 1, #script_update.menu.text do for i = 1, #script_update.menu.text do
text = text..script_update.menu.text[i].."\n" text = text..script_update.menu.text[i].."\n"
end end
sampShowDialog(2160,"Обновление скриптов: Rubin Mods","Скрипт\tВерсия\n"..text,"Выбрать","Закрыть",5) sampShowDialog(2160,"Обновление скриптов: Rubin Mods","Скрипт\tВерсия\n"..text,"Выбрать","Закрыть",5)
end end
}, },
menu2 = { menu2 = {
data = {}, data = {},
text = {}, text = {},
dialog = {}, dialog = {},
show = function(data) show = function(data)
script_update.menu2.data = data script_update.menu2.data = data
script_update.menu2.text = {} script_update.menu2.text = {}
script_update.menu2.dialog = {} script_update.menu2.dialog = {}
local ini = inicfg.load({}, script_update.address_ini) local ini = inicfg.load({}, script_update.address_ini)
local k = data.script_name local k = data.script_name
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Автообновление %s", (ini[k].auto_update and "{59fc30}ON" or "{ff0000}OFF")) script_update.menu2.text[#script_update.menu2.text+1] = string.format("Автообновление %s", (ini[k].auto_update and "{59fc30}ON" or "{ff0000}OFF"))
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
ini[k].auto_update = not ini[k].auto_update ini[k].auto_update = not ini[k].auto_update
inicfg.save(ini, script_update.address_ini) inicfg.save(ini, script_update.address_ini)
script_update.menu2.show(data) script_update.menu2.show(data)
end end
if not ini[k].auto_update then if not ini[k].auto_update then
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Проверять обновления %s", (ini[k].check_update and "{59fc30}ON" or "{ff0000}OFF")) script_update.menu2.text[#script_update.menu2.text+1] = string.format("Проверять обновления %s", (ini[k].check_update and "{59fc30}ON" or "{ff0000}OFF"))
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
ini[k].check_update = not ini[k].check_update ini[k].check_update = not ini[k].check_update
inicfg.save(ini, script_update.address_ini) inicfg.save(ini, script_update.address_ini)
script_update.menu2.show(data) script_update.menu2.show(data)
end end
end end
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Последние изменения") script_update.menu2.text[#script_update.menu2.text+1] = string.format("Последние изменения")
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
script_update.changelog(ini[k].changelog_url) script_update.changelog(ini[k].changelog_url)
end end
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Удалить из списка") script_update.menu2.text[#script_update.menu2.text+1] = string.format("Удалить из списка")
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function() script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
ini[k] = nil ini[k] = nil
inicfg.save(ini, script_update.address_ini) inicfg.save(ini, script_update.address_ini)
script_update.menu.show() script_update.menu.show()
end end
local text = "" local text = ""
for i = 1, #script_update.menu2.text do for i = 1, #script_update.menu2.text do
text = text..script_update.menu2.text[i].."\n" text = text..script_update.menu2.text[i].."\n"
end end
sampShowDialog(2162,"Настройки обновления для "..data.script_name,text,"Выбрать","Назад",2) sampShowDialog(2162,"Настройки обновления для "..data.script_name,text,"Выбрать","Назад",2)
end end
}, },
changelog = function(url, data) changelog = function(url, data)
local fpath = os.tmpname() local fpath = os.tmpname()
local result, text = pcall(openURL, url, fpath) local result, text = pcall(openURL, url, fpath)
if result then if result then
sampShowDialog(2161,"Changelog - "..thisScript().name,text,"Выбрать","Назад",4) sampShowDialog(2161,"Changelog - "..thisScript().name,text,"Выбрать","Назад",4)
end end
end end
} }
-->> SCRIPT UTF-8 -->> SCRIPT UTF-8
-->> utf8(table path, incoming variables encoding, outcoming variables encoding) -->> utf8(table path, incoming variables encoding, outcoming variables encoding)
-->> table path example { "sampev", "onShowDialog" } -->> table path example { "sampev", "onShowDialog" }
-->> encoding options nil | AnsiToUtf8 | Utf8ToAnsi -->> encoding options nil | AnsiToUtf8 | Utf8ToAnsi
_utf8 = load([=[return function(utf8_func, in_encoding, out_encoding); if encoding == nil then; encoding = require("encoding"); encoding.default = "CP1251"; u8 = encoding.UTF8; end; if type(utf8_func) ~= "table" then; return false; end; if AnsiToUtf8 == nil or Utf8ToAnsi == nil then; AnsiToUtf8 = function(text); return u8(text); end; Utf8ToAnsi = function(text); return u8:decode(text); end; end; if _UTF8_FUNCTION_SAVE == nil then; _UTF8_FUNCTION_SAVE = {}; end; local change_var = "_G"; for s = 1, #utf8_func do; change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _UTF8_FUNCTION_SAVE[change_var] == nil then _UTF8_FUNCTION = function(...); local pack = table.pack(...); for i = 1, pack.n do; if type(pack[i]) == "string" and in_encoding ~= nil and (in_encoding == "AnsiToUtf8" or in_encoding == "Utf8ToAnsi") then; pack[i] = _G[in_encoding](pack[i]); end; end; local unpacked = {_UTF8_FUNCTION_SAVE[change_var](table.unpack(pack))}; for i = 1, #unpacked do; if type(unpacked[i]) == "string" and out_encoding ~= nil and (out_encoding == "AnsiToUtf8" or out_encoding == "Utf8ToAnsi") then; unpacked[i] = _G[out_encoding](unpacked[i]); end; end; return table.unpack(unpacked); end; local text = string.format("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); load(text)(); _UTF8_FUNCTION = nil; end; return true; end]=]) _utf8 = load([=[return function(utf8_func, in_encoding, out_encoding); if encoding == nil then; encoding = require("encoding"); encoding.default = "CP1251"; u8 = encoding.UTF8; end; if type(utf8_func) ~= "table" then; return false; end; if AnsiToUtf8 == nil or Utf8ToAnsi == nil then; AnsiToUtf8 = function(text); return u8(text); end; Utf8ToAnsi = function(text); return u8:decode(text); end; end; if _UTF8_FUNCTION_SAVE == nil then; _UTF8_FUNCTION_SAVE = {}; end; local change_var = "_G"; for s = 1, #utf8_func do; change_var = string.format('%s["%s"]', change_var, utf8_func[s]); end; if _UTF8_FUNCTION_SAVE[change_var] == nil then; _UTF8_FUNCTION = function(...); local pack = table.pack(...); readTable = function(t, enc); for k, v in next, t do; if type(v) == 'table' then; readTable(v, enc); else; if enc ~= nil and (enc == "AnsiToUtf8" or enc == "Utf8ToAnsi") then; if type(k) == "string" then; k = _G[enc](k); end; if type(v) == "string" then; t[k] = _G[enc](v); end; end; end; end; return t; end; return table.unpack(readTable({_UTF8_FUNCTION_SAVE[change_var](table.unpack(readTable(pack, in_encoding)))}, out_encoding)); end; local text = string.format("_UTF8_FUNCTION_SAVE['%s'] = %s; %s = _UTF8_FUNCTION;", change_var, change_var, change_var); load(text)(); _UTF8_FUNCTION = nil; end; return true; end]=])
function utf8(...) function utf8(...)
pcall(_utf8(), ...) pcall(_utf8(), ...)
end end
utf8({ "sampShowDialog" }, "Utf8ToAnsi") utf8({ "sampShowDialog" }, "Utf8ToAnsi")
utf8({ "sampSendChat" }, "Utf8ToAnsi") utf8({ "sampSendChat" }, "Utf8ToAnsi")
utf8({ "sampAddChatMessage" }, "Utf8ToAnsi") utf8({ "sampAddChatMessage" }, "Utf8ToAnsi")
utf8({ "print" }, "Utf8ToAnsi") utf8({ "print" }, "Utf8ToAnsi")
utf8({ "sampSetCurrentDialogEditboxText" }, "Utf8ToAnsi") utf8({ "sampSetCurrentDialogEditboxText" }, "Utf8ToAnsi")
utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8") utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8")
utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "Utf8ToAnsi") utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "Utf8ToAnsi")
utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "Utf8ToAnsi") utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "Utf8ToAnsi")

@ -1,3 +1,3 @@
آمِّو<EFBFBD> َْ 22.01.2023 Версия от 27.01.2023
ذمًوه ّيِوُْـ Релиз скрипта

@ -1 +1 @@
22.01.2023 27.01.2023
Loading…
Cancel
Save