set encoding to utf-8 & added module autoupdate

master
rubin 2 years ago
parent b985f26966
commit c7f76b1dff
  1. 426
      drugs-mats.lua

@ -1,8 +1,9 @@
script_name('Drugs-Mats') script_name('drugs-mats')
script_author("Serhiy_Rubin") script_author("Serhiy_Rubin")
local sampev, vkeys, inicfg = require 'lib.samp.events', require 'lib.vkeys', require 'inicfg' script_version("18.02.2023")
sampev, vkeys, inicfg = require 'lib.samp.events', require 'lib.vkeys', require 'inicfg'
local check_inventory, drugs_timer, not_drugs_timer, renderText, d = 1, 0, false, {}, {} local check_inventory, drugs_timer, not_drugs_timer, renderText, d = 1, 0, false, {}, {}
dlstatus = require("moonloader").download_status
local sleep = 0 local sleep = 0
local check_get_mats = true local check_get_mats = true
local check_boostinfo = 0 local check_boostinfo = 0
@ -11,7 +12,7 @@ local bonus_drugs = 1
function main() function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end while not isSampAvailable() do wait(100) end
lua_thread.create(script_update.main)
local result, PlayerId = sampGetPlayerIdByCharHandle(PLAYER_PED) local result, PlayerId = sampGetPlayerIdByCharHandle(PLAYER_PED)
my_name = sampGetPlayerNickname(PlayerId) my_name = sampGetPlayerNickname(PlayerId)
local ip, port = sampGetCurrentServerAddress( ) local ip, port = sampGetCurrentServerAddress( )
@ -109,80 +110,80 @@ function ShowDialog(int, dtext, dinput, string_or_number, ini1, ini2)
d[1], d[2], d[3], d[4], d[5], d[6] = int, dtext, dinput, string_or_number, ini1, ini2 d[1], d[2], d[3], d[4], d[5], d[6] = int, dtext, dinput, string_or_number, ini1, ini2
if int == 1 then if int == 1 then
dialogLine, dialogTextToList = {}, {} dialogLine, dialogTextToList = {}, {}
dialogLine[#dialogLine + 1] = '{59fc30} > Íàñòðîéêè äëÿ àêêàóíòà\t{FFFFFF}'..my_name dialogLine[#dialogLine + 1] = '{59fc30} > Настройки для аккаунта\t{FFFFFF}'..my_name
dialogLine[#dialogLine + 1] = ' Ñêðèïò\t'..(ini[inikeys].run and "{59fc30}ON" or "{ff0000}OFF") dialogLine[#dialogLine + 1] = ' Скрипт\t'..(ini[inikeys].run and "{59fc30}ON" or "{ff0000}OFF")
dialogLine[#dialogLine + 1] = ' Ïðîâåðêà èíâåíòàðÿ [SRP/ERP]\t'..(ini[inikeys].inventory and "{59fc30}ON" or "{ff0000}OFF") dialogLine[#dialogLine + 1] = ' Проверка инвентаря [SRP/ERP]\t'..(ini[inikeys].inventory and "{59fc30}ON" or "{ff0000}OFF")
dialogLine[#dialogLine + 1] = ' Ïðîâåðêà /boostinfo [SRP]\t'..(ini[inikeys].boostinfo and "{59fc30}ON" or "{ff0000}OFF") dialogLine[#dialogLine + 1] = ' Проверка /boostinfo [SRP]\t'..(ini[inikeys].boostinfo and "{59fc30}ON" or "{ff0000}OFF")
if ini[inikeys].run then if ini[inikeys].run then
dialogLine[#dialogLine + 1] = ' Ñìåíèòü ïîçèöèþ\t' dialogLine[#dialogLine + 1] = ' Сменить позицию\t'
end end
dialogLine[#dialogLine + 1] = ' Ñåðâåðíàÿ êîìàíäà ïðèíÿòü íàðêî\t'..ini[inikeys].server_cmd dialogLine[#dialogLine + 1] = ' Серверная команда принять нарко\t'..ini[inikeys].server_cmd
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå êîìàíäó êîòîðàÿ èñïîëüçóåòñÿ äëÿ ïðèíÿòèÿ íàðêîòèêîâ íà âàøåì ñåðâåðå!" dialogTextToList[#dialogLine] = "{FFFFFF}Введите команду которая используется для принятия наркотиков на вашем сервере!"
dialogLine[#dialogLine + 1] = ' Ñåêóíä äî ñëåäóþùåãî ïðèíÿòèÿ íàðêî\t'..ini[inikeys].seconds dialogLine[#dialogLine + 1] = ' Секунд до следующего принятия нарко\t'..ini[inikeys].seconds
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå ÷åðåç ñêîëüêî ìîæíî ïðèíÿòü íàðêîòèê íà âàøåì ñåðâåðå!" dialogTextToList[#dialogLine] = "{FFFFFF}Введите через сколько можно принять наркотик на вашем сервере!"
dialogLine[#dialogLine + 1] = ' Ìàêñèìàëüíîå HP\t'..ini[inikeys].hp dialogLine[#dialogLine + 1] = ' Максимальное HP\t'..ini[inikeys].hp
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå âàøå ìàêñèìàëüíîå HP!" dialogTextToList[#dialogLine] = "{FFFFFF}Введите ваше максимальное HP!"
dialogLine[#dialogLine + 1] = ' Ìàêñèìóì ãðàìì ìîæíî èñïîëüçîâàòü\t'..ini[inikeys].max_use_gram dialogLine[#dialogLine + 1] = ' Максимум грамм можно использовать\t'..ini[inikeys].max_use_gram
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå ñêîëüêî ìàêñèìóì ãðàìì íàðêîòèêîâ ìîæíî èñïîëüçîâàòü çà ðàç!" dialogTextToList[#dialogLine] = "{FFFFFF}Введите сколько максимум грамм наркотиков можно использовать за раз!"
dialogLine[#dialogLine + 1] = ' HP äàåò 1 ãðàìì íàðêîòèêîâ\t'..ini[inikeys].hp_one_gram dialogLine[#dialogLine + 1] = ' HP дает 1 грамм наркотиков\t'..ini[inikeys].hp_one_gram
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå ñêîëüêî HP äàåò 1 ãðàìì íàðêîòèêîâ!" dialogTextToList[#dialogLine] = "{FFFFFF}Введите сколько HP дает 1 грамм наркотиков!"
dialogLine[#dialogLine + 1] = '{59fc30} > Îáùèå íàñòðîéêè\t' dialogLine[#dialogLine + 1] = '{59fc30} > Общие настройки\t'
dialogLine[#dialogLine + 1] = ' Êíîïêà äëÿ èñïîëüçâàíèÿ íàðêî\t'..ini.global.key:gsub("VK_", '') dialogLine[#dialogLine + 1] = ' Кнопка для использвания нарко\t'..ini.global.key:gsub("VK_", '')
dialogLine[#dialogLine + 1] = ' Ñîêðàùåííàÿ êîìàíäà\t'..ini.global.cmd dialogLine[#dialogLine + 1] = ' Сокращенная команда\t'..ini.global.cmd
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå ñîêðàùåííóþ êîìàíäó äëÿ ïðèíÿòèÿ íàðêîòèêîâ!" dialogTextToList[#dialogLine] = "{FFFFFF}Введите сокращенную команду для принятия наркотиков!"
dialogLine[#dialogLine + 1] = ' Òåêñò êîãäà òàéìåð ñòîèò\t'..ini.lines.one dialogLine[#dialogLine + 1] = ' Текст когда таймер стоит\t'..ini.lines.one
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå òåêñò òàéìåðà êîãäà îí îòêëþ÷åí.\n\tÌîæíî èñïîëüçîâàòü çàìåíû è öâåòà HEX\n\t {036d80}!n{FFFFFF} - ïåðåõîä íà íîâóþ ñòðîêó\n\t {036d80}!a{FFFFFF} - çàìåíèòñÿ íà îñòàòîê íàðêîòèêîâ\n\t {036d80}!m{FFFFFF} - çàìåíèòñÿ íà îñòàòîê ìàòåðèàëîâ" dialogTextToList[#dialogLine] = "{FFFFFF}Введите текст таймера когда он отключен.\n\tМожно использовать замены и цвета HEX\n\t {036d80}!n{FFFFFF} - переход на новую строку\n\t {036d80}!a{FFFFFF} - заменится на остаток наркотиков\n\t {036d80}!m{FFFFFF} - заменится на остаток материалов"
dialogLine[#dialogLine + 1] = ' Òåêñò êîãäà èä¸ò òàéìåð\t'..ini.lines.two dialogLine[#dialogLine + 1] = ' Текст когда идёт таймер\t'..ini.lines.two
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå òåêñò òàéìåðà êîãäà îí ðàáîòàåò.\n\tÌîæíî èñïîëüçîâàòü çàìåíû è öâåòà HEX\n\t {036d80}!n{FFFFFF} - ïåðåõîä íà íîâóþ ñòðîêó\n\t {036d80}!a{FFFFFF} - çàìåíèòñÿ íà îñòàòîê íàðêîòèêîâ\n\t {036d80}!s{FFFFFF} - çàìåíèòñÿ íà îñòàòîê ñåêóíä\n\t {036d80}!m{FFFFFF} - çàìåíèòñÿ íà îñòàòîê ìàòåðèàëîâ" dialogTextToList[#dialogLine] = "{FFFFFF}Введите текст таймера когда он работает.\n\tМожно использовать замены и цвета HEX\n\t {036d80}!n{FFFFFF} - переход на новую строку\n\t {036d80}!a{FFFFFF} - заменится на остаток наркотиков\n\t {036d80}!s{FFFFFF} - заменится на остаток секунд\n\t {036d80}!m{FFFFFF} - заменится на остаток материалов"
dialogLine[#dialogLine + 1] = ' Øðèôò\t'..ini.render.font dialogLine[#dialogLine + 1] = ' Шрифт\t'..ini.render.font
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå íàçâàíèå øðèôòà" dialogTextToList[#dialogLine] = "{FFFFFF}Введите название шрифта"
dialogLine[#dialogLine + 1] = ' Ðàçìåð\t'..ini.render.size dialogLine[#dialogLine + 1] = ' Размер\t'..ini.render.size
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå ðàçìåð øðèôòà" dialogTextToList[#dialogLine] = "{FFFFFF}Введите размер шрифта"
dialogLine[#dialogLine + 1] = ' Ñòèëü\t'..ini.render.flag dialogLine[#dialogLine + 1] = ' Стиль\t'..ini.render.flag
dialogTextToList[#dialogLine] = "{FFFFFF}Óñòàíàâëèâàéòå ñòèëü ïóòåì ñëîæåíèÿ.\n\nÒåêñò áåç îñîáåííîñòåé = 0\nÆèðíûé òåêñò = 1\nÍàêëîííîñòü(Êóðñèâ) = 2\nÎáâîäêà òåêñòà = 4\nÒåíü òåêñòà = 8\nÏîä÷åðêíóòûé òåêñò = 16\nÇà÷åðêíóòûé òåêñò = 32\n\nÑòàíäàðò: 13" dialogTextToList[#dialogLine] = "{FFFFFF}Устанавливайте стиль путем сложения.\n\nТекст без особенностей = 0\nЖирный текст = 1\nНаклонность(Курсив) = 2\nОбводка текста = 4\nТень текста = 8\nПодчеркнутый текст = 16\nЗачеркнутый текст = 32\n\nСтандарт: 13"
dialogLine[#dialogLine + 1] = ' Âûðàâíèâàíèå\t'..( ini.render.align == 1 and "Îò ëåâîãî êðàÿ" or ( ini.render.align == 2 and "Ïî ñåðåäèíå" or ( ini.render.align == 3 and " Îò ïðàâîãî êðàÿ" or '' ) ) ) dialogLine[#dialogLine + 1] = ' Выравнивание\t'..( ini.render.align == 1 and "От левого края" or ( ini.render.align == 2 and "По середине" or ( ini.render.align == 3 and " От правого края" or '' ) ) )
dialogLine[#dialogLine + 1] = ' Îòñòóï íîâîé ñòðîêè\t'..ini.render.height dialogLine[#dialogLine + 1] = ' Отступ новой строки\t'..ini.render.height
dialogTextToList[#dialogLine] = "{FFFFFF}Ââåäèòå ÷èñëî îò 2 äî 10." dialogTextToList[#dialogLine] = "{FFFFFF}Введите число от 2 до 10."
dialogLine[#dialogLine + 1] = '{59fc30}Êîíòàêòû àâòîðà\t' dialogLine[#dialogLine + 1] = '{59fc30}Контакты автора\t'
local text = "" local text = ""
for k,v in pairs(dialogLine) do for k,v in pairs(dialogLine) do
text = text..v.."\n" text = text..v.."\n"
end end
sampShowDialog(0, 'Drugs-Mats: Íàñòðîéêè', text, "Âûáðàòü", "Çàêðûòü", 4) sampShowDialog(0, 'Drugs-Mats: Настройки', text, "Выбрать", "Закрыть", 4)
end end
if int == 2 then if int == 2 then
d[7] = true d[7] = true
sampShowDialog(0, "Drugs-Mats: Èçìåíåíèå íàñòðîåê", dtext, "Âûáðàòü", "Íàçàä", 1) sampShowDialog(0, "Drugs-Mats: Изменение настроек", dtext, "Выбрать", "Назад", 1)
end end
if int == 3 then if int == 3 then
sampShowDialog(0, "Drugs-Mats: Êîíòàêòû àâòîðà", "{FFFFFF}Âûáåðè ÷òî ñêîïèðîâàòü\t\nÍèê íà Samp-Rp\tSerhiy_Rubin\nÑòðàíè÷êà {4c75a3}VK{FFFFFF}\tvk.com/id353828351\nÃðóïïà {4c75a3}VK{FFFFFF} ñ ìîäàìè\tvk.com/club161589495\n{10bef2}Skype{FFFFFF}\tserhiyrubin\n{7289da}Discord{FFFFFF}\tSerhiy_Rubin#3391", "Êîïèðîâàòü", "Íàçàä", 5) sampShowDialog(0, "Drugs-Mats: Контакты автора", "{FFFFFF}Выбери что скопировать\t\nНик на Samp-Rp\tSerhiy_Rubin\nСтраничка {4c75a3}VK{FFFFFF}\tvk.com/id353828351\nГруппа {4c75a3}VK{FFFFFF} с модами\tvk.com/club161589495\n{10bef2}Skype{FFFFFF}\tserhiyrubin\n{7289da}Discord{FFFFFF}\tSerhiy_Rubin#3391", "Копировать", "Назад", 5)
end end
end end
function doDialog() function doDialog()
local caption = sampGetDialogCaption() local caption = sampGetDialogCaption()
if caption == 'Drugs-Mats: Íàñòðîéêè' then if caption == 'Drugs-Mats: Настройки' then
local result, button, list, input = sampHasDialogRespond(0) local result, button, list, input = sampHasDialogRespond(0)
if result and button == 1 then if result and button == 1 then
if dialogLine ~= nil and dialogLine[list + 1] ~= nil then if dialogLine ~= nil and dialogLine[list + 1] ~= nil then
local str = dialogLine[list + 1] local str = dialogLine[list + 1]
if str:find('Ñêðèïò') then if str:find('Скрипт') then
ini[inikeys].run = not ini[inikeys].run ini[inikeys].run = not ini[inikeys].run
inicfg.save(ini) inicfg.save(ini)
ShowDialog(1) ShowDialog(1)
end end
if str:find('Ñìåíèòü ïîçèöèþ') then if str:find('Сменить позицию') then
lua_thread.create(function() lua_thread.create(function()
wait(200) wait(200)
pos = true pos = true
end) end)
end end
if str:find('Ïðîâåðêà èíâåíòàðÿ') then if str:find('Проверка инвентаря') then
ini[inikeys].inventory = not ini[inikeys].inventory ini[inikeys].inventory = not ini[inikeys].inventory
inicfg.save(ini) inicfg.save(ini)
ShowDialog(1) ShowDialog(1)
end end
if str:find('Ñåðâåðíàÿ êîìàíäà ïðèíÿòü íàðêî') then if str:find('Серверная команда принять нарко') then
ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].server_cmd, true, inikeys, 'server_cmd') ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].server_cmd, true, inikeys, 'server_cmd')
end end
if str:find('boostinfo') then if str:find('boostinfo') then
@ -190,48 +191,48 @@ function doDialog()
inicfg.save(ini) inicfg.save(ini)
ShowDialog(1) ShowDialog(1)
end end
if str:find('Ñåêóíä äî ñëåäóþùåãî ïðèíÿòèÿ íàðêî') then if str:find('Секунд до следующего принятия нарко') then
ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].seconds, false, inikeys, 'seconds') ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].seconds, false, inikeys, 'seconds')
end end
if str:find('Ìàêñèìàëüíîå HP') then if str:find('Максимальное HP') then
ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].hp, false, inikeys, 'hp') ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].hp, false, inikeys, 'hp')
end end
if str:find('Ìàêñèìóì ãðàìì ìîæíî èñïîëüçîâàòü') then if str:find('Максимум грамм можно использовать') then
ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].max_use_gram, false, inikeys, 'max_use_gram') ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].max_use_gram, false, inikeys, 'max_use_gram')
end end
if str:find('HP äàåò 1 ãðàìì íàðêîòèêîâ') then if str:find('HP дает 1 грамм наркотиков') then
ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].hp_one_gram, false, inikeys, 'hp_one_gram') ShowDialog(2, dialogTextToList[list + 1], ini[inikeys].hp_one_gram, false, inikeys, 'hp_one_gram')
end end
if str:find('Ñîêðàùåííàÿ êîìàíäà') then if str:find('Сокращенная команда') then
ShowDialog(2, dialogTextToList[list + 1], ini.global.cmd, true, 'global', 'cmd') ShowDialog(2, dialogTextToList[list + 1], ini.global.cmd, true, 'global', 'cmd')
end end
if str:find('Òåêñò êîãäà òàéìåð ñòîèò') then if str:find('Текст когда таймер стоит') then
ShowDialog(2, dialogTextToList[list + 1], ini.lines.one, true, 'lines', 'one') ShowDialog(2, dialogTextToList[list + 1], ini.lines.one, true, 'lines', 'one')
end end
if str:find('Òåêñò êîãäà èä¸ò òàéìåð') then if str:find('Текст когда идёт таймер') then
ShowDialog(2, dialogTextToList[list + 1], ini.lines.two, true, 'lines', 'two') ShowDialog(2, dialogTextToList[list + 1], ini.lines.two, true, 'lines', 'two')
end end
if str:find('Øðèôò') then if str:find('Шрифт') then
ShowDialog(2, dialogTextToList[list + 1], ini.render.font, true, 'render', 'font') ShowDialog(2, dialogTextToList[list + 1], ini.render.font, true, 'render', 'font')
end end
if str:find('Ðàçìåð') then if str:find('Размер') then
ShowDialog(2, dialogTextToList[list + 1], ini.render.size, true, 'render', 'size') ShowDialog(2, dialogTextToList[list + 1], ini.render.size, true, 'render', 'size')
end end
if str:find('Ñòèëü') then if str:find('Стиль') then
ShowDialog(2, dialogTextToList[list + 1], ini.render.flag, true, 'render', 'flag') ShowDialog(2, dialogTextToList[list + 1], ini.render.flag, true, 'render', 'flag')
end end
if str:find('Âûðàâíèâàíèå') then if str:find('Выравнивание') then
ini.render.align = ( ini.render.align == 1 and 2 or ( ini.render.align == 2 and 3 or ( ini.render.align == 3 and 1 or 2 ) ) ) ini.render.align = ( ini.render.align == 1 and 2 or ( ini.render.align == 2 and 3 or ( ini.render.align == 3 and 1 or 2 ) ) )
inicfg.save(ini) inicfg.save(ini)
ShowDialog(1) ShowDialog(1)
end end
if str:find('Îòñòóï íîâîé ñòðîêè') then if str:find('Отступ новой строки') then
ShowDialog(2, dialogTextToList[list + 1], ini.render.height, false, 'render', 'height') ShowDialog(2, dialogTextToList[list + 1], ini.render.height, false, 'render', 'height')
end end
if str:find('Êîíòàêòû àâòîðà') then if str:find('Контакты автора') then
ShowDialog(3) ShowDialog(3)
end end
if str:find('Êíîïêà äëÿ èñïîëüçâàíèÿ íàðêî') then if str:find('Кнопка для использвания нарко') then
lua_thread.create(function() lua_thread.create(function()
wait(150) wait(150)
local keys = "" local keys = ""
@ -239,7 +240,7 @@ function doDialog()
wait(0) wait(0)
for k, v in pairs(vkeys) do for k, v in pairs(vkeys) do
if not sampIsDialogActive() then if not sampIsDialogActive() then
sampShowDialog(0, "Ñìåíà êëàâèøè", "{FFFFFF}Íàæìèòå íà ëþáóþ êëàâèøó\nÎíà áóäåò èñïîëüçîâàòüñÿ äëÿ èñïîëüçîâàíèÿ íàðêîòèêà", "Âûáðàòü", "Çàêðûòü", 0) sampShowDialog(0, "Смена клавиши", "{FFFFFF}Нажмите на любую клавишу\nОна будет использоваться для использования наркотика", "Выбрать", "Закрыть", 0)
end end
if wasKeyPressed(v) and k ~= "VK_ESCAPE" and k ~= "VK_RETURN" and k ~= "VK_SPACE" then if wasKeyPressed(v) and k ~= "VK_ESCAPE" and k ~= "VK_RETURN" and k ~= "VK_SPACE" then
keys = k keys = k
@ -254,7 +255,7 @@ function doDialog()
end end
end end
end end
if caption == "Drugs-Mats: Èçìåíåíèå íàñòðîåê" then if caption == "Drugs-Mats: Изменение настроек" then
if d[7] then if d[7] then
d[7] = false d[7] = false
sampSetCurrentDialogEditboxText(ini[d[5]][d[6]]) sampSetCurrentDialogEditboxText(ini[d[5]][d[6]])
@ -283,7 +284,7 @@ function doDialog()
end end
end end
end end
if caption == "Drugs-Mats: Êîíòàêòû àâòîðà" then if caption == "Drugs-Mats: Контакты автора" then
local result, button, list, input = sampHasDialogRespond(0) local result, button, list, input = sampHasDialogRespond(0)
if result then if result then
if button == 1 then if button == 1 then
@ -301,50 +302,50 @@ function doDialog()
end end
function sampev.onServerMessage(color, message) function sampev.onServerMessage(color, message)
if check_boostinfo == 2 and color == -1 and message:find("Äåéñòâóåò äî") then if check_boostinfo == 2 and color == -1 and message:find("Действует до") then
return false return false
end end
if check_boostinfo == 2 and color == -1 and message:find("Áîíóñû îòêëþ÷åíû") then if check_boostinfo == 2 and color == -1 and message:find("Бонусы отключены") then
check_boostinfo = 0 check_boostinfo = 0
return false return false
end end
if (message == " (( Çäîðîâüå íå ïîïîëíÿåòñÿ ÷àùå, ÷åì ðàç â ìèíóòó ))" or message == ' (( Çäîðîâüå ìîæíî ïîïîëíèòü íå ÷àùå, ÷åì ðàç â ìèíóòó ))') then not_drugs_timer = true end if (message == " (( Здоровье не пополняется чаще, чем раз в минуту ))" or message == ' (( Здоровье можно пополнить не чаще, чем раз в минуту ))') then not_drugs_timer = true end
if string.find(message, my_name) then if string.find(message, my_name) then
if string.find(message, "óïîòðåáèë%(à%) íàðêîòèê") then if string.find(message, "употребил%(а%) наркотик") then
if not not_drugs_timer then drugs_timer = os.time() else not_drugs_timer = false end if not not_drugs_timer then drugs_timer = os.time() else not_drugs_timer = false end
end end
if string.find(message, "îðóæèå èç ìàòåðèàëîâ") then if string.find(message, "оружие из материалов") then
check_get_mats = true check_get_mats = true
end end
end end
if message:find('âûáðîñèë') and (message:find('àðêîòèêè') or message:find('àòåðèàëû')) and string.find(message, my_name) then if message:find('выбросил') and (message:find('аркотики') or message:find('атериалы')) and string.find(message, my_name) then
check_get_mats = true check_get_mats = true
end end
if message:find('Âû âçÿëè íåñêîëüêî êîìïëåêòîâ') then if message:find('Вы взяли несколько комплектов') then
check_get_mats = true check_get_mats = true
end end
if message:find('Âû îãðàáèëè äîì! Íàâîðîâàííûé ìåòàëë ìîæíî ñäàòü îêîëî ïîðòà.') then if message:find('Вы ограбили дом! Наворованный металл можно сдать около порта.') then
check_get_mats = true check_get_mats = true
end end
if message:find('Ó âàñ (%d+)/500 ìàòåðèàëîâ ñ ñîáîé') then if message:find('У вас (%d+)/500 материалов с собой') then
ini[inikeys].mats = message:match('Ó âàñ (%d+)/500 ìàòåðèàëîâ ñ ñîáîé') ini[inikeys].mats = message:match('У вас (%d+)/500 материалов с собой')
inicfg.save(ini) inicfg.save(ini)
end end
if string.find(message, " %(%( Îñòàòîê: (%d+) ãðàìì %)%)") then if string.find(message, " %(%( Остаток: (%d+) грамм %)%)") then
if not not_drugs_timer then drugs_timer = os.time() else not_drugs_timer = false end if not not_drugs_timer then drugs_timer = os.time() else not_drugs_timer = false end
ini[inikeys].drugs = string.match(message, " %(%( Îñòàòîê: (%d+) ãðàìì %)%)") ini[inikeys].drugs = string.match(message, " %(%( Остаток: (%d+) грамм %)%)")
inicfg.save(ini) inicfg.save(ini)
end end
if string.find(message, '%(%( Îñòàòîê: (%d+) ìàòåðèàëîâ %)%)') then if string.find(message, '%(%( Остаток: (%d+) материалов %)%)') then
ini[inikeys].mats = message:match('%(%( Îñòàòîê: (%d+) ìàòåðèàëîâ %)%)') ini[inikeys].mats = message:match('%(%( Остаток: (%d+) материалов %)%)')
inicfg.save(ini) inicfg.save(ini)
end end
if message:find('Âû êóïèëè %d+ ãðàìì íàðêîòèêîâ çà %d+ âèðò %(Ó âàñ åñòü (%d+) ãðàìì%)') then if message:find('Вы купили %d+ грамм наркотиков за %d+ вирт %(У вас есть (%d+) грамм%)') then
ini[inikeys].drugs = message:match('Âû êóïèëè %d+ ãðàìì íàðêîòèêîâ çà %d+ âèðò %(Ó âàñ åñòü (%d+) ãðàìì%)') ini[inikeys].drugs = message:match('Вы купили %d+ грамм наркотиков за %d+ вирт %(У вас есть (%d+) грамм%)')
inicfg.save(ini) inicfg.save(ini)
end end
if message:find('Âû êóïèëè (%d+) ãðàìì íàðêîòèêîâ çà %d+ âèðò ó .+') then if message:find('Вы купили (%d+) грамм наркотиков за %d+ вирт у .+') then
local s1 = message:match('Âû êóïèëè (%d+) ãðàìì íàðêîòèêîâ çà %d+ âèðò ó .+') local s1 = message:match('Вы купили (%d+) грамм наркотиков за %d+ вирт у .+')
ini[inikeys].drugs = tonumber(s1) + ini[inikeys].drugs ini[inikeys].drugs = tonumber(s1) + ini[inikeys].drugs
inicfg.save(ini) inicfg.save(ini)
end end
@ -374,16 +375,16 @@ function sampev.onSendCommand(cmd)
end end
function sampev.onShowDialog(dialogId, style, title, button1, button2, text) function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
if title:find('Èíôîðìàöèÿ') or title:find('Êàðìàíû') then if title:find('Информация') or title:find('Карманы') then
local nark, mats = false, false local nark, mats = false, false
local arr = split(text, "\n") local arr = split(text, "\n")
for i = 1, #arr do for i = 1, #arr do
if arr[i]:find('Íàðêîòèêè\t(%d+)') then if arr[i]:find('Наркотики\t(%d+)') then
ini[inikeys].drugs = arr[i]:match('Íàðêîòèêè\t(%d+)') ini[inikeys].drugs = arr[i]:match('Наркотики\t(%d+)')
nark = true nark = true
end end
if arr[i]:find('Ìàòåðèàëû\t(%d+)') then if arr[i]:find('Материалы\t(%d+)') then
ini[inikeys].mats = arr[i]:match('Ìàòåðèàëû\t(%d+)') ini[inikeys].mats = arr[i]:match('Материалы\t(%d+)')
mats = true mats = true
end end
end end
@ -398,11 +399,11 @@ function sampev.onShowDialog(dialogId, style, title, button1, button2, text)
return false return false
end end
end end
if dialogId == 22 and title == "Áîíóñû" then if dialogId == 22 and title == "Бонусы" then
local arr = split(text, "\n") local arr = split(text, "\n")
for i = 1, #arr do for i = 1, #arr do
if arr[i]:find('Òàéìåð íà Íàðêî (.+)') then if arr[i]:find('Таймер на Нарко (.+)') then
bonus_drugs = tonumber(arr[i]:match('Òàéìåð íà Íàðêî (.+)')) bonus_drugs = tonumber(arr[i]:match('Таймер на Нарко (.+)'))
break break
end end
end end
@ -415,7 +416,6 @@ end
function GetMats() function GetMats()
if not check_get_mats then return end if not check_get_mats then return end
check_get_mats = false check_get_mats = false
repeat repeat
wait(0) wait(0)
@ -455,3 +455,251 @@ function split(str, delim, plain)
until not pos until not pos
return tokens return tokens
end end
function addChatMessage(text)
local tag = string.format("{667dff}[%s]{FFFFFF} ", thisScript().name)
sampAddChatMessage(tag..text, 0xFFFFFFFF)
end
-->> UPDATE MODULE
function openURL(url, fpath, message_off)
local text = ""
local file_download = false
local download_final = false
if doesFileExist(fpath) then
os.remove(fpath)
end
downloadUrlToFile(url, fpath, function(id, status, p1, p2)
if status == dlstatus.STATUS_ENDDOWNLOADDATA then
file_download = true
end
if status == dlstatus.STATUSEX_ENDDOWNLOAD then
download_final = true
end
end
)
repeat
wait(1000)
until download_final or file_download
if file_download then
local f = io.open(fpath, "r")
if f then
text = f:read("*a")
io.close(f)
end
os.remove(fpath)
end
if (text:find("Not found") and not text:find('"Not found"')) or text == "" then
text = ""
if not message_off then
addChatMessage("Не удалось скачать обновление по ссылке:")
addChatMessage(url)
end
end
return text
end
script_update = {
version_url = "http://git.deadpoo.net/rubin/drugs-mats/raw/branch/master/version",
script_url = "http://git.deadpoo.net/rubin/drugs-mats/raw/branch/master/drugs-mats.lua",
changelog_url = "http://git.deadpoo.net/rubin/drugs-mats/raw/branch/master/changelog",
address_ini = string.format("rubin-mods-updates\\%s.ini", thisScript().name),
main = function()
if not doesDirectoryExist("moonloader\\config\\rubin-mods-updates") then
createDirectory("moonloader\\config\\rubin-mods-updates")
end
local ini = inicfg.load({
settings = {
check_update = true,
auto_update = true,
server_version = ""
}
}, script_update.address_ini)
ini.settings.version_url = script_update.version_url
ini.settings.script_url = script_update.script_url
ini.settings.changelog_url = script_update.changelog_url
ini.settings.version = thisScript().version
ini.settings.script_name = thisScript().name
local command = (thisScript().name:gsub(" ", "").."-update"):lower()
sampRegisterChatCommand(command, script_update.command)
if ini.settings.check_update or ini.settings.auto_update then
local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.version_url, fpath)
if result then
ini.settings.server_version = text
if text ~= "" and text ~= thisScript().version then
addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) )
if ini.settings.auto_update then
addChatMessage( string.format("Автообновление скрипта включено. Процесс запущен!") )
script_update.command()
else
addChatMessage( string.format("Автообновление скрипта выключено. Обновить самому: /%s", command) )
end
end
end
end
inicfg.save(ini, script_update.address_ini)
script_update.menu.init()
end,
command = function()
lua_thread.create(function()
local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.version_url, fpath)
if result then
if text ~= "" and text ~= thisScript().version then
addChatMessage( string.format("Вышла новая версия '%s'. Текущая: '%s'", text, thisScript().version) )
local fpath = os.tmpname()
local result, text = pcall(openURL, script_update.script_url, fpath)
if result and text ~= "" and text:find(thisScript().name:gsub("%-", "%%-")) then
local file, error = io.open(thisScript().path, "w")
if file ~= nil then
file:write(text)
file:flush()
io.close(file)
addChatMessage("Обновление завершено, скрипт перезагружен!")
wait(500)
thisScript():reload()
end
end
else
addChatMessage("У Вас установлена последняя версия!")
end
end
end)
end,
menu = {
dialog = {},
ini = {},
init = function()
if not sampIsChatCommandDefined("rubin-mods") then
sampAddChatMessage("{667dff}[RUBIN MODS]{FFFFFF} Управление обновлениями скриптов: /rubin-mods", 0xFFFFFFFF)
sampRegisterChatCommand("rubin-mods",script_update.menu.show)
while true do
wait(0)
local result, button, list, input = sampHasDialogRespond(2160)
if result and button == 1 then
if script_update.menu.ini[list+1] ~= nil and script_update.menu.dialog[list+1] ~= nil then
script_update.menu.dialog[list+1](script_update.menu.ini[list+1])
end
end
local result, button, list, input = sampHasDialogRespond(2162)
if result then
if button == 1 then
if script_update.menu2.text[list+1] ~= nil and script_update.menu2.dialog[list+1] ~= nil then
script_update.menu2.dialog[list+1]()
end
else
script_update.menu.show()
end
end
local result, button, list, input = sampHasDialogRespond(2161)
if result then
script_update.menu2.show(script_update.menu2.data)
end
end
end
end,
show = function()
script_update.menu.dialog = {}
script_update.menu.ini = {}
local text = ""
if doesDirectoryExist("moonloader\\config\\rubin-mods-updates") then
local FileHandle, FileName = findFirstFile("moonloader\\config\\rubin-mods-updates\\*")
while FileName ~= nil do
if FileName ~= nil and FileName ~= ".." and FileName ~= "." and FileName:find("%.ini") then
local address = string.format("moonloader\\config\\rubin-mods-updates\\%s", FileName)
if doesFileExist(address) then
local ini = inicfg.load({}, address)
script_update.menu.ini[#script_update.menu.ini+1] = address
text = string.format("%s%s\n", text, string.format("%s\t%s%s", ini.settings.script_name, (ini.settings.version == ini.settings.server_version and "{59fc30}" or "{ff0000}"),ini.settings.version))
script_update.menu.dialog[#script_update.menu.dialog+1] = function(data)
script_update.menu2.show(data)
end
end
end
FileName = findNextFile(FileHandle)
end
findClose(FileHandle)
else
text = "Не найдена директория:\t\n moonloader\\config\\rubin-mods-updates\t"
end
sampShowDialog(2160,"Обновление скриптов: Rubin Mods","Скрипт\tВерсия\n"..text,"Выбрать","Закрыть",5)
end
},
menu2 = {
data = {},
text = {},
dialog = {},
show = function(data)
script_update.menu2.data = data
script_update.menu2.text = {}
script_update.menu2.dialog = {}
if doesFileExist(data) then
local ini = inicfg.load({}, data)
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Автообновление %s", (ini.settings.auto_update and "{59fc30}ON" or "{ff0000}OFF"))
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
ini.settings.auto_update = not ini.settings.auto_update
inicfg.save(ini, data)
script_update.menu2.show(data)
end
if not ini.settings.auto_update then
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Проверять обновления %s", (ini.settings.check_update and "{59fc30}ON" or "{ff0000}OFF"))
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
ini.settings.check_update = not ini.settings.check_update
inicfg.save(ini, data)
script_update.menu2.show(data)
end
end
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Последние изменения")
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
script_update.changelog(ini.settings.changelog_url, ini.settings.script_name)
end
script_update.menu2.text[#script_update.menu2.text+1] = string.format("Удалить из списка")
script_update.menu2.dialog[#script_update.menu2.dialog+1] = function()
os.remove(data)
script_update.menu.show()
end
local text = ""
for i = 1, #script_update.menu2.text do
text = text..script_update.menu2.text[i].."\n"
end
sampShowDialog(2162,"Настройки обновления для "..ini.settings.script_name,text,"Выбрать","Назад",2)
end
end
},
changelog = function(url, name)
local fpath = os.tmpname()
local result, text = pcall(openURL, url, fpath)
if result then
sampShowDialog(2161,"Changelog - "..name,text,"Выбрать","Назад",4)
end
end
}
-->> SCRIPT UTF-8
-->> utf8(table path, incoming variables encoding, outcoming variables encoding)
-->> table path example { "sampev", "onShowDialog" }
-->> 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(...); 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(...)
pcall(_utf8(), ...)
end
utf8({ "sampShowDialog" }, "Utf8ToAnsi")
utf8({ "sampSendChat" }, "Utf8ToAnsi")
utf8({ "sampAddChatMessage" }, "Utf8ToAnsi")
utf8({ "print" }, "Utf8ToAnsi")
utf8({ "renderGetFontDrawTextLength" }, "Utf8ToAnsi")
utf8({ "renderFontDrawText" }, "Utf8ToAnsi")
utf8({ "sampSetCurrentDialogEditboxText" }, "Utf8ToAnsi")
utf8({ "sampHasDialogRespond" }, nil, "AnsiToUtf8")
utf8({ "sampev", "onServerMessage" }, "AnsiToUtf8", "Utf8ToAnsi")
utf8({ "sampev", "onShowDialog" }, "AnsiToUtf8", "Utf8ToAnsi")
utf8({ "sampev", "onSendCommand" }, "AnsiToUtf8", "Utf8ToAnsi")
Loading…
Cancel
Save