SlonPvpru

[ARZ] TrainBot Madrasso v1.4

Jun 4th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.67 KB | None | 0 0
  1. script_name("MDX | TRAIN BOT")
  2. script_author("madrasso")
  3. script_version("1.4")
  4. script_properties("work-in-pause")
  5.  
  6. local hook              = require('lib.samp.events')
  7. local encoding          = require('lib.encoding')
  8. local memory             = require('memory')
  9. local request           = require('lib.requests')
  10. memory.fill(0x00531155, 0x90, 5, true) -- fix jump
  11. local font                 = renderCreateFont("Arial", 10, 12)
  12. encoding.default         = 'CP1251'
  13. u8                         = encoding.UTF8
  14. cp1251                     = encoding.CP1251
  15.  
  16. local inicfg                = require('inicfg')
  17. local config = inicfg.load({
  18.     settings = {
  19.         id = 0;
  20.         ['auto-crash'] = false;
  21.     }
  22. }, '[mdx scripts] TRAIN BOT');
  23.  
  24. local other = {color = '2e82ff'};
  25.  
  26. local points = {
  27.     [1] = {2822.626953125, 90.498596191406, 24.95460319519};
  28.     [2] = {2864.75, 1329.0899658203, 9.7203121185303};
  29.     [3] = {1392.3271484375, 2632.25, 9.7203121185303};
  30.     [4] = {-1944.375, 82.024803161621, 24.618618011475};
  31.     [5] = {838.77020263672, -1388.5576171875, -2.7222609519958}
  32. }
  33.  
  34. local info = {
  35.     status = false;
  36.     state = false;
  37.     flights = 0;
  38.     earn = 0;
  39.     pickUp = nil;
  40.     point = 'не обнаружен';
  41.     speed = 34;
  42.     dist = 210;
  43.     wait = 5000;
  44.     boostSpeed = false;
  45. }
  46.  
  47. function chat(msg, type)
  48.     if type == nil then type = true end
  49.     local color = (type and other.color or 'f50575')
  50.     local msg = msg:gsub('{color}', '{'..color..'}')
  51.     sampAddChatMessage('    mdx scripts    {FFFFFF}| '..msg, (type and '0x'..other.color or 0xf50575))
  52. end
  53.  
  54. local function xf()
  55.     while not isSampAvailable() do wait(0) end
  56.     chat('Проверка наличия лицензии успешно пройдена.')
  57.     if tonumber(config['settings']['id']) >= 1 then
  58.         chat('По умолчанию установлен ид вконтакте: {color}'..config['settings']['id'])
  59.     end
  60.     if config['settings']['auto-crash'] then
  61.         chat('По умолчанию включена функция автокраша')
  62.     end
  63. end
  64.  
  65. function main()
  66.     xf()
  67.     while not isSampfuncsLoaded() or not isSampLoaded() do wait(0) end
  68.     commands();
  69.  
  70.     lua_thread.create(function()
  71.         while true do wait(0)
  72.             if info['status'] then
  73.                 renderDrawBoxWithBorder(39, 215, 200, 90, 0xAA000000, 3, 0x90f50575)
  74.                 renderFontDrawText(font, "Поинт: "..info['point'], 49, 230, 0xFFFFFFFF, 0x90000000)
  75.                 renderFontDrawText(font, "Заработано: "..info['earn'], 49, 250, 0xFFFFFFFF, 0x90000000)
  76.                 renderFontDrawText(font, "Количество рейсов: "..info['flights'], 49, 270, 0xFFFFFFFF, 0x90000000)
  77.                 local text, _, _, _ = sampGetChatString(99)
  78.                 if text:find('closed the connection') or text:find("You are banned from this server") or text:find('Use /quit to exit or press') or text:find("Lost connection to the server") then
  79.                     sampAddChatMessage(" ", -1)
  80.                     sendVK('Вы были кикнуты.')
  81.                 end
  82.             end
  83.         end
  84.     end)
  85.  
  86.     while true do wait(0)
  87.         if info['pickUp'] then
  88.             if info['pickUp'][1] and info['pickUp'][2] and info['pickUp'][3] then
  89.                 if isCharInAnyCar(PLAYER_PED) then
  90.                     local car = storeCarCharIsInNoSave(PLAYER_PED);
  91.                     local speed = getCarSpeed(car)
  92.                     printString(math.floor(speed), 50)
  93.                     local x,y,z = getCharCoordinates(PLAYER_PED)
  94.                     local dist = getDistanceBetweenCoords3d(x,y,z, info['pickUp'][1], info['pickUp'][2], info['pickUp'][3])
  95.                     local tormoz = tonumber((info['boostSpeed'] and '120' or info['dist']));
  96.                     local tormoz2 =  tonumber((info['boostSpeed'] and '15' or '80'));
  97.                     if tonumber(dist) < tormoz and tonumber(dist) > tormoz2 then
  98.                         info['state'] = 'brake'
  99.                     elseif tonumber(dist) < 10 then
  100.                         info['state'] = 'full_brake'
  101.                     end
  102.                 end
  103.                 if info['status'] and info['state'] == 'gas' and isCharInAnyCar(PLAYER_PED) then
  104.                     local car = storeCarCharIsInNoSave(PLAYER_PED);
  105.                     local speed = getCarSpeed(car)
  106.                     if speed < tonumber(info['speed']) then
  107.                         if info['boostSpeed'] and speed < 10 then
  108.                             for i = speed, info['speed'], 2 do
  109.                                 wait(200)
  110.                                 setTrainSpeed(car, i);
  111.                             end
  112.                         end
  113.                         press_gas();
  114.                     end
  115.                 elseif info['status'] and isCharInAnyCar(PLAYER_PED) then
  116.                     local car = storeCarCharIsInNoSave(PLAYER_PED);
  117.                     local speed = getCarSpeed(car)
  118.                     if info['state'] == 'brake' then
  119.                         if speed >= 8 then
  120.                             if info['boostSpeed'] then
  121.                                 print('bost brake')
  122.                                 for i = speed, 7, -4 do
  123.                                     wait(150)
  124.                                     if isCharInAnyCar(PLAYER_PED) then
  125.                                         setTrainSpeed(car, i);
  126.                                     end
  127.                                 end
  128.                             end
  129.                             press_brake();
  130.                         end
  131.                     elseif info['state'] == 'full_brake' then
  132.                         if speed > 1.2 then
  133.                             if info['boostSpeed'] then
  134.                                 print('bost brake full')
  135.                                 wait(300)
  136.                                 if isCharInAnyCar(PLAYER_PED) then
  137.                                     setTrainSpeed(car, 1);
  138.                                 end
  139.                             end
  140.                             press_brake();
  141.                         else
  142.                             if isCharInAnyCar(PLAYER_PED) then
  143.                                 setTrainSpeed(car, 0.6);
  144.                             end
  145.                             wait(500);
  146.                             if isCharInAnyCar(PLAYER_PED) then
  147.                                 setTrainSpeed(car, 0);
  148.                             end
  149.                             wait(info['wait']);
  150.                             if isCharInAnyCar(PLAYER_PED) then
  151.                                 setTrainSpeed(car, 0);
  152.                                 info['state'] = 'gas'
  153.                             end
  154.                             wait(500)
  155.                         end
  156.                     end
  157.                 elseif info['status'] and info['state'] == 'toPickUp' then
  158.                     GoToCoord(-2095.4909667969, 514.75042724609, 1487.6927490234);
  159.                     GoToCoord(-2098.5727539063, 512.82043457031, 1487.6927490234);
  160.                     GoToCoord(-2102.4104003906, 512.78045654297, 1487.6927490234);
  161.                     good_dialog = false;
  162.                     while not good_dialog do
  163.                         setGameKeyState(21, 255);
  164.                         sampForceOnfootSync();
  165.                         wait(5000);
  166.                     end
  167.                     good_dialog = false;
  168.                     info['state'] = false;
  169.                 end
  170.             end
  171.         end
  172.     end
  173. end
  174.  
  175. function commands()
  176.     sampRegisterChatCommand('tgo', train_start)
  177.     sampRegisterChatCommand('tgo.id', train_id)
  178.     sampRegisterChatCommand('tgo.crash', train_crash)
  179.     sampRegisterChatCommand('tgo.speed', train_speed)
  180.     sampRegisterChatCommand('tgo.dist', train_dist)
  181.     sampRegisterChatCommand('tgo.wait', train_wait)
  182.     sampRegisterChatCommand('tgo.boost', function()
  183.         info['boostSpeed'] = not info['boostSpeed']
  184.         chat('Буст скорости {color}'..(info['boostSpeed'] and 'активирован' or 'деактивирован'),info['boostSpeed'])
  185.     end);
  186. end
  187.  
  188. function hook.onServerMessage(color, msg)
  189.     if msg:find('Рейс успешно завершен') then
  190.         info['earn'] = info['earn'] + tonumber(msg:match('Заработано за рейс: (%d+)%$'))
  191.         info['flights'] = info['flights'] + 1
  192.         sendVK('Рейс успешно завершен.\n\nЗаработано виртов: '..info['earn']..'\n Количество рейсов проехано: '..info['flights'])
  193.         lua_thread.create(function() info['state'] = false wait(9000) info['state'] = 'toPickUp' end)
  194.     elseif msg:match('Администратор .*:.*{%w+}.*') then
  195.         local admin, answer = msg:match('Администратор (.*):.*{%w+}(.*)')
  196.         sendVK('Администратор '..tostring(admin)..': '..tostring(answer))
  197.         if config['settings']['auto-crash'] then callFunction(0x823BDB, 3, 3, 0, 0, 0) end
  198.     end
  199. end
  200.  
  201. function hook.onTextDrawSetString(id, text)
  202.     if id == 2074 then
  203.         info['pickUp'] = points[tonumber(text)]
  204.         info['point'] = tonumber(text)
  205.         print('Point: '..tonumber(text))
  206.     end
  207. end
  208.  
  209. function hook.onShowDialog(id, style, title, btn1, btn2, text)
  210.     if info['status'] then
  211.         if text:find('Вы хотите занять очередь на регистрацию рейса') then
  212.             good_dialog = true
  213.             sampSendDialogResponse(id, 1, -1, -1)
  214.             return false
  215.         elseif text:find('Ваша очередь подошла, завершить регистрацию рейса') then
  216.             info['state'] = false
  217.             lua_thread.create(function()
  218.                 sendVK('Новый рейс успешно начат.')
  219.                 wait(15000)
  220.                 info['state'] = 'gas';
  221.             end)
  222.             sampSendDialogResponse(id, 1, -1, -1)
  223.             return false
  224.         elseif text:find'Сейчас все рабочие места на рейсах заняты' then
  225.             sampSendDialogResponse(id, 1, -1, -1)
  226.             return false
  227.         elseif text:find('в живой очереди на регистрацию рейса') then
  228.             sampSendDialogResponse(id, 1, -1, -1)
  229.             return false
  230.         elseif text:find('Вы хотите освободить своё место в очереди') then
  231.             good_dialog = true
  232.             sampSendDialogResponse(id, 0, -1, -1)
  233.             return false
  234.         end
  235.     end
  236. end
  237.  
  238. function train_start()
  239.     info['status'] = not info['status']
  240.     WorkInBackground(info['status']);
  241.     chat('Статус бота: {color}'..(info['status'] and 'включен' or 'выключен'), info['status'])
  242.     if isCharInAnyCar(PLAYER_PED) then
  243.         info['state'] = (info['status'] and 'gas' or false)
  244.     end
  245. end
  246.  
  247. function train_id(var)
  248.     if tonumber(var) == nil or #var == 0 or tonumber(var) <= 0 then
  249.         chat('Неверно указан ид вконтакте.', false)
  250.         return
  251.     else
  252.         chat('Установлен новый ид вконтакте: {color}'..tonumber(var))
  253.         config['settings']['id'] = tonumber(var)
  254.         inicfg.save(config, '[mdx scripts] TRAIN BOT')
  255.     end
  256. end
  257.  
  258. function train_crash()
  259.     config['settings']['auto-crash'] = not config['settings']['auto-crash']
  260.     chat('Автоматический краш {color}'..(config['settings']['auto-crash'] and 'включен' or 'выключен'), config['settings']['auto-crash'])
  261. end
  262.  
  263. function train_speed(var)
  264.     if tonumber(var) == nil or #var == 0 or tonumber(var) <= 0 then
  265.         chat('Укажите число.', false)
  266.         return
  267.     else
  268.         chat('Установлена новая максимальная скорость: {color}'..tonumber(var))
  269.         info['speed'] = tonumber(var);
  270.     end
  271. end
  272.  
  273. function train_dist(var)
  274.     if tonumber(var) == nil or #var == 0 or tonumber(var) <= 0 then
  275.         chat('Укажите число.', false)
  276.         return
  277.     else
  278.         chat('Установлена новая дистанция начатия торзможения: {color}'..tonumber(var))
  279.         info['dist'] = tonumber(var);
  280.     end
  281. end
  282.  
  283. function train_wait(var)
  284.     if tonumber(var) ~= nil then
  285.         chat('Установлена новая задержка остановки на станциях: {color}'..tonumber(var))
  286.         info['wait'] = tonumber(var);
  287.     else
  288.         chat('Укажите число.', false)
  289.         return
  290.     end
  291. end
  292.  
  293. function press_gas()
  294.     writeMemory(0xB73458 + 0x20, 1, 255, false)
  295. end
  296.  
  297. function press_brake()
  298.     writeMemory(0xB73458 + 0x1C, 1, 255, false)
  299. end
  300.  
  301. function GoToCoord(x,y,z)
  302.     local koef1, koef2 = 1.05, 0.02
  303.     local function getPov(ang)
  304.         return (ang^koef1)*koef2*100/memory.getfloat(0xB7CB50, true)
  305.     end
  306.     while not locateCharAnyMeans2d(PLAYER_PED, x, y, 1, 1, true) and info['status'] do
  307.         local POSX,POSY,POSZ = getCharCoordinates(PLAYER_PED)
  308.         local angle    = math.acos((x-POSX)/math.sqrt((x - POSX)*(x - POSX)+(y - POSY)*(y - POSY)))
  309.         if POSY > y then angle = 2*math.pi - angle end --получение угла
  310.         if angle < 0 then angle = angle + 2*math.pi end
  311.         angle    = math.deg(angle)
  312.         local angX    = math.asin((z-POSZ)/math.sqrt((z-POSZ)^2+(y-POSY)^2))
  313.         local cpx,cpy,cpz     = getActiveCameraCoordinates()
  314.         local cx,cy,cz     = getActiveCameraPointAt()
  315.         local curangle     = math.acos((cx-cpx)/math.sqrt((cx-cpx)*(cx-cpx)+(cy-cpy)*(cy-cpy)))
  316.         if cpy > cy then curangle = 2*math.pi - curangle end -- получение текущего угла камеры
  317.         curangle = math.deg(curangle)
  318.         local heading = getCharHeading(PLAYER_PED) + 90
  319.         if heading > 360 then heading = heading - 360 end
  320.         local angsum = 360 - curangle + angle
  321.         if angsum > 360 then angsum = angsum - 360 end
  322.         if angsum < 180 then curangle = curangle + getPov(angsum)
  323.         else curangle = curangle - getPov(360-angsum) end
  324.         local xAngle    = math.asin((z-POSZ)/math.sqrt((z-POSZ)^2+(math.sqrt((x-POSX)^2+(y-POSY)^2))^2))
  325.         setCameraPositionUnfixed(xAngle,math.rad(curangle)+math.pi)
  326.         setGameKeyState(1, -255)
  327.         wait(0)
  328.     end
  329. end
  330.  
  331. function WorkInBackground(work)
  332.     local memory = require 'memory'
  333.     if work then
  334.         memory.setuint8(7634870, 1)
  335.         memory.setuint8(7635034, 1)
  336.         memory.fill(7623723, 144, 8)
  337.         memory.fill(5499528, 144, 6)
  338.     else
  339.         memory.setuint8(7634870, 0)
  340.         memory.setuint8(7635034, 0)
  341.         memory.hex2bin('5051FF1500838500', 7623723, 8)
  342.         memory.hex2bin('0F847B010000', 5499528, 6)
  343.     end
  344. end
  345.  
  346. function sendVK(text)
  347.     if tonumber(config['settings']['id']) == nil or type(config['settings']['id']) ~= 'number' then
  348.         chat('Неверно указан ид страницы, отправка сообщения отменена.', false)
  349.         return
  350.     end
  351.     local _, myid = sampGetPlayerIdByCharHandle(PLAYER_PED)
  352.     local text = toSendGet("[TRAIN-BOT]\n"..text.."\n\n - "..sampGetPlayerNickname(myid).."["..myid.."] - "..tostring(getServer()).."&#10084;")
  353.     local result, response = pcall(request.get, "http://scripts.mdx-scripts.ru/notifications/messages.php?message="..text.."&id="..config['settings']['id'].."&type=send")
  354. end
  355.  
  356. function toSendGet(str)
  357.     local diff = urlencode(u8:encode(str, 'CP1251'))
  358.     return diff
  359. end
  360.  
  361. function urlencode(str)
  362.     if (str) then
  363.         str = string.gsub (str, "\n", "\r\n")
  364.         str = string.gsub (str, "([^%w ])",
  365.             function (c) return string.format ("%%%02X", string.byte(c)) end)
  366.         str = string.gsub (str, " ", "+")
  367.     end
  368.     return str
  369. end
  370.  
  371. function getServer()
  372.     servers = {"Phoenix", "Tucson", "Scottdale", "Chandler", "Brainburg", "Saint Rose", "Mesa", "Red-Rock", "Yuma"}
  373.     for i = 1, #servers do
  374.         if sampGetCurrentServerName():find(servers[i]) then
  375.             return servers[i]
  376.         end
  377.     end
  378.     return 'Unknown'
  379. end
  380.  
  381. function SearchMarker(posX, posY, posZ, radius, isRace)
  382.     local ret_posX = 0.0
  383.     local ret_posY = 0.0
  384.     local ret_posZ = 0.0
  385.     local isFind = false
  386.  
  387.     for id = 0, 31 do
  388.         local MarkerStruct = 0
  389.         if isRace then MarkerStruct = 0xC7F168 + id * 56
  390.         else MarkerStruct = 0xC7DD88 + id * 160 end
  391.         local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
  392.         local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
  393.         local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
  394.  
  395.         if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
  396.             if getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ) < radius then
  397.                 ret_posX = MarkerPosX
  398.                 ret_posY = MarkerPosY
  399.                 ret_posZ = MarkerPosZ
  400.                 isFind = true
  401.                 radius = getDistanceBetweenCoords3d(MarkerPosX, MarkerPosY, MarkerPosZ, posX, posY, posZ)
  402.             end
  403.         end
  404.     end
  405.  
  406.     return isFind, ret_posX, ret_posY, ret_posZ, radius
  407. end
  408.  
  409. function hook.onSendVehicleSync(data)
  410.     if info['status'] then
  411.         if tonumber(math.sqrt(data.moveSpeed.x * data.moveSpeed.x + data.moveSpeed.y * data.moveSpeed.y + data.moveSpeed.z * data.moveSpeed.z) * 126) > 80 then
  412.             data.moveSpeed.x = 0
  413.             data.moveSpeed.y = 0.66996252536774
  414.             data.moveSpeed.z = 0.0033537545241416
  415.         end
  416.     end
  417. end
  418.  
  419. function hook.onSendDeathNotification(reason, killerId)
  420.     sendVK('Вы умерли.')
  421. end
Add Comment
Please, Sign In to add comment