SlonPvpru

[DRP] Sorter 20.06.2020

Apr 23rd, 2020
753
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 40.89 KB | None | 0 0
  1. -- https://www.blast.hk/threads/51242/
  2.  
  3. script_version("20.06.2020")
  4. item_id = 1243
  5. delivery_id = 1249
  6. accept_id = 1246
  7. lic_day = 0
  8. places = {}
  9. local sampev = require 'lib.samp.events'
  10. local glyph_ranges = nil
  11. local effil = require 'effil'
  12. local imgui = require 'imgui'
  13. local font_flag = require('moonloader').font_flag
  14. local encoding = require 'encoding'
  15. local ip = 'ws://45.140.167.12:27800'
  16. local websocket = ''
  17. local client =''
  18. if not doesFileExist('moonloader\\lib\\websocket.lua') or
  19.      not doesFileExist('moonloader\\lib\\copas.lua') then
  20.          print('Отсутствуют сетевые библиотеки')
  21.      else
  22.           websocket = require 'websocket'
  23.           client = websocket.client.copas({timeout = 2})
  24. end
  25. local res, https = pcall(require, 'ssl.https')
  26. assert(res, 'Library ssl.https not found')
  27. local inicfg = require 'inicfg'
  28. imgui.BufferingBar = require('imgui_addons').BufferingBar
  29. encoding.default = 'CP1251'
  30. u8 = encoding.UTF8
  31. local bNotf, notf = pcall(import, "imgui_notf.lua")
  32. if not doesFileExist('moonloader\\config\\gsorter\\gsorter.ini') then
  33.     if not doesDirectoryExist('moonloader\\config\\gsorter') then  createDirectory('moonloader\\config\\gsorter') end
  34.     local  ini =
  35.         {
  36.                 filters =
  37.                 {
  38.                         check_gun    = true,
  39.                         check_food   = true,
  40.                         check_furniture = true,
  41.                         check_furnitur = true,
  42.                         check_clothes = true,
  43.                         check_general = true,
  44.                         check_alcohol = true,
  45.                         check_transport = true,
  46.                         check_accessory = true,
  47.                         check_radio = true,
  48.                         check_cosmetics = true,
  49.                         check_pyrotechnics = true,
  50.                         check_auto = true,
  51.                         check_sport = true,
  52.                         int_price_dost = 0,1,
  53.                         check_parachute = true,
  54.                         check_type_towar = true,
  55.                         check_type_product = true,
  56.                         check_type_auto = true,
  57.                         check_office = true,
  58.                         text_maxprice = 6,
  59.                         int_sklad = 0,
  60.                         check_fruit = true,
  61.                         int_sklad2 = 0,
  62.                         int_quantity = 100,
  63.                         text_maxdilprice = 0.1,
  64.                         item_id = 1141,
  65.                         accept_id = 1144,
  66.                         delivery_id = 1147,
  67.                         go_delivery = true,
  68.                         check_sf = true,
  69.                         check_ls = true,
  70.                         check_lv = true,
  71.                         hud_stats = true,
  72.                         accept_sleep = 350
  73.                 }
  74.         }
  75.     inicfg.save(ini, 'gsorter\\gsorter')
  76. end
  77. local event_dialog = 0
  78. local directIni = 'moonloader\\config\\gsorter\\gsorter.ini'
  79. local mainIni = inicfg.load(nil, directIni)
  80. local fullscreen = imgui.ImBool(false)
  81. local main_window_state = imgui.ImBool(false)
  82. local hud_stats = imgui.ImBool(mainIni.filters.hud_stats==true)
  83. local hud = imgui.ImBool(false)
  84. local window_render_list  = imgui.ImBool(false)
  85. local accept_sleep = imgui.ImInt((mainIni.filters.accept_sleep and mainIni.filters.accept_sleep or 350))
  86. local check_gun = imgui.ImBool(mainIni.filters.check_gun)
  87. local check_food = imgui.ImBool(mainIni.filters.check_food)
  88. local check_cm = imgui.ImBool(mainIni.filters.check_cm==true)
  89. local check_sf = imgui.ImBool(mainIni.filters.check_sf==true)
  90. local check_ls = imgui.ImBool(mainIni.filters.check_ls==true)
  91. local check_lv = imgui.ImBool(mainIni.filters.check_lv==true)
  92. local check_furniture = imgui.ImBool(mainIni.filters.check_furniture)
  93. local check_clothes = imgui.ImBool(mainIni.filters.check_clothes)
  94. local check_general = imgui.ImBool(mainIni.filters.check_general)
  95. local go_delivery = imgui.ImBool((mainIni.filters.go_delivery and mainIni.filters.go_delivery or true))
  96. local check_fruit = imgui.ImBool(mainIni.filters.check_fruit)
  97. local check_transport = imgui.ImBool(mainIni.filters.check_transport)
  98. local check_accessory = imgui.ImBool(mainIni.filters.check_accessory)
  99. local check_radio = imgui.ImBool(mainIni.filters.check_radio)
  100. local check_cosmetics = imgui.ImBool(mainIni.filters.check_cosmetics)
  101. local check_pyrotechnics = imgui.ImBool(mainIni.filters.check_pyrotechnics)
  102. local check_auto = imgui.ImBool(mainIni.filters.check_auto)
  103. local check_sport = imgui.ImBool(mainIni.filters.check_sport)
  104. local int_price_dost = imgui.ImFloat(mainIni.filters.int_price_dost)
  105. local check_alcohol = imgui.ImBool(mainIni.filters.check_alcohol)
  106. local check_parachute = imgui.ImBool(mainIni.filters.check_parachute)
  107. local check_type_towar = imgui.ImBool(mainIni.filters.check_type_towar)
  108. local check_type_product = imgui.ImBool(mainIni.filters.check_type_product)
  109. local check_type_auto = imgui.ImBool(mainIni.filters.check_type_auto)
  110. local check_office = imgui.ImBool(mainIni.filters.check_office)
  111. local text_maxprice = imgui.ImFloat(mainIni.filters.text_maxprice)
  112. local int_sklad = imgui.ImInt(mainIni.filters.int_sklad)
  113. local int_sklad2 = imgui.ImInt(mainIni.filters.int_sklad2)
  114. local int_quantity = imgui.ImInt(mainIni.filters.int_quantity)
  115. local text_maxdilprice = imgui.ImFloat(mainIni.filters.text_maxdilprice)
  116. local text_chat = imgui.ImBuffer((mainIni.filters.text_chat and mainIni.filters.text_chat or 'Котик'),256)
  117. local delivery_window_state = imgui.ImBool(false)
  118. local password = imgui.ImBuffer((mainIni.filters.password and mainIni.filters.password or '' ),256)
  119. local auth_window = imgui.ImBool(false)
  120. local key_order = {}
  121. local accept_product = {}
  122. local check_stats = true
  123. local delivery_stats = {}
  124. local bot = false
  125. local day_money = 0
  126. local day_box = 0
  127. local day_reise = 0
  128. local stats_autoupdate = false
  129. local postrequest = {}
  130. local soft = 'sorter'
  131. local sorter_status = true
  132. require "lib.moonloader"
  133. require "lib.sampfuncs"
  134. function main()
  135. while not isSampAvailable() do wait(100) end
  136. autoupdate("http://www.zamcontroller.ru/sorter/update.json", '['..string.upper(thisScript().name)..']: ', "http://zamcontroller.ru/PremiumSorter.luac")
  137. local sendstat = {}
  138. local _, my_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
  139. local user = sampGetPlayerNickname(my_id)
  140. sampRegisterChatCommand('sorter', cmd_status)
  141. if not doesFileExist('moonloader\\MONSTER.luac') then
  142.     sampRegisterChatCommand('z', cmd_z)
  143.     sampRegisterChatCommand('zchat', cmd_zchat)
  144. end
  145. local connected, err = client:connect(ip, '')
  146. if err then print(err) end
  147. if connected then
  148.     if not connected then
  149.         sampAddChatMessage('{B40431}[SORTER]{ffffff} - Ошибка соединения с сервером.',-1)
  150.     else
  151.         sampAddChatMessage('{5858FA}[SORTER]{ffffff} - Вы успешно подключились к серверу скрипта, ожидание авторизации...',-1)
  152.         sampSendChat('/mn')
  153.     end
  154. end
  155. lua_thread.create(function()
  156.     while true do wait(0)
  157.         local message, opcode = client:receive()
  158.         if message then
  159.             local result = decodeJson(message)
  160.             if result and result.days and tonumber(result.days)>0 then
  161.                 _G.item_id  = result.item_id
  162.                 _G.accept_id = result.accept_id
  163.                 _G.delivery_id = result.delivery_id
  164.                 _G.lic_day = result.days
  165.                 _G.places = result.places
  166.                 sampAddChatMessage('{B40431}[SORTER]{ffffff} - Успешная авторизация, данные о лицензии подтверждены!', -1)
  167.                 sampAddChatMessage('{B40431}[SORTER]{ffffff} - Осталось {B40431}'..lic_day..'{ffffff} дней лицензии',-1)
  168.                 sampAddChatMessage('{B40431}[SORTER]{ffffff} - Анонимный чат: {B40431}/z <text>',-1)
  169.                 auth_window.v = false
  170.                 bot = true
  171.             elseif result['action']=='chat_message' and mainIni.filters.check_chat   then
  172.                 if not doesFileExist('moonloader\\MONSTER.luac') then
  173.                     sampAddChatMessage(u8:decode(tostring(result['text'])), -1)
  174.                 end
  175.             elseif result['action']=='newstat' then
  176.                 day_money = result['money']
  177.                 day_reise = result['reise']
  178.                 day_box     = result['box']
  179.             elseif result['action']=='error' then
  180.                 sampAddChatMessage('{ff0000}[ERROR] - {ffffff}'..u8:decode(result['text']), -1)
  181.             elseif result['action']=='ping' then
  182.                 client:send(encodeJson({action='pong'}))
  183.             end
  184.     end
  185.  end
  186. end)
  187. lua_thread.create(function()
  188. while true do wait(0)
  189.     if not window_render_list.v and update_product then
  190.         update_product = nil
  191.         sampSendDialogResponse(event_dialog,0,-1)
  192.     elseif (not window_render_list.v and not delivery_window_state.v and isKeyJustPressed(VK_INSERT)) then
  193.         sampSendChat('/company')
  194.     elseif (not window_render_list.v and not delivery_window_state.v and isKeyJustPressed(VK_DELETE)) then
  195.         sampSendChat('/delivery')
  196.     end
  197. end
  198. end)
  199.   while true do
  200.     wait(0)
  201.             imgui.Process=true
  202.         if window_render_list.v and update_product==1  then
  203.                     sampSendDialogResponse(local_id,0)
  204.                     wait(5000)
  205.         end
  206.     end
  207. end
  208. function apply_custom_style()
  209.     imgui.SwitchContext()
  210.     local style = imgui.GetStyle()
  211.     local colors = style.Colors
  212.     local clr = imgui.Col
  213.     local ImVec4 = imgui.ImVec4
  214.     style.WindowRounding = 8
  215.     style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
  216.     style.ChildWindowRounding = 2.0
  217.     style.FrameRounding = 3
  218.     style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
  219.     style.ScrollbarSize = 13.0
  220.     style.ScrollbarRounding = 0
  221.     style.GrabMinSize = 8.0
  222.     style.GrabRounding = 1.0
  223.     style.WindowPadding = imgui.ImVec2(4.0, 4.0)
  224.     style.FramePadding = imgui.ImVec2(3.5, 3.5)
  225.     style.ButtonTextAlign = imgui.ImVec2(0.0, 0.5)
  226.     colors[clr.WindowBg]              = ImVec4(0.14, 0.12, 0.16, 0.79);
  227.     colors[clr.ChildWindowBg]         = ImVec4(0.30, 0.20, 0.39, 0.00);
  228.     colors[clr.PopupBg]               = ImVec4(0.05, 0.05, 0.10, 0.90);
  229.     colors[clr.Border]                = ImVec4(0.89, 0.85, 0.92, 1.00);
  230.     colors[clr.BorderShadow]          = ImVec4(0.00, 0.00, 0.00, 0.00);
  231.     colors[clr.FrameBg]               = ImVec4(0.30, 0.20, 0.39, 0.40);
  232.     colors[clr.FrameBgHovered]        = ImVec4(0.41, 0.19, 0.63, 0.28);
  233.     colors[clr.FrameBgActive]         = ImVec4(0.41, 0.19, 0.63, 0.50);
  234.     colors[clr.TitleBg]               = ImVec4(0.41, 0.19, 0.63, 0.45);
  235.     colors[clr.TitleBgCollapsed]      = ImVec4(0.41, 0.19, 0.63, 0.35);
  236.     colors[clr.TitleBgActive]         = ImVec4(0.41, 0.19, 0.63, 0.78);
  237.     colors[clr.MenuBarBg]             = ImVec4(0.30, 0.20, 0.39, 0.37);
  238.     colors[clr.ScrollbarBg]           = ImVec4(0.30, 0.20, 0.39, 1.00);
  239.     colors[clr.ScrollbarGrab]         = ImVec4(0.41, 0.19, 0.63, 0.31);
  240.     colors[clr.ScrollbarGrabHovered]  = ImVec4(0.41, 0.19, 0.63, 0.48);
  241.     colors[clr.ScrollbarGrabActive]   = ImVec4(0.41, 0.19, 0.63, 1.00);
  242.     colors[clr.ComboBg]               = ImVec4(0.30, 0.20, 0.39, 1.00);
  243.     colors[clr.CheckMark]             = ImVec4(0.56, 0.61, 1.00, 1.00);
  244.     colors[clr.SliderGrab]            = ImVec4(0.41, 0.19, 0.63, 0.24);
  245.     colors[clr.SliderGrabActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
  246.     colors[clr.Button]                = ImVec4(0.41, 0.19, 0.63, 0.44);
  247.     colors[clr.ButtonHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
  248.     colors[clr.ButtonActive]          = ImVec4(0.64, 0.33, 0.94, 1.00);
  249.     colors[clr.Header]                = ImVec4(0.41, 0.19, 0.63, 0.76);
  250.     colors[clr.HeaderHovered]         = ImVec4(0.41, 0.19, 0.63, 0.86);
  251.     colors[clr.HeaderActive]          = ImVec4(0.41, 0.19, 0.63, 1.00);
  252.     colors[clr.ResizeGrip]            = ImVec4(0.41, 0.19, 0.63, 0.20);
  253.     colors[clr.ResizeGripHovered]     = ImVec4(0.41, 0.19, 0.63, 0.78);
  254.     colors[clr.ResizeGripActive]      = ImVec4(0.41, 0.19, 0.63, 1.00);
  255.     colors[clr.CloseButton]           = ImVec4(1.00, 1.00, 1.00, 0.75);
  256.     colors[clr.CloseButtonHovered]    = ImVec4(0.88, 0.74, 1.00, 0.59);
  257.     colors[clr.CloseButtonActive]     = ImVec4(0.88, 0.85, 0.92, 1.00);
  258.     colors[clr.PlotLines]             = ImVec4(0.89, 0.85, 0.92, 1.00);
  259.     colors[clr.PlotLinesHovered]      = ImVec4(0.41, 0.19, 0.63, 0.10);
  260.     colors[clr.PlotHistogram]         = ImVec4(0.89, 0.85, 0.92, 0.63);
  261.     colors[clr.PlotHistogramHovered]  = ImVec4(0.41, 0.19, 0.63, 1.00);
  262.     colors[clr.TextSelectedBg]        = ImVec4(0.41, 0.19, 0.63, 0.43);
  263.     colors[clr.ModalWindowDarkening]  = ImVec4(0.20, 0.20, 0.20, 0.35);
  264. end
  265. apply_custom_style()
  266. function cmd_status()
  267.     sorter_status = not sorter_status
  268.     if not sorter_status then if bNotf then notf.addNotification('Сортировщик нокаутирован', 3, 3) end else
  269.         if bNotf then notf.addNotification('Сортировщик включен', 3, 2) end end
  270. end
  271. function onWindowMessage(msg, wparam, lparam)
  272.     if(msg == 0x100) then
  273.         if(wparam == VK_ESCAPE and window_render_list.v) then
  274.             window_render_list.v = false
  275.             consumeWindowMessage()
  276.         end
  277.     end
  278. end
  279. function sampev.onServerMessage(color,text)
  280.     if (text == '• {AC0000}[Ошибка] {ffffff}На Ваших складах недостаточно товара для этого заказа' ) and window_render_list.v then
  281.         update_product = 1
  282.         sampSendChat('/company')
  283.         if bNotf then   notf.addNotification('На Ваших складах недостаточно товара для этого заказа', 3, 3) end
  284.     elseif text:find('Посигнальте, чтобы') then  lua_thread.create(function() setVirtualKeyDown(VK_H, true); wait(400); setVirtualKeyDown(VK_H, false) end)
  285.     elseif text=='• {AC0000}[Ошибка] {ffffff}Нет свободных заказов на доставку товара' and window_render_list.v then
  286.         if bNotf then   notf.addNotification('Нет свободных заказов на доставку товара', 3, 3) end
  287.         update_product = 1
  288.         sampSendChat('/company')
  289.     elseif text:find('Вы доставили заказ%. Доход: %$(%d+) %(%$(%d+) доставлено в кассу компании%)') then
  290.         lua_thread.create(function()
  291.         local money,box = text:match('Вы доставили заказ%. Доход: %$(%d+) %(%$(%d+) доставлено в кассу компании%)')
  292.         print(money,box)
  293.         _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  294.         user =  sampGetPlayerNickname(my_id)
  295.         local server,port =  sampGetCurrentServerAddress()
  296.         client:send(encodeJson({
  297.                                                         soft=soft,
  298.                                                         action = 'sorter_addstat',
  299.                                                         password = password.v,
  300.                                                         user = tostring(user),
  301.                                                         server = tostring(server),
  302.                                                         money = tonumber(money),
  303.                                                         box = tonumber(box)
  304.                                                     }))
  305.     end)
  306.     elseif text:find('Добро пожаловать на Diamond Role Play!') then
  307.         _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  308.      user =  sampGetPlayerNickname(my_id)
  309.         sampSendChat('/mn')
  310.     elseif (text:find('Вы доставили заказ. Доход:')) then check_stats = true ;sampSendChat('/mn');sampAddChatMessage(text, -1)
  311.     elseif text == 'Прекратите флуд!' and window_render_list.v then
  312.         sampSendChat('/company')
  313.     end
  314. end
  315. function sampev.onSendDialogResponse(id,button,line,text)
  316.     if (id==delivery_id) then
  317.         delivery_window_state.v=false
  318.         return {id,button,(key_order[line+1] and key_order[line+1] or (id==1108 and 50 or 30)   ),text}
  319.     end
  320. end
  321. function sampev.onShowDialog(id,style,title,button1,button2,text)
  322.     print('[ID]: '..title..': '..id)
  323.     event_dialog = id
  324.     if id == accept_id and update_product == 2 and window_render_list.v then  -- если надо свой заказ принять
  325.         lua_thread.create(function()
  326.             local keyy = 0
  327.             for line in text:gmatch("[^\n]+") do
  328.                 if line:find(accept_product[3]) then
  329.                     wait(accept_sleep.v-sampGetPlayerPing(my_id))
  330.                     sampSendDialogResponse(id,1,keyy)
  331.                 end
  332.                  key = key+1
  333.             end
  334.         end)
  335.                      return false
  336.     --Чек статы
  337.     elseif (title:find('Меню игрока') and check_stats) then
  338.         if not bot then
  339.             auth_window.v = true
  340.         end
  341.         sampSendDialogResponse(id,1,3)
  342.         return false
  343.     elseif (title:find('Работник стоянки') and check_stats) then
  344.         for line in text:gmatch("[^\n]+") do
  345.         if (line:find('Заработано очков опыта: %{.*%}(%d+)')) then
  346.             delivery_stats['score'] = tonumber(line:match('Заработано очков опыта: %{.*%}(%d+)'))
  347.         elseif (line:find('Совершено рейсов: %{.*%}(%d+)')) then
  348.             delivery_stats['reise'] = tonumber(line:match('Совершено рейсов: %{.*%}(%d+)'))
  349.         elseif (line:find('Заработано денег: %{.*%}%$(%d+)')) then
  350.             delivery_stats['money'] = tonumber(line:match('Заработано денег: %{.*%}%$(%d+)'))
  351.         end
  352.         end
  353.         check_stats = false
  354.         sampSendDialogResponse(id,1,1)
  355.  
  356.         return false
  357.     elseif (title:find('Трудовая книжка') and check_stats) then
  358.             sampSendDialogResponse(id,1,1)
  359.             return false
  360.     elseif (title:find('Выберите стоянку') and update_product==2 and go_delivery.v) then
  361.         lua_thread.create(function()
  362.             wait(accept_sleep.v-sampGetPlayerPing(my_id))
  363.             accept_product[6] = nil
  364.             sampSendDialogResponse(id,1,0)
  365.         end)
  366.             return false
  367.     elseif (title:find('Свободные заказы') and update_product==2) then
  368.         lua_thread.create(function()
  369.             wait(accept_sleep.v-sampGetPlayerPing(my_id))
  370.                 sampSendDialogResponse(id,1,65535,65535)
  371.                 if not accept_product[6] then
  372.                     update_product=1
  373.                     if bNotf then   notf.addNotification("Заказ принят на стоянку", 3, 2) end
  374.                     if check_cm.v then
  375.                         sampSendChat('/cm Заказчик: '.. accept_product[1]..', товар: '..accept_product[2])
  376.                         wait(400)
  377.                         sampSendChat('/cm Количество: '..accept_product[3]..'ед. Доставка: ' ..accept_product[5]..'$/ед.')
  378.                     end
  379.                 end
  380.                 sampSendChat('/company')
  381.             end)
  382.                     return false
  383.                 elseif (id==delivery_id and sorter_status and bot) then
  384.                         delivery_window_state.v = true
  385.                         order=''
  386.                         local_id = id
  387.                         key_order={}
  388.                         count=-1
  389.                         for line in text:gmatch("[^\n]+") do
  390.                             count=count+1
  391.                             if (line:find("%{FFDF80%}(%d+)%.%{FFFFFF%}%s+([А-Яа-я ]+)%s+([A-Za-zА-Я а-я%-]+)%s+(%d+)ед%.%s+%$([%.0-9]+)%s+%/%s+ед%s+%[([A-Z-a-zА-Яа-я0-9№/ ]+)%s-%s+([A-Z-a-zА-Яа-я0-9№/ ]+)%]")) then
  392.                                  key,service,product,quantity,price,where,destination = line:   match("%{FFDF80%}(%d+)%.%{FFFFFF%}%s+([A-Za-zА-Я а-я%-]+)%s+([A-Za-zА-Я а-я%-]+)%s+(%d+)ед%.%s+%$([%.0-9]+)%s+%/%s+ед%s+%[([A-Z-a-zА-Яа-я0-9№/ ]+)%s-%s+([A-Z-a-zА-Яа-я0-9№/ ]+)%]")
  393.                                     if ((product == (check_gun.v==true and 'Оружие'or'') or product == (check_food.v==true and 'Продукты питания'or'') or product == (check_furniture.v==true and 'Мебель'or'') or product == (check_sport.v==true and 'Спорт-Товары'or'') or product == (check_clothes.v==true and 'Одежда'or'') or product == (check_pyrotechnics.v==true and 'Пиротехника'or'') or product == (check_radio.v==true and 'Радиоигрушки' or '') or product == (check_parachute.v==true and 'Парашютное снаряжение'or'') or product == (check_parachute.v==true and 'Парашютное снаряжение'or'') or product == (check_accessory.v==true and 'Аксессуары'or'') or product == (check_alcohol.v==true and 'Алкоголь'or'') or product == (check_cosmetics.v==true and 'Косметические средства'or'') or product == (check_fruit.v==true and 'Фрукты'or'') or product == (check_office.v==true and 'Канцелярские товары'or'') or product == (check_general.v==true and 'Товары общего пользования'or'') or product == (check_auto.v==true and 'Автозапчасти'or'') or product == (check_transport.v==true and 'Транспорт'or'')) and (tonumber(price)>=int_price_dost.v)and (int_quantity.v<=tonumber(quantity)) and (int_sklad.v==0 or where:find('№'..int_sklad.v..'( |-)') or where:find('№'..int_sklad2.v..'( |-)') or destination:find('№'..int_sklad2.v) or destination:find('№'..int_sklad.v)) and (int_quantity.v<=tonumber(quantity))  and (service==(check_type_product.v==true and 'Перевозка продуктов'or'') or service==(check_type_towar.v==true and 'Перевозка товаров'or'') or service==(check_type_auto.v==true and 'Перевозка транспорта'or''))) then
  394.                                         order = (order==''and '' or order..'\n') ..service..'\t'..product..'['..quantity..']\t'..price..'\t'..where..' - '..destination
  395.                                         key_order[#key_order+1] = count-1
  396.                                 end
  397.                             end
  398.                         end
  399.                         order = 'Услуга\tПродукт[Кол-во] \tЦена\tОткуда-куда\n'..order..'\n{00ff00}Следующая страница'
  400.                         return {id, style, title, button1, button2, order}
  401.     elseif (title:find('Выберите склад') and update_product==2  and bot) then
  402.         sampSendDialogResponse(id,-1,0)
  403.         return false
  404.     elseif title:find('Доставка товаров') and style==1 then
  405.         local d_stat = {}
  406.         for line in text:gmatch("[^\n]+") do
  407.             if line:find('Вашего транспорта: %{FFEE96%}(%d+)ед. %+ (%d+)') then
  408.                 local p1,p2 = line:match('Вашего транспорта: %{FFEE96%}(%d+)ед. %+ (%d+)')
  409.                 d_stat['my'] = tonumber(p1)+tonumber(p2)
  410.             elseif line:find('Доступно к доставке: %{FFEE96%}(%d+)') then
  411.                 d_stat['sklad'] = tonumber(line:match('Доступно к доставке: %{FFEE96%}(%d+)'))
  412.             end
  413.         end
  414.         if d_stat['my']<=d_stat['sklad'] then
  415.             sampSendDialogResponse(id,1,65535,d_stat['my'])
  416.         else
  417.             sampSendDialogResponse(id,1,65535,d_stat['sklad'])
  418.         end
  419.         return false
  420.     elseif (style==5 and id==item_id and sorter_status  and bot) then
  421.         window_render_list.v = true
  422.         order={}
  423.         count=-1
  424.         for line in text:gmatch("[^\n]+") do
  425.             count=count+1
  426.                 if (line:find("%{FFDF80%}(%d+)%.%{FFFFFF%}%s+([A-Za-zА-Я а-я]+)%s+([A-Za-zА-Я а-я%-]+)%s+(%d+)%s+-%s+%$(%d+%.%d+)%s+%$(%d+%.%d+)")) then
  427.                     key,pos,product,quantity,price,delprice = line: match("%{FFDF80%}(%d+)%.%{FFFFFF%}%s+([A-Za-zА-Я а-я]+)%s+([A-Za-zА-Я а-я%-]+)%s+(%d+)%s+-%s+%$(%d+%.%d+)%s+%$(%d+%.%d+)")
  428.                     if ((product == (check_gun.v==true and 'Оружие'or'') or product == (check_food.v==true and 'Продукты питания'or'') or product == (check_furniture.v==true and 'Мебель'or'') or product == (check_fruit.v==true and 'Фрукты'or'') or product == (check_sport.v==true and 'Спорт-Товары'or'') or product == (check_pyrotechnics.v==true and 'Пиротехника'or'') or product == (check_clothes.v==true and 'Одежда'or'') or product == (check_radio.v==true and 'Радиоигрушки' or '') or product == (check_parachute.v==true and 'Парашютное снаряжение'or'') or product == (check_parachute.v==true and 'Парашютное снаряжение'or'') or product == (check_accessory.v==true and 'Аксессуары'or'') or product == (check_alcohol.v==true and 'Алкоголь'or'') or product == (check_cosmetics.v==true and 'Косметические средства'or'') or product == (check_office.v==true and 'Канцелярские товары'or'') or product == (check_sport.v==true and 'Спорт-Товары'or'')or product == (check_general.v==true and 'Товары общего пользования'or'') or product == (check_auto.v==true and 'Автозапчасти'or'') or product == (check_transport.v==true and 'Транспорт'or'')) and ( (places[u8:encode(pos)]=='LS' and check_ls.v ) or (places[u8:encode(pos)]=='SF' and check_sf.v )  or (places[u8:encode(pos)]=='LV' and check_lv.v )) and (text_maxdilprice.v <= tonumber(delprice)) and (tonumber(price)<=text_maxprice.v) ) then
  429.                         table.insert(order, {pos,product,quantity,price,delprice,key-1})
  430.                     end
  431.              end
  432.         end
  433.         local_id = id
  434.         if order == {} then
  435.             sampAddChatMessage('Увы, фильтр убрал все варианты',-1)
  436.             sampSendDialogResponse(id,0,-1)
  437.             return false
  438.         else
  439.             update_product = 1
  440.             window_render_list.v = true
  441.             return false
  442.         end
  443.     elseif update_product and title=="{FFDF80}Компания" then
  444.         if update_product  == 1 then
  445.              sampSendDialogResponse(id,-1,2)
  446.         elseif update_product == 2 and go_delivery.v then
  447.             sampSendDialogResponse(id,-1,3)
  448.         elseif update_product == 2 and not go_delivery.v then
  449.             update_product=1
  450.         elseif window_render_list.v then
  451.             sampSendDialogResponse(id,0,-1)
  452.             return false
  453.         end
  454.         return false
  455.     end
  456. end
  457. function imgui.BeforeDrawFrame()
  458.     if glyph_ranges == nil then
  459.         glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
  460.         imgui.GetIO().Fonts:Clear()
  461.         imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\arialbd.ttf', 15 , nil, glyph_ranges)
  462.         imgui.RebuildFonts()
  463.     end
  464. end
  465. function cmd_zchat()
  466.     mainIni.filters.check_chat = not mainIni.filters.check_chat
  467.     inicfg.save(mainIni, directIni)
  468.     sampAddChatMessage('Новый статус чата: '.. tostring(mainIni.filters.check_chat), -1)
  469. end
  470. function cmd_z(text)
  471. lua_thread.create(function()
  472.     if #text>0 then
  473.         if mainIni.filters.check_chat then
  474.             client:send(encodeJson({soft=soft,user=tostring(user),prefix=tostring(text_chat.v:gsub('%{[A-Za-z%d+]+%}','')),action='chat_message',text=u8:encode(tostring(text:gsub('%{[A-Za-z%d+]+%}','')))}))
  475.         else
  476.             sampAddChatMessage('У Вас выключен чат, включить его можно /zchat', -1)
  477.         end
  478.     else
  479.         sampAddChatMessage('/z <Текст>', -1)
  480.     end
  481. end)
  482. end
  483. function imgui.OnDrawFrame()
  484. local _, my_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
  485. local user = sampGetPlayerNickname(my_id)
  486. if  delivery_window_state.v or window_render_list.v then imgui.ShowCursor = true    else    imgui.ShowCursor = false end
  487. local iScreenWidth, iScreenHeight = getScreenResolution()
  488. if isCharInAnyCar(PLAYER_PED) then
  489. local car = getCarModel(storeCarCharIsInNoSave(PLAYER_PED))
  490. if bot and hud_stats.v and (car==499 or car==413 or car==498 or car==443) and delivery_stats['score']~=nil then
  491. imgui.SetNextWindowPos(imgui.ImVec2(iScreenWidth - 155, iScreenHeight / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
  492. imgui.SetNextWindowSize(imgui.ImVec2(300, 180), imgui.Cond.FirstUseEver)
  493. imgui.Begin(u8"PremiumSorter | HUD",-1, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse+imgui.WindowFlags.NoTitleBar)
  494. imgui.CenterText( u8 '  ' .. user .. '[' .. my_id ..']')
  495. imgui.Separator()
  496. imgui.Columns(2)
  497. imgui.SetColumnWidth(-1, 180)
  498. imgui.Text(u8'Ваш навык:')
  499.  
  500. imgui.Text(u8'Деньги за сутки:')
  501.  
  502. imgui.Text(u8'Рейсы за сутки:')
  503.  
  504. imgui.Text(u8'В кассу за сутки:')
  505.  
  506. imgui.Text(u8'Совершено рейсов:')
  507.  
  508. imgui.Text(u8'Заработано опыта:')
  509.  
  510. imgui.Text(u8'Заработано денег:')
  511.  
  512. imgui.NextColumn()
  513. imgui.Text(u8:encode(delivery_stats['score']<250 and 'Чайник' or (delivery_stats['score']<2500 and 'Любитель' or (delivery_stats['score']<5000 and 'Перевозчик' or 'Король') )))
  514. imgui.Text(tostring(day_money) ..'$')
  515. imgui.Text(tostring(day_reise))
  516. imgui.Text(tostring(day_box)..'$')
  517. imgui.Text(tostring(delivery_stats['reise']))
  518. imgui.Text(tostring(delivery_stats['score']))
  519. imgui.Text(tostring(delivery_stats['money']) ..'$')
  520. imgui.Columns(1)
  521. imgui.Separator()
  522. imgui.End()
  523. end
  524. end
  525. if auth_window.v then
  526.     imgui.SetNextWindowPos(imgui.ImVec2(iScreenWidth/2,iScreenHeight/2), imgui.Cond.FirstUseEver)
  527.     imgui.SetNextWindowSize(imgui.ImVec2(200, 150), imgui.Cond.FirstUseEver)
  528.     imgui.Begin(u8"Авторизация",-1, imgui.WindowFlags.ShowBorders+imgui.WindowFlags.NoCollapse+imgui.WindowFlags.ShowBorders+imgui.WindowFlags.NoMove+imgui.WindowFlags.NoResize)
  529.     imgui.Text(u8'Введите пароль от лицензии')
  530.     imgui.InputText('##password',password)
  531.     if imgui.Button(u8'Далее') then
  532.         mainIni.filters.password = password.v
  533.         inicfg.save(mainIni, directIni)
  534.         lua_thread.create(function()
  535.             _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  536.          user =  sampGetPlayerNickname(my_id)
  537.          local server,port =  sampGetCurrentServerAddress()
  538.          client:send(encodeJson({
  539.                                                             soft=soft,
  540.                                                             action = 'auth',
  541.                                                             password = password.v,
  542.                                                             user = tostring(user),
  543.                                                             server = tostring(server)
  544.                                                         }))
  545.     end)
  546.     end
  547.     imgui.End()
  548.     end
  549.     if (window_render_list.v) then
  550.         if not fullscreen.v then
  551.             imgui.SetNextWindowPos(imgui.ImVec2(iScreenWidth/2, iScreenHeight / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5,  0.5))
  552.             imgui.SetNextWindowSize(imgui.ImVec2(iScreenWidth/1.5, iScreenHeight/1.3), imgui.Cond.FirstUseEver)
  553.             imgui.Begin(u8"PremiumSorter ["..lic_day.."]",window_render_list, imgui.WindowFlags.ShowBorders +   imgui.WindowFlags.NoCollapse+imgui.WindowFlags.ShowBorders)
  554.         else
  555.             imgui.SetNextWindowPos(imgui.ImVec2(0,0))
  556.             imgui.SetNextWindowSize(imgui.ImVec2(iScreenWidth, iScreenHeight))
  557.             imgui.Begin(u8"PremiumSorter ["..lic_day.."]",window_render_list, imgui.WindowFlags.ShowBorders +   imgui.WindowFlags.NoCollapse+imgui.WindowFlags.ShowBorders + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove )
  558.         end
  559.         imgui.CenterTextColoredRGB('            {008B8B}ZAKO')
  560.         imgui.SetCursorPos(imgui.ImVec2(160,25))
  561.         imgui.TextColored(imgui.ImColor(255.0, 255.0, 255.0, 255.0):GetVec4(),u8'[ID] Заказ')
  562.         imgui.SameLine(390.0)
  563.         imgui.TextColored(imgui.ImColor(255.0, 255.0, 255.0, 255.0):GetVec4(),u8'Товар')
  564.         imgui.SameLine(550.0)
  565.         imgui.TextColored(imgui.ImColor(255.0, 255.0, 255.0, 255.0):GetVec4(),u8'Количество (ед.)')
  566.         imgui.SameLine(670.0)
  567.         imgui.TextColored(imgui.ImColor(255.0, 255.0, 255.0, 255.0):GetVec4(),u8'Стоимость (1 ед.)')
  568.         imgui.SameLine(800.0)
  569.         imgui.TextColored(imgui.ImColor(255.0, 255.0, 255.0, 255.0):GetVec4(),u8'Цена доставки (1 ед.)')
  570.         imgui.SameLine(970.0)
  571.         imgui.TextColored(imgui.ImColor(255.0, 255.0, 255.0, 255.0):GetVec4(),u8'Город')
  572.         if imgui.Checkbox(u8'Оружие',check_gun) or
  573.         imgui.Checkbox(u8'Канцелярия',check_office) or
  574.         imgui.Checkbox(u8'Мебель',check_furniture) or
  575.         imgui.Checkbox(u8'Продукты питания',check_food) or
  576.         imgui.Checkbox(u8'Алкоголь',check_alcohol) or
  577.         imgui.Checkbox(u8'Одежда',check_clothes) or
  578.         imgui.Checkbox(u8'Транспорт',check_transport) or
  579.         imgui.Checkbox(u8'Радиоигрушки',check_radio) or
  580.         imgui.Checkbox(u8'Аксессуары',check_accessory) or
  581.         imgui.Checkbox(u8'Фрукты',check_fruit) or
  582.         imgui.Checkbox(u8'Косметика',check_cosmetics) or
  583.         imgui.Checkbox(u8'Парашюты',check_parachute) or
  584.         imgui.Checkbox(u8'Спорт',check_sport) or
  585.         imgui.Checkbox(u8'Общее пользование',check_general) or
  586.         imgui.Checkbox(u8'Пиротехника',check_pyrotechnics) or
  587.         imgui.Checkbox(u8'Автозапчасти',check_auto) or
  588.         imgui.Checkbox(u8'Los-Santos',check_ls) or
  589.         imgui.Checkbox(u8'San-Fierro',check_sf) or
  590.         imgui.Checkbox(u8'Las-Venturas',check_lv)  then
  591.             mainIni.filters.check_type_towar = check_type_towar.v
  592.             mainIni.filters.check_type_product = check_type_product.v
  593.             mainIni.filters.check_type_auto = check_type_auto.v
  594.             mainIni.filters.check_gun = check_gun.v
  595.             mainIni.filters.check_ls = check_ls.v
  596.             mainIni.filters.check_sf = check_sf.v
  597.             mainIni.filters.check_lv = check_lv.v
  598.             mainIni.filters.check_office = check_office.v
  599.             mainIni.filters.check_furniture = check_furniture.v
  600.             mainIni.filters.check_food = check_food.v
  601.             mainIni.filters.check_transport = check_transport.v
  602.             mainIni.filters.check_clothes = check_clothes.v
  603.             mainIni.filters.check_alcohol = check_alcohol.v
  604.             mainIni.filters.check_radio = check_radio.v
  605.             mainIni.filters.check_fruit = check_fruit.v
  606.             mainIni.filters.check_accessory = check_accessory.v
  607.             mainIni.filters.check_cosmetics = check_cosmetics.v
  608.             mainIni.filters.check_parachute = check_parachute.v
  609.             mainIni.filters.check_sport = check_sport.v
  610.             mainIni.filters.check_general = check_general.v
  611.             mainIni.filters.check_pyrotechnics = check_pyrotechnics.v
  612.             mainIni.filters.int_price_dost = int_price_dost.v
  613.             mainIni.filters.int_sklad = int_sklad.v
  614.             mainIni.filters.int_sklad2 = int_sklad2.v
  615.             mainIni.filters.int_quantity = int_quantity.v
  616.             mainIni.filters.check_auto = check_auto.v
  617.             update_product = 1
  618.             inicfg.save(mainIni, directIni)
  619.         end
  620.         imgui.SetCursorPos(imgui.ImVec2(160,45))
  621.         imgui.BeginChild('items', imgui.ImVec2(imgui.GetWindowSize().x-imgui.GetWindowSize().x/5,imgui.GetWindowSize().y-255), true)
  622.         local prices_item = {}
  623.         local prices_del = {}
  624.         for i = 1,table.maxn(order) do
  625.             if imgui.Selectable(u8:encode('['..(i-1)..'] ' ..order[i][1])) then
  626.                 while local_id ~= item_id do wait(0) end
  627.                 sampSendDialogResponse(local_id,-1,order[i][6])
  628.                     accept_product = order[i]
  629.                     update_product = 2
  630.             end
  631.             imgui.SameLine(240.0)
  632.             imgui.CenterTextColoredRGB(order[i][2])
  633.             imgui.SameLine(470.0)
  634.             imgui.CenterTextColoredRGB(order[i][3])
  635.             imgui.SameLine(600.0)
  636.             imgui.CenterTextColoredRGB(order[i][4])
  637.             imgui.SameLine(700.0)
  638.             imgui.CenterTextColoredRGB(order[i][5])
  639.             if places[u8:encode(order[i][1])] then
  640.                 imgui.SameLine(830.0)
  641.                 imgui.CenterTextColoredRGB(places[u8:encode(order[i][1])])
  642.             end
  643.             prices_item[i] = order[i][4]
  644.             prices_del[i] = order[i][5]
  645.         end
  646.         imgui.EndChild()
  647.         imgui.Columns(2)
  648.         imgui.NewLine()
  649.         imgui.SameLine(160)
  650.         imgui.Text(u8'              Мониторинг цен на товары')
  651.         imgui.NewLine()
  652.         imgui.SameLine(160)
  653.         imgui.PlotHistogram('##item',prices_item,0,'', 0, 6, imgui.ImVec2(400, 60))
  654.         imgui.NewLine()
  655.         imgui.SameLine(160)
  656.         imgui.Text(u8'              Мониторинг цен на доставку')
  657.         imgui.NewLine()
  658.         imgui.SameLine(160)
  659.         imgui.PlotHistogram('##del',prices_del, 0,'', 0, 1.5, imgui.ImVec2(400, 60))
  660.         imgui.NextColumn()
  661.         imgui.NewLine(70)
  662.         imgui.SliderFloat(u8'Мин. цена доставки', text_maxdilprice, 0.1, 1.5)
  663.         imgui.SliderFloat(u8'Макс. цена закупа', text_maxprice, 0.0, 8)
  664.         if imgui.InputInt(u8'Стартовая задержка', accept_sleep) then
  665.                 mainIni.filters.accept_sleep = accept_sleep.v
  666.                 inicfg.save(mainIni, directIni)
  667.         end
  668.         if imgui.Checkbox(u8'Отчеты в /cm',check_cm) then
  669.              mainIni.filters.check_cm = check_cm.v
  670.                 inicfg.save(mainIni, directIni)
  671.         end
  672.         if imgui.Checkbox(u8'Автоматически забирать заказ на доставку',go_delivery) then
  673.          mainIni.filters.go_delivery = go_delivery.v
  674.          inicfg.save(mainIni, directIni)
  675.         end
  676.         imgui.Checkbox(u8'Полноэкранный режим',fullscreen)
  677.         if sampGetPlayerPing(my_id) > accept_sleep.v then
  678.             imgui.CenterTextColoredRGB('{ff0000}Задержка должна быть больше пинга! Пинг: {ffffff}' .. sampGetPlayerPing(my_id))
  679.         end
  680.         imgui.Columns(1)
  681.         imgui.End()
  682.     elseif delivery_window_state.v then
  683.         imgui.SetNextWindowPos(imgui.ImVec2(30, iScreenHeight / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5,  0.5))
  684.         imgui.SetNextWindowSize(imgui.ImVec2(380, 530), imgui.Cond.FirstUseEver)
  685.         imgui.Begin(u8"Сортировщик заказов",delivery_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.ShowBorders +   imgui.WindowFlags.NoCollapse+imgui.WindowFlags.ShowBorders)
  686.         imgui.Columns(2)
  687.         imgui.Text( u8 'Минимальная цена за ед.')
  688.         imgui.SliderFloat(u8'за ед.', int_price_dost, 0.1, 1.5)
  689.         imgui.Text( u8 'Желаемый склад.')
  690.         imgui.InputInt(u8'##3', int_sklad)
  691.         imgui.Text( u8 'Ещё желаемый склад.')
  692.         imgui.InputInt(u8'##7', int_sklad2)
  693.         imgui.Text( u8 'Минимальное количество')
  694.         imgui.InputInt(u8'##4   ', int_quantity)
  695.         if imgui.Button( u8"Сохранить") then
  696.             update_product = 1
  697.             mainIni.filters.check_type_towar = check_type_towar.v
  698.             mainIni.filters.check_type_product = check_type_product.v
  699.             mainIni.filters.check_type_auto = check_type_auto.v
  700.             mainIni.filters.check_gun = check_gun.v
  701.             mainIni.filters.check_office = check_office.v
  702.             mainIni.filters.check_furniture = check_furniture.v
  703.             mainIni.filters.check_food = check_food.v
  704.             mainIni.filters.check_transport = check_transport.v
  705.             mainIni.filters.check_clothes = check_clothes.v
  706.             mainIni.filters.check_radio = check_radio.v
  707.             mainIni.filters.check_fruit = check_fruit.v
  708.             mainIni.filters.check_accessory = check_accessory.v
  709.             mainIni.filters.check_cosmetics = check_cosmetics.v
  710.             mainIni.filters.check_parachute = check_parachute.v
  711.             mainIni.filters.check_sport = check_sport.v
  712.             mainIni.filters.check_general = check_general.v
  713.             mainIni.filters.check_alcohol = check_alcohol.v
  714.             mainIni.filters.check_pyrotechnics = check_pyrotechnics.v
  715.             mainIni.filters.int_price_dost = int_price_dost.v
  716.             mainIni.filters.int_sklad = int_sklad.v
  717.             mainIni.filters.int_sklad2 = int_sklad2.v
  718.             mainIni.filters.int_quantity = int_quantity.v
  719.             mainIni.filters.check_auto = check_auto.v
  720.             mainIni.filters.check_fruit = check_fruit.v
  721.             inicfg.save(mainIni, directIni)
  722.             sampCloseCurrentDialogWithButton(0)
  723.             sampSendChat('/delivery')
  724.         end
  725.         imgui.NextColumn()
  726.         imgui.Checkbox(u8'Перевозка товаров',check_type_towar)
  727.         imgui.Checkbox(u8'Перевозка продуктов',check_type_product)
  728.         imgui.Checkbox(u8'Перевозка транспорта',check_type_auto)
  729.         if imgui.Checkbox(u8'Худ',hud_stats) then   mainIni.filters.hud_stats = hud_stats.v ;    inicfg.save(mainIni, directIni) end
  730.         if imgui.InputText(u8'Тэг в чате /z', text_chat) then mainIni.filters.text_chat = text_chat.v ;     inicfg.save(mainIni, directIni) end
  731.         imgui.NextColumn()
  732.         imgui.Separator()
  733.         imgui.Checkbox(u8'Оружие',check_gun)
  734.         imgui.Checkbox(u8'Канцелярия',check_office)
  735.         imgui.Checkbox(u8'Мебель',check_furniture)
  736.         imgui.Checkbox(u8'Продукты питания',check_food)
  737.         imgui.Checkbox(u8'Алкоголь',check_alcohol)
  738.         imgui.Checkbox(u8'Одежда',check_clothes)
  739.         imgui.Checkbox(u8'Транспорт',check_transport)
  740.         imgui.NextColumn()
  741.         imgui.Checkbox(u8'Радиоигрушки',check_radio)
  742.         imgui.Checkbox(u8'Аксессуары',check_accessory)
  743.         imgui.Checkbox(u8'Косметика',check_cosmetics)
  744.         imgui.Checkbox(u8'Парашюты',check_parachute)
  745.         imgui.Checkbox(u8'Фрукты',check_fruit)
  746.         imgui.Checkbox(u8'Спорт',check_sport)
  747.         imgui.Checkbox(u8'Общее пользование',check_general)
  748.         imgui.Checkbox(u8'Пиротехника',check_pyrotechnics)
  749.         imgui.Checkbox(u8'Автозапчасти',check_auto)
  750.         imgui.Columns(1)
  751.         imgui.End()
  752.     end
  753.     end
  754. function imgui.CenterTextColoredRGB(text)
  755.     local width = imgui.GetWindowWidth()
  756.     local style = imgui.GetStyle()
  757.     local colors = style.Colors
  758.     local ImVec4 = imgui.ImVec4
  759.  
  760.     local explode_argb = function(argb)
  761.         local a = bit.band(bit.rshift(argb, 24), 0xFF)
  762.         local r = bit.band(bit.rshift(argb, 16), 0xFF)
  763.         local g = bit.band(bit.rshift(argb, 8), 0xFF)
  764.         local b = bit.band(argb, 0xFF)
  765.         return a, r, g, b
  766.     end
  767.  
  768.     local getcolor = function(color)
  769.         if color:sub(1, 6):upper() == 'SSSSSS' then
  770.             local r, g, b = colors[1].x, colors[1].y, colors[1].z
  771.             local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
  772.             return ImVec4(r, g, b, a / 255)
  773.         end
  774.         local color = type(color) == 'string' and tonumber(color, 16) or color
  775.         if type(color) ~= 'number' then return end
  776.         local r, g, b, a = explode_argb(color)
  777.         return imgui.ImColor(r, g, b, 1000):GetVec4()
  778.     end
  779.  
  780.     local render_text = function(text_)
  781.         for w in text_:gmatch('[^\r\n]+') do
  782.             local textsize = w:gsub('{.-}', '')
  783.             local text_width = imgui.CalcTextSize(u8(textsize))
  784.             local text, colors_, m = {}, {}, 1
  785.             w = w:gsub('{(......)}', '{%1FF}')
  786.             while w:find('{........}') do
  787.                 local n, k = w:find('{........}')
  788.                 local color = getcolor(w:sub(n + 1, k - 1))
  789.                 if color then
  790.                     text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
  791.                     colors_[#colors_ + 1] = color
  792.                     m = n
  793.                 end
  794.                 w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
  795.             end
  796.             if text[0] then
  797.                 for i = 0, #text do
  798.                     imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
  799.                     imgui.SameLine(nil, 0)
  800.                 end
  801.                 imgui.NewLine()
  802.             else
  803.                 imgui.Text(u8(w))
  804.             end
  805.         end
  806.     end
  807.     render_text(text)
  808. end
  809. function asyncHttpRequest(method, url, args, resolve, reject)
  810.    local request_thread = effil.thread(function (method, url, args)
  811.       local requests = require 'requests'
  812.       local result, response = pcall(requests.request, method, url, args)
  813.       if result then
  814.          response.json, response.xml = nil, nil
  815.          return true, response
  816.       else
  817.          return false, response
  818.       end
  819.    end)(method, url, args)
  820.    -- Если запрос без функций обработки ответа и ошибок.
  821.    if not resolve then resolve = function() end end
  822.    if not reject then reject = function() end end
  823.    -- Проверка выполнения потока
  824.    lua_thread.create(function()
  825.       local runner = request_thread
  826.       while true do
  827.          local status, err = runner:status()
  828.          if not err then
  829.             if status == 'completed' then
  830.               result, response = runner:get()
  831.                if result then
  832.                   resolve(response)
  833.                else
  834.                   reject(response)
  835.                end
  836.                return
  837.             elseif status == 'canceled' then
  838.                return reject(status)
  839.             end
  840.          else
  841.             return reject(err)
  842.          end
  843.          wait(0)
  844.       end
  845.    end)
  846. end
  847. function autoupdate(json_url, prefix, url)
  848.   local dlstatus = require('moonloader').download_status
  849.   local json = getWorkingDirectory() .. '\\'..thisScript().name..'-version.json'
  850.   if doesFileExist(json) then os.remove(json) end
  851.   downloadUrlToFile(json_url, json,
  852.     function(id, status, p1, p2)
  853.       if status == dlstatus.STATUSEX_ENDDOWNLOAD then
  854.         if doesFileExist(json) then
  855.           local f = io.open(json, 'r')
  856.           if f then
  857.             local info = decodeJson(f:read('*a'))
  858.             updatelink = info.updateurl
  859.             updateversion = info.latest
  860.             f:close()
  861.             os.remove(json)
  862.             if updateversion ~= thisScript().version then
  863.               lua_thread.create(function(prefix)
  864.                 local dlstatus = require('moonloader').download_status
  865.                 local color = -1
  866.                 if bNotf then   notf.addNotification("Обнаружено обновление, загружаю...", 3, 2) end
  867.                 wait(250)
  868.                 downloadUrlToFile(updatelink, thisScript().path,
  869.                   function(id3, status1, p13, p23)
  870.                     if status1 == dlstatus.STATUS_DOWNLOADINGDATA then
  871.                       print(string.format('Загружено %d из %d.', p13, p23))
  872.                     elseif status1 == dlstatus.STATUS_ENDDOWNLOADDATA then
  873.                       print('Загрузка обновления завершена.')
  874.                       if bNotf then notf.addNotification("Обновление загружено, запускаю...", 3, 2) end
  875.                       goupdatestatus = true
  876.                       lua_thread.create(function() wait(500) thisScript():reload() end)
  877.                     end
  878.                     if status1 == dlstatus.STATUSEX_ENDDOWNLOAD then
  879.                       if goupdatestatus == nil then
  880.                                                 if bNotf then   notf.addNotification("Ошибка обновления, запускаю старую версию", 3, 3) end
  881.                         update = false
  882.                       end
  883.                     end
  884.                   end
  885.                 )
  886.                 end, prefix
  887.               )
  888.             else
  889.               update = false
  890.               print('v'..thisScript().version..': Обновление не требуется.')
  891.             end
  892.           end
  893.         else
  894.           print('v'..thisScript().version..': Не могу проверить обновление. Смиритесь или проверьте самостоятельно на '..url)
  895.           update = false
  896.         end
  897.       end
  898.     end
  899.   )
  900.   while update ~= false do wait(100) end
  901. end
  902. function imgui.CenterText(text)
  903.     imgui.SetCursorPosX((imgui.GetWindowSize().x/2) - (imgui.CalcTextSize(text).x / 2))
  904.     imgui.Text(text)
  905. end
Add Comment
Please, Sign In to add comment