Advertisement
Reavik

Robsom

Jan 7th, 2023 (edited)
119
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.87 KB | None | 1 0
  1. --Update 2.1
  2. local nameBot = "Robsom"
  3. --local namePlayer = "Reavik"
  4. local namePlayer = "Reavik"
  5. local limpar = "SOUTH"
  6. local toChest = "NORTH"
  7. local toInv = "EAST"
  8. -- Printa tudo oque o player escreve
  9. local debug = false
  10. -- Não mude, apenas digite "mon"
  11. local monitor = true
  12. -- Tamanho do texto
  13. local scale = 0.5
  14. -- Entre 1 e 16
  15. local color = 2
  16. -- Modem Portas
  17. local m1 = 100
  18. local m2 = 200
  19.  
  20. local im = peripheral.find("inventoryManager")
  21. print("[" .. nameBot .. "]" .. " Localizando InventoryManager...")
  22. local cb = peripheral.find("chatBox")
  23. print("[" .. nameBot .. "]" .. " Localizando ChatBox...")
  24. local rs = peripheral.find("rsBridge")
  25. print("[" .. nameBot .. "]" .. " Localizando ponte RS...")
  26. local modem = peripheral.wrap("right")
  27. print("[" .. nameBot .. "]" .. " Localizando Moden...")
  28. modem.open(m1, m2)
  29. local mon = peripheral.find("monitor")
  30. print("[" .. nameBot .. "]" .. " Localizando Monitor...")
  31.  
  32. if mon == nil then
  33.     print("[" .. nameBot .. "]" .. " Monitor não encontrado")
  34. else
  35.     mon.setTextColor(color)
  36.     mon.setTextScale(scale)
  37.     term.redirect(mon)
  38.     print("[" .. nameBot .. "]" .. " Monitor encontrado")
  39. end
  40.  
  41. if im == nil then
  42.     print("[" .. nameBot .. "]" .. " Gerenciandor de inventario não encontrado")
  43. else
  44.     print("[" .. nameBot .. "]" .. " inventoriManager encontrado")
  45. end
  46.  
  47. if cb == nil then
  48.     print("[" .. nameBot .. "]" .. " Caixa de Chat não encontrada")
  49. else
  50.     print("[" .. nameBot .. "]" .. " chatBox encontrada")
  51. end
  52.  
  53. if rs == nil then
  54.     print("[" .. nameBot .. "]" .. " Ponte RS não encontrada")
  55. else
  56.     print("[" .. nameBot .. "]" .. " Ponte RS localizada")
  57. end
  58.  
  59. if modem == nil then
  60.     print("[" .. nameBot .. "]" .. " Modem não encontrado")
  61. else
  62.     print("[" .. nameBot .. "]" .. " Modem localizado")
  63. end
  64.  
  65. function dump(o)
  66.     if type(o) == "table" then
  67.         local s = "{ "
  68.         for k, v in pairs(o) do
  69.             if type(k) ~= "number" then
  70.                 k = '"' .. k .. '"'
  71.             end
  72.             s = s .. "[" .. k .. "] = " .. dump(v) .. ","
  73.         end
  74.         return s .. "} "
  75.     else
  76.         return tostring(o)
  77.     end
  78. end
  79.  
  80. function Split(s, delimiter)
  81.     result = {};
  82.     for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
  83.         table.insert(result, match);
  84.     end
  85.     return result;
  86. end
  87.  
  88. function sendMessage(message)
  89.     if cb ~= nil then
  90.     cb.sendMessageToPlayer(message, namePlayer, nameBot)
  91.     end
  92.     print("[" .. nameBot .. "]" .. message)
  93.     if modem ~= nil then
  94.         modem.transmit(m1, m2, "[" .. nameBot .. "]" .. message)
  95.     end
  96. end
  97.  
  98. sendMessage(" Já estou online e pronto para trabalhar!")
  99.  
  100. while true do
  101.     local e, player, msg = os.pullEvent("chat")
  102.     local split_string = Split(msg, " ")
  103.     local msg = string.lower(split_string[1])
  104.     local item = split_string[2]
  105.     local quantity = tonumber(split_string[3])
  106.  
  107.     if debug  and player == namePlayer then
  108.         print(player..": "..msg)
  109.         sendMessage(" "..player..": "..msg)
  110.     end
  111.     if msg == "ajuda" and player == namePlayer then
  112.         li = {
  113.             "       Esses são meus comandos       ",
  114.             " --------------- 1 / 4 --------------",
  115.             " pegar <item> <quantidade> EX: pegar glass 64",
  116.             " --------------- 2 / 4 --------------",
  117.             " limpar ou limpar <n1> EX: limpar 1/2/3/4",
  118.             " --------------- 3 / 4 --------------",
  119.             " craft <nomeDoItem> ou craftar <nomeDoItem> -> para craftar",
  120.             " --------------- 4 / 4 --------------",
  121.             " cons <nomeDoItem> -> para ver quantos desse item você possui",
  122.             " ------------------------------------"
  123.         }
  124.         for i = 1, #li do
  125.             sendMessage(li[i])
  126.             os.sleep(1)
  127.         end
  128.     end
  129.     if msg == "pegar" and player == namePlayer and rs ~= nil   and im ~= nil then
  130.         local Tabela = rs.listItems()
  131.         local search = nil
  132.         local exato = nil
  133.         local parecido = nil
  134.         local parecido2 = nil
  135.  
  136.         for a = 1, #Tabela, 1 do
  137.             local splitOn = Tabela[a]["displayName"]
  138.             -- Ajusto na string.
  139.             local t = {}
  140.             for w in string.gsub(item, "([%u][%l]*)", "%1 "):gmatch("%S+") do
  141.                 table.insert(t, w)
  142.             end
  143.             ItemTextoGrande = ""
  144.             for i, word in ipairs(t) do
  145.                 ItemTextoGrande = ItemTextoGrande .. word .. " "
  146.             end
  147.             ItemTextoGrande = string.sub(ItemTextoGrande, 1, -2) -- remove o último espaço em branco
  148.  
  149.             -- Buscando Item
  150.             local inicio, fim = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[1])) -- First Word
  151.             local inicio2 = nil
  152.             local inicio3 = nil
  153.             if t[2] ~= nil then inicio2 = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[2])) end -- Second Word
  154.             if t[3] ~= nil then inicio3 = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[3])) end -- Third Word
  155.  
  156.             if (string.lower(splitOn) == string.lower("[" .. ItemTextoGrande .. "]") and exato == nil) then
  157.                 exato = Tabela[a]
  158.             elseif inicio3 ~= nil and inicio2 ~= nil and inicio ~= nil then
  159.                 parecido = Tabela[a]
  160.                 parecido2 = Tabela[a]
  161.             elseif inicio2 ~= nil and inicio ~= nil and parecido2 == nil then
  162.                 parecido = Tabela[a]
  163.             elseif inicio ~= nil and parecido == nil then
  164.                 parecido = Tabela[a]
  165.             end
  166.         end
  167.  
  168.         if exato ~= nil then
  169.             search = exato
  170.         elseif parecido ~= nil then
  171.             search = parecido
  172.         end
  173.  
  174.         if (search == nil) then
  175.             sendMessage(" Este item '" .. item .. "' não foi encontrado!")
  176.         else
  177.             if quantity == nil then quantity = 1 end
  178.                 rs.exportItem({ name = search["name"], count = quantity }, (toChest))
  179.                 im.addItemToPlayer(toInv, quantity, 0, search["name"])
  180.             if quantity > search["amount"]then
  181.                 sendMessage(" Você apenas possui [" .. search["amount"] .. "] " .. search["displayName"] .. " no seu sistema.")
  182.             end
  183.             if search["amount"]< 1 then
  184.                 sendMessage(" Acabaram todos os itens de '" .. search["displayName"] .. "' do sistema!")
  185.             else
  186.                 sendMessage(" Item " .. search["displayName"] .. " adicionado ao seu inventário.")
  187.             end
  188.         end
  189.     end
  190.     if msg == "limpar" and player == namePlayer  and rs ~= nil  and im ~= nil then
  191.     sendMessage(" Ok, limpando seu inventário.")
  192.     myInv = im.getItems()
  193.     local foo = {}
  194.  
  195.     for k, v in pairs(myInv) do
  196.         table.insert(foo, k, v.count)
  197.     end
  198.  
  199.     local lines = {
  200.         { min = 9, max = 17 },
  201.         { min = 18, max = 26 },
  202.         { min = 27, max = 35 },
  203.         { min = 0, max = 8 },
  204.         { min = 9, max = 35 }
  205.     }
  206.     local search = 5
  207.     if item then
  208.         search = tonumber(item)
  209.     else
  210.         search = 5
  211.     end
  212.  
  213.     for k, v in pairs(myInv) do
  214.         table.insert(foo, k, v.count)
  215.     end
  216.  
  217.     for k, v in pairs(foo) do
  218.         if k >= lines[search].min and k <= lines[search].max then
  219.             im.removeItemFromPlayer(limpar, v, k)
  220.         end
  221.     end
  222.     end
  223.     if msg == "cons" and player == namePlayer  and rs ~= nil then
  224.         local Tabela = rs.listItems()
  225.         local search = nil
  226.         local exato = nil
  227.         local parecido = nil
  228.         local parecido2 = nil
  229.  
  230.         for a = 1, #Tabela, 1 do
  231.             local splitOn = Tabela[a]["displayName"]
  232.             -- Ajusto na string.
  233.             local t = {}
  234.             for w in string.gsub(item, "([%u][%l]*)", "%1 "):gmatch("%S+") do
  235.                 table.insert(t, w)
  236.             end
  237.             ItemTextoGrande = ""
  238.             for i, word in ipairs(t) do
  239.                 ItemTextoGrande = ItemTextoGrande .. word .. " "
  240.             end
  241.             ItemTextoGrande = string.sub(ItemTextoGrande, 1, -2) -- remove o último espaço em branco
  242.  
  243.             -- Buscando Item
  244.             local inicio, fim = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[1])) -- First Word
  245.             local inicio2 = nil
  246.             local inicio3 = nil
  247.             if t[2] ~= nil then inicio2 = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[2])) end -- Second Word
  248.             if t[3] ~= nil then inicio3 = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[3])) end -- Third Word
  249.  
  250.             if (string.lower(splitOn) == string.lower("[" .. ItemTextoGrande .. "]") and exato == nil) then
  251.                 exato = Tabela[a]
  252.             elseif inicio3 ~= nil and inicio2 ~= nil and inicio ~= nil then
  253.                 parecido = Tabela[a]
  254.                 parecido2 = Tabela[a]
  255.             elseif inicio2 ~= nil and inicio ~= nil and parecido2 == nil then
  256.                 parecido = Tabela[a]
  257.             elseif inicio ~= nil and parecido == nil then
  258.                 parecido = Tabela[a]
  259.             end
  260.         end
  261.  
  262.         if exato ~= nil then
  263.             search = exato
  264.         elseif parecido ~= nil then
  265.             search = parecido
  266.         end
  267.         print("["..nameBot.."] Buscando por " .. item)
  268.         if search == nil then
  269.             sendMessage(" Não foi encontrado " .. item .. " no estoque.")
  270.         else
  271.             local craftavel = ""
  272.             if search["isCraftable"] then
  273.                 craftavel = "Sim"
  274.             else
  275.                 craftavel = "Não"
  276.             end
  277.             sendMessage(" Atualmente você tem " .. search["amount"] .. " " .. search["displayName"] .. " em estoque.")
  278.             print("["..nameBot.."] Atualmente você tem " .. search["amount"] .. " " .. search["displayName"] .. " em estoque.")
  279.             if modem ~= nil then
  280.                 local tag = ""
  281.                 if search["tags"] == nil then
  282.                     tag = "[Tag não encontrada]"
  283.                 else
  284.                     tag = search["tags"][1]
  285.                 end
  286.                 if modem ~= nil then
  287.                     modem.transmit(m1, m2, "         Informações sobre "..search["displayName"])
  288.                     modem.transmit(m1, m2, "         Nome:          "..search["displayName"])
  289.                     modem.transmit(m1, m2, "         Quantidade:    ["..search["amount"].."]")
  290.                     modem.transmit(m1, m2, "         Craftavel:     "..craftavel)
  291.                     modem.transmit(m1, m2, "         Tag do Item:   "..tag)
  292.                 end
  293.             end
  294.         end
  295.     end
  296.     if msg == "craft" and player == namePlayer  and rs ~= nil  then
  297.         local Tabela = rs.listItems()
  298.         local search = nil
  299.         local exato = nil
  300.         local parecido = nil
  301.         local parecido2 = nil
  302.  
  303.         if quantity == nil then quantity = 1 end
  304.  
  305.         for a = 1, #Tabela, 1 do
  306.             local splitOn = Tabela[a]["displayName"]
  307.             -- Ajusto na string.
  308.             local t = {}
  309.             for w in string.gsub(item, "([%u][%l]*)", "%1 "):gmatch("%S+") do
  310.                 table.insert(t, w)
  311.             end
  312.             ItemTextoGrande = ""
  313.             for i, word in ipairs(t) do
  314.                 ItemTextoGrande = ItemTextoGrande .. word .. " "
  315.             end
  316.             ItemTextoGrande = string.sub(ItemTextoGrande, 1, -2) -- remove o último espaço em branco
  317.  
  318.             -- Buscando Item
  319.             local inicio, fim = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[1])) -- First Word
  320.             local inicio2 = nil
  321.             local inicio3 = nil
  322.             if t[2] ~= nil then inicio2 = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[2])) end -- Second Word
  323.             if t[3] ~= nil then inicio3 = string.find(string.lower(Tabela[a]["displayName"]), string.lower(t[3])) end -- Third Word
  324.  
  325.             if (string.lower(splitOn) == string.lower("[" .. ItemTextoGrande .. "]") and exato == nil) then
  326.                 exato = Tabela[a]
  327.             elseif inicio3 ~= nil and inicio2 ~= nil and inicio ~= nil then
  328.                 parecido = Tabela[a]
  329.                 parecido2 = Tabela[a]
  330.             elseif inicio2 ~= nil and inicio ~= nil and parecido2 == nil then
  331.                 parecido = Tabela[a]
  332.             elseif inicio ~= nil and parecido == nil then
  333.                 parecido = Tabela[a]
  334.             end
  335.         end
  336.  
  337.         if exato ~= nil then
  338.             search = exato
  339.         elseif parecido ~= nil then
  340.             search = parecido
  341.         end
  342.  
  343.         if search == nil then
  344.             sendMessage(" O item "..item.." não foi encontrado.")
  345.         else
  346.             if search["isCraftable"] == true then
  347.                 sendMessage(" Craftando [" .. quantity .."] unidades de " .. search["displayName"])
  348.                 rs.craftItem({ name = search["name"], count = quantity })
  349.             else
  350.                 sendMessage(" O item " .. search["displayName"] .. " não é craftável.")
  351.             end
  352.         end
  353.     end
  354.     if msg == "restart" and player == namePlayer then
  355.         if mon ~= nil then
  356.             mon.clear()
  357.         end
  358.         print("[" .. nameBot .. "]" .. " Reiniciando o sistema.")
  359.         os.reboot()
  360.     end
  361.     if msg == "mon" and player == namePlayer  and mon ~= nil then
  362.         if monitor == true then
  363.             print("[" .. nameBot .. "]" .. " Monitor encontrado, redirecionando.")
  364.             term.current()
  365.         else
  366.             print("[" .. nameBot .. "]" .. " Voltando para o terminal")
  367.             mon.setTextScale(scale)
  368.             mon.setTextColor(color)
  369.             term.redirect(mon)
  370.             monitor = true
  371.         end
  372.         elseif msg == "mon" and player == namePlayer and modem ~= nil then
  373.         modem.transmit(m1, m2, "mon")
  374.     end
  375.     if msg == "debug" and player == namePlayer then
  376.         debug = not debug
  377.     end
  378. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement