SlonPvpru

[DRP] Welder/FactoryBot v1.1

Jul 11th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.99 KB | None | 0 0
  1. -- https://www.blast.hk/threads/59236/
  2.  
  3. script_version('1.1')
  4. require "lib.sampfuncs"
  5. require "lib.moonloader"
  6. local imgui = require 'imgui'
  7. local encoding = require 'encoding'
  8. local memory = require "memory"
  9. encoding.default = 'CP1251'
  10. u8 = encoding.UTF8
  11. local objects = {}
  12. local auth = false
  13. local txd_panel = {}
  14. local iScreenWidth, iScreenHeight = getScreenResolution()
  15. local status = false
  16. local sampev = require 'lib.samp.events'
  17. local l_start = false
  18. local ip = 'ws://45.140.167.12:27802'
  19. local websocket = require 'websocket'
  20. local client = websocket.client.copas({timeout = 2})
  21. local res, https = pcall(require, 'ssl.https')
  22. assert(res, 'Library ssl.https not found')
  23.  
  24. -----------------CONFIG--------------------
  25.  
  26. local inicfg = require 'inicfg'
  27. if not doesFileExist('moonloader\\config\\FactoryBot\\FactoryBot.ini') then
  28.     if not doesDirectoryExist('moonloader\\config\\FactoryBot') then
  29.         createDirectory('moonloader\\config\\FactoryBot')
  30.     end
  31.     local  ini ={   config =    {   }   }
  32.     inicfg.save(ini, 'FactoryBot\\FactoryBot')
  33. end
  34. local directIni = 'moonloader\\config\\FactoryBot\\FactoryBot.ini'
  35. local mainIni = inicfg.load(nil, directIni)
  36.  
  37. ------------ImGUI-----------
  38.  
  39. local password = imgui.ImBuffer((mainIni.config.password and mainIni.config.password or '') ,256)
  40. local auth_status = imgui.ImBool(false)
  41.  
  42. function main()
  43.     while not isSampAvailable() do wait(100) end
  44.     sampRegisterChatCommand('fbstart', function()
  45.         status = not status
  46.         if status then
  47.             sampAddChatMessage('{00ff00}[F-BOT]{ffffff} - Бот включен', -1)
  48.             writeMemory(7634870, 1, 1, 1)
  49.             writeMemory(7635034, 1, 1, 1)
  50.             memory.fill(7623723, 144, 8)
  51.             memory.fill(5499528, 144, 6)
  52.         else
  53.             sampAddChatMessage('{00ff00}[F-BOT]{ffffff} - Бот выключен', -1)
  54.             writeMemory(7634870, 1, 0, 0)
  55.             writeMemory(7635034, 1, 0, 0)
  56.             memory.hex2bin('5051FF1500838500', 7623723, 8)
  57.             memory.hex2bin('0F847B010000', 5499528, 6)
  58.         end
  59.     end)
  60.    
  61.     autoupdate("No links", '['..string.upper(thisScript().name)..']: ', "No links")
  62.     local connected, err = client:connect(ip, '')
  63.     if err then print(err) end
  64.     if connected then
  65.         if not connected then
  66.             sampAddChatMessage('{B40431}[FY-BOT]{ffffff} - Ошибка соединения с сервером.',-1)
  67.         else
  68.             sampAddChatMessage('{B40431}[FY-BOT]{ffffff} - Вы успешно подключились к серверу ZAKO. Ожидание данных авторизации...',-1)
  69.             sampSendChat('/stats')
  70.             lua_thread.create(function()
  71.                 while true do wait(0)
  72.                     imgui.Process = auth_status.v
  73.                     local message, opcode = client:receive()
  74.                     if message then
  75.                         local result = decodeJson(message)
  76.                         if result['action']=='auth' then
  77.                             auth_status.v = false
  78.                             auth = true
  79.                         elseif result['action']=='chatmessage' then
  80.                             sampAddChatMessage('{B40431}[FY-BOT]{ffffff} - '..u8:decode(result['message']),-1)
  81.                         elseif result['action']=='error' then
  82.                             sampAddChatMessage('{ff0000}(FY-BOT) [ERROR] - {ffffff}'..u8:decode(result['text']), -1)
  83.                         elseif result['action']=='clicktxd' then
  84.                             sampSendClickTextdraw(result['id'])
  85.                         elseif result['action']=='ping' then
  86.                             client:send(encodeJson({action='pong'}))
  87.                         end
  88.                     end
  89.                 end
  90.             end)
  91.         end
  92.     end
  93. end
  94.  
  95. function sampev.onServerMessage(color,text)
  96.     if text:find('Добро пожаловать на Diamond Role Play!') then
  97.         _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  98.         user =  sampGetPlayerNickname(my_id)
  99.         auth_status.v = true
  100.     elseif text:find('Администратор [A-Za-z_%d+]+%[%d+%]:') then
  101.         lua_thread.create(function()
  102.             local   _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  103.             sendvkmessage('[FY-BOT] | '..sampGetPlayerNickname(my_id)..'<br>Пишет администратор: '..text)
  104.         end)
  105.     end
  106. end
  107.  
  108. function sampev.onCreateObject(id,data)
  109.     if status then
  110.         if #objects == 0 then
  111.             lua_thread.create(function()
  112.                 wait(1500)
  113.                 if #objects > 0 then
  114.                     _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  115.                     user =  sampGetPlayerNickname(my_id)
  116.                     local server,port =  sampGetCurrentServerAddress()
  117.                     client:send(encodeJson({
  118.                         soft='fybot',
  119.                         action = 'validobject',
  120.                         password = password.v,
  121.                         user = tostring(user),
  122.                         server = tostring(server),
  123.                         txd = txd_panel,
  124.                         objects = objects
  125.                     }))
  126.                     objects={}
  127.                 end
  128.             end)
  129.         end
  130.         local dist = getDistanceBetweenCoords3d(data.position.x ,data.position.y ,data.position.z ,getCharCoordinates(playerPed))
  131.         if dist <= 6.6 and dist > 3 then
  132.             table.insert(objects,{data.modelId,data.position.z})
  133.         end
  134.     end
  135. end
  136.  
  137. function sampev.onShowDialog(id,style,title,button1,button2,text)
  138.     if title:find('Статистика') and not auth then
  139.         auth_status.v = true
  140.         sampSendDialogResponse(id)
  141.         return false
  142.     end
  143. end
  144.  
  145. function sampev.onShowTextDraw(id,data)
  146.     if status then
  147.         if data.position.y == 206 then
  148.             txd_panel['start'] = id
  149.         elseif data.position.x==549 then
  150.             txd_panel['good'] = id
  151.         elseif data.position.x == 599 then
  152.             txd_panel['bad'] = id
  153.         elseif data.text == 'START' then
  154.             sampSendClickTextdraw(txd_panel['start'])
  155.             l_start = true
  156.         end
  157.     end
  158. end
  159.  
  160. function imgui.OnDrawFrame()
  161.     if auth_status.v then imgui.ShowCursor = true end
  162.     if auth_status.v then
  163.         imgui.SetNextWindowPos(imgui.ImVec2(iScreenWidth/2,iScreenHeight/2), imgui.Cond.FirstUseEver,imgui.ImVec2(0.5, 0.5))
  164.         imgui.SetNextWindowSize(imgui.ImVec2(200, 100), imgui.Cond.FirstUseEver)
  165.         imgui.Begin(u8"FactoryBot | Auth",-1, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse+imgui.WindowFlags.NoTitleBar)
  166.         imgui.CenterText(u8'Введите пароль')
  167.         imgui.PushItemWidth(170)
  168.         imgui.InputText('##password',password)
  169.         imgui.PopItemWidth()
  170.         imgui.NewLine()
  171.         imgui.SameLine(45)
  172.         if imgui.Button(u8'Войти',imgui.ImVec2(100, 25)) then
  173.             mainIni.config.password = password.v
  174.             inicfg.save(mainIni, directIni)
  175.             lua_thread.create(function()
  176.                 _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  177.                 user =  sampGetPlayerNickname(my_id)
  178.                 local server,port =  sampGetCurrentServerAddress()
  179.                 client:send(encodeJson({
  180.                     soft='fybot',
  181.                     action = 'auth',
  182.                     password = password.v,
  183.                     user = tostring(user),
  184.                     server = tostring(server)
  185.                 }))
  186.             end)
  187.         end
  188.         imgui.End()
  189.     end
  190. end
  191.  
  192. function imgui.CenterText(text)
  193.     imgui.SetCursorPosX((imgui.GetWindowSize().x/2) - (imgui.CalcTextSize(text).x / 2))
  194.     imgui.Text(text)
  195. end
  196.  
  197. function apply_custom_style()
  198.     imgui.SwitchContext()
  199.     local style = imgui.GetStyle()
  200.     local colors = style.Colors
  201.     local clr = imgui.Col
  202.     local ImVec4 = imgui.ImVec4
  203.  
  204.     style.WindowPadding = imgui.ImVec2(15, 15)
  205.     style.WindowRounding = 15.5
  206.     style.FramePadding = imgui.ImVec2(5, 5)
  207.     style.FrameRounding = 4.0
  208.     style.ItemSpacing = imgui.ImVec2(12, 8)
  209.     style.ItemInnerSpacing = imgui.ImVec2(8, 6)
  210.     style.IndentSpacing = 25.0
  211.     style.ScrollbarSize = 15.0
  212.     style.ScrollbarRounding = 9.0
  213.     style.GrabMinSize = 5.0
  214.     style.GrabRounding = 3.0
  215.  
  216.     colors[clr.Text] = ImVec4(0.80, 0.80, 0.83, 1.00)
  217.     colors[clr.TextDisabled] = ImVec4(0.24, 0.23, 0.29, 1.00)
  218.     colors[clr.WindowBg] = ImVec4(0.06, 0.05, 0.07, 1.00)
  219.     colors[clr.ChildWindowBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
  220.     colors[clr.PopupBg] = ImVec4(0.07, 0.07, 0.09, 1.00)
  221.     colors[clr.Border] = ImVec4(0.80, 0.80, 0.83, 0.88)
  222.     colors[clr.BorderShadow] = ImVec4(0.92, 0.91, 0.88, 0.00)
  223.     colors[clr.FrameBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
  224.     colors[clr.FrameBgHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
  225.     colors[clr.FrameBgActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
  226.     colors[clr.TitleBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
  227.     colors[clr.TitleBgCollapsed] = ImVec4(1.00, 0.98, 0.95, 0.75)
  228.     colors[clr.TitleBgActive] = ImVec4(0.07, 0.07, 0.09, 1.00)
  229.     colors[clr.MenuBarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
  230.     colors[clr.ScrollbarBg] = ImVec4(0.10, 0.09, 0.12, 1.00)
  231.     colors[clr.ScrollbarGrab] = ImVec4(0.80, 0.80, 0.83, 0.31)
  232.     colors[clr.ScrollbarGrabHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
  233.     colors[clr.ScrollbarGrabActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
  234.     colors[clr.ComboBg] = ImVec4(0.19, 0.18, 0.21, 1.00)
  235.     colors[clr.CheckMark] = ImVec4(0.80, 0.80, 0.83, 0.31)
  236.     colors[clr.SliderGrab] = ImVec4(0.80, 0.80, 0.83, 0.31)
  237.     colors[clr.SliderGrabActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
  238.     colors[clr.Button] = ImVec4(0.10, 0.09, 0.12, 1.00)
  239.     colors[clr.ButtonHovered] = ImVec4(0.24, 0.23, 0.29, 1.00)
  240.     colors[clr.ButtonActive] = ImVec4(0.56, 0.56, 0.58, 1.00)
  241.     colors[clr.Header] = ImVec4(0.10, 0.09, 0.12, 1.00)
  242.     colors[clr.HeaderHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
  243.     colors[clr.HeaderActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
  244.     colors[clr.ResizeGrip] = ImVec4(0.00, 0.00, 0.00, 0.00)
  245.     colors[clr.ResizeGripHovered] = ImVec4(0.56, 0.56, 0.58, 1.00)
  246.     colors[clr.ResizeGripActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
  247.     colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16)
  248.     colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39)
  249.     colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00)
  250.     colors[clr.PlotLines] = ImVec4(0.40, 0.39, 0.38, 0.63)
  251.     colors[clr.PlotLinesHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
  252.     colors[clr.PlotHistogram] = ImVec4(0.40, 0.39, 0.38, 0.63)
  253.     colors[clr.PlotHistogramHovered] = ImVec4(0.25, 1.00, 0.00, 1.00)
  254.     colors[clr.TextSelectedBg] = ImVec4(0.25, 1.00, 0.00, 0.43)
  255.     colors[clr.ModalWindowDarkening] = ImVec4(1.00, 0.98, 0.95, 0.73)
  256. end
  257.  
  258. apply_custom_style()
  259.  
  260. function sendvkmessage(text)
  261.     _, my_id =  sampGetPlayerIdByCharHandle(PLAYER_PED)
  262.     user =  sampGetPlayerNickname(my_id)
  263.     local result,code,err_msg = client:send(encodeJson({soft='fybot',
  264.         action='vk',
  265.         user=tostring(user),
  266.         password = password.v,
  267.         text=u8:encode(tostring(text))}))
  268.     if not result then
  269.         print('ERROR VK MESS: '..err_msg)
  270.     end
  271. end
  272.  
  273. function autoupdate(json_url, prefix, url)
  274.     local dlstatus = require('moonloader').download_status
  275.     local json = getWorkingDirectory() .. '\\'..thisScript().name..'-version.json'
  276.     if doesFileExist(json) then os.remove(json) end
  277.     downloadUrlToFile(json_url, json,
  278.         function(id, status, p1, p2)
  279.             if status == dlstatus.STATUSEX_ENDDOWNLOAD then
  280.                 if doesFileExist(json) then
  281.                     local f = io.open(json, 'r')
  282.                     if f then
  283.                         local info = decodeJson(f:read('*a'))
  284.                         updatelink = info.updateurl
  285.                         updateversion = info.latest
  286.                         f:close()
  287.                         os.remove(json)
  288.                         print(updateversion)
  289.                         if updateversion ~= thisScript().version then
  290.                             lua_thread.create(function(prefix)
  291.                                 local dlstatus = require('moonloader').download_status
  292.                                 local color = -1
  293.                                 wait(250)
  294.                                 downloadUrlToFile(updatelink, thisScript().path,
  295.                                     function(id3, status1, p13, p23)
  296.                                         if status1 == dlstatus.STATUS_DOWNLOADINGDATA then
  297.                                             print(string.format('Загружено %d из %d.', p13, p23))
  298.                                         elseif status1 == dlstatus.STATUS_ENDDOWNLOADDATA then
  299.                                             print('Загрузка обновления завершена.')
  300.  
  301.                                             goupdatestatus = true
  302.                                             lua_thread.create(function() wait(500) thisScript():reload() end)
  303.                                         end
  304.                                         if status1 == dlstatus.STATUSEX_ENDDOWNLOAD then
  305.                                             if goupdatestatus == nil then
  306.                                                 update = false
  307.                                             end
  308.                                         end
  309.                                     end
  310.                                 )
  311.                             end, prefix
  312.                             )
  313.                         else
  314.                             update = false
  315.                         end
  316.                     end
  317.                 else
  318.                     print('v'..thisScript().version..': Не могу проверить обновление. Смиритесь или проверьте самостоятельно на '..url)
  319.                     update = false
  320.                 end
  321.             end
  322.         end
  323.     )
  324.     while update ~= false do wait(100) end
  325. end
Add Comment
Please, Sign In to add comment