Advertisement
Gallent

Crafty

Mar 19th, 2025 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 47.20 KB | None | 0 0
  1. -- Current plan:
  2. -- Create somewhere the bot can access the network. (supply)
  3. -- Give it another inventory it can move things into, and from there suck into the turtle
  4.  
  5. -- Have loop using the parallel api.
  6. -- Make it listen for chat. Format of "crafty <routine> <amount> <return to current>"
  7. -- "crafty stop" should make the bot immediately cease the program and, if possible, return to base station or wherever it started.
  8.  
  9. -- first argument should accept stuff like fleshAuto, sourceGems, essence, etc.
  10. -- instead of running the actual files, these will set the the information that the computer has to use.
  11. -- Namely, target (the type of device to use), materials (a table of possible materials), and results
  12. -- If the last argument is true, then save the current location as tempHome.
  13. -- teleport to the access point, read through the network until you find the correct item id, move it to the other inventory in slot 1, then suck into turtle
  14. -- teleport to correct point ("imbuer" for source gems, "basin" for leather, etc), then execute normal program
  15.  
  16. -- when done or stopped, check if that last argument was true. If not, return to the access point, deposit the result, send message to me, then either remain there or return to a default
  17. -- if true, then check how much fuel it takes to return. If it's too expensive, still return to base point and deposit the result
  18. -- otherwise, if argument is true and if there is enough fuel to return to starting location, do so
  19.  
  20.  
  21. -- Possibly set up "crafty echo"/"crafty say" program so that I can make crafty speak.
  22. -- preprogrammed responses? "Hey Crafty, say hello" could make crafty send a message to the whole server like "Hello, I'm Crafty! Ivy's autocrafting bot! Pleased to meet you all!"
  23. -- table of responses to the phrase "Hello Crafty" based on each user.
  24. local chatBox = peripheral.find("chatBox")
  25. local automata = peripheral.find("endAutomata")
  26.  
  27. --important IDs
  28. local turtleStorageName = "turtle_2"
  29. local mainPoint = "supply"
  30. local ownerIGN="Gallent_Bristle"
  31.  
  32. chatBox.sendMessageToPlayer("Good morning, I'm up and running!", ownerIGN, "Crafty")
  33.  
  34. local programTable
  35.  
  36. local storageNames={
  37.     drawers="functionalstorage:storage_controller_0",
  38.     mainStorage="occultism:storage_controller_1",
  39.     -- apotheosis="sophisticatedstorage:controller_1",
  40.     -- ironScrolls="entangled:tile_0"
  41. }
  42.  
  43. local storageModems={}
  44.  
  45. local function storageSync() if automata.distanceToPoint(mainPoint) == 0 then for k,v in pairs(storageNames) do storageModems[k]=peripheral.wrap(v) end end end
  46.  
  47. --Variables for the crafting programs
  48. local queue={}
  49. local working=false
  50. local stopped=false
  51. local clearQueue=false
  52. local paused=false
  53. local pauseLoc
  54. local suck,drop
  55.  
  56. local altReturn=false
  57.  
  58. local fuelList = {
  59.     ["minecraft:charcoal"]=80,
  60.     ["minecraft:coal"]=80,
  61.     ["modern_industrialization:lignite_coal"]=80
  62. }
  63.  
  64.  
  65. local sideSearch = function(peripheralName)
  66.     local sideTable = {
  67.         front=function()
  68.             suck = turtle.suck
  69.             drop = turtle.drop
  70.             return true
  71.         end,
  72.         left=function()
  73.             turtle.turnLeft()
  74.             suck = turtle.suck
  75.             drop = turtle.drop
  76.         return true end,
  77.         right=function()
  78.             turtle.turnRight()
  79.             suck = turtle.suck
  80.             drop = turtle.drop
  81.         return true end,
  82.         back=function ()
  83.             turtle.turnLeft()
  84.             turtle.turnLeft()
  85.             suck = turtle.suck
  86.             drop = turtle.drop
  87.             return true
  88.         end,
  89.         top=function ()
  90.             suck=turtle.suckUp
  91.             drop=turtle.dropUp
  92.         end,
  93.         bottom=function ()
  94.             suck=turtle.suckDown
  95.             drop=turtle.dropDown
  96.         end
  97.     }
  98.  
  99.     local target = peripheral.find(peripheralName)
  100.     if target== nil then
  101.         turtle.turnLeft()
  102.         target = peripheral.find(peripheralName)
  103.         if target == nil then
  104.             local errorMessage = {
  105.                 {text="I'm sorry, I cannot find the block id "},
  106.                 {text=peripheralName, color="red"},
  107.                 {text=" at this location. Did you move it, perhaps?"}
  108.             }
  109.  
  110.             for k,v in pairs(automata.points()) do
  111.                 if automa.distanceToPoint(v) == 0 then
  112.                     for _,locMessage in pairs({
  113.                         {"Be sure to update the point named "},
  114.                         {text=v, color="gold"},
  115.                         {text=" when you are able!"}
  116.                     }) do errorMessage[#errorMessage+1] = locMessage
  117.                     break
  118.                     end
  119.                 end
  120.             end
  121.  
  122.             chatBox.sendFormattedMessageToPlayer(
  123.                 textutils.serialiseJSON(errorMessage), ownerIGN, "Crafty"
  124.             )
  125.             return false
  126.         end
  127.     end
  128.     sideTable[peripheral.getName(target)]()
  129.  
  130.     return target
  131. end
  132.  
  133. local responseTable = {
  134.     --Flandre
  135.     ["1784f778-5e6a-4154-9f19-da52687082af"] = {
  136.         "Hello Flan!",
  137.         "Hello Flan! Your wings are looking lovely today!",
  138.         "Hello Flandre! I hope you're having fun!",
  139.         "Hello Flan! How is your factory coming along?",
  140.         "Hello Flan! Sadly, I cannot offer you any blood if you're hungry, but hopefully I can bring you other food soon!"
  141.     },
  142.     --Ruby
  143.     ["ba192da4-c6a0-4815-8114-34ae8526574e"] = {
  144.         "Hello Ruby!",
  145.         "Hello Ruby, how is everything coming along? ^.^",
  146.         "Hello Ruby, I hope your day is going well!",
  147.         "Hello Ruby! Thank you for always offering to help Ivy! She doesn't like feeling reliant on others, but she does appreciate it!"
  148.     },
  149.     --Penny
  150.     ["e7127dc1-70e3-4700-b28a-888be7464f8d"]={
  151.         "Hello Penny!",
  152.         "Hey Penny! Hope your mekanism is coming along well!",
  153.         "Salutations Penny! Hope your mekanism is coming along well!",
  154.         "Hey Penny! As a robot, I absolutely love your farm!",
  155.         "Hello Penny! I hope everything is going well!",
  156.         "Hello Penny! Nice skin!",
  157.         "Salutations Penny! Nice skin!",
  158.         "Nice to see you again, Penny! I hope your reactor is ok. I'm happy to give you supplies if you need them!",
  159.         "Salutations friend Penny!",
  160.         "It is great to see you again, Penny! I am in awe at your factory and growing skills!",
  161.         "Hello again, Penny! Do you think you can teach me how to be as cute as you some day?",
  162.         "Greetings, Friend Penny! Your mekasuit looks so cool!"
  163.     },
  164.     --Noire
  165.     ["356a5e15-289b-4a7c-9373-f1c12209bdcd"]={
  166.         "Hello Noire!",
  167.         "Hello Vivid!",
  168.         "Hello Server-Chan!",
  169.         "Hello Noire! Thank you for running this server for everyone!",
  170.     },
  171.     ["35899282-36fc-4e45-819e-4e3cb14695c8"] = {
  172.         "Hello Chris!",
  173.         "Hello Chris, I hope you and your wives are doing well!"
  174.     },
  175.     general={
  176.         "Hello! ^.^",
  177.         "Hi there!",
  178.         "Greetings!",
  179.         "Nice to see you!",
  180.         "Hello! I'm sorry I don't have specific dialogue for you!",
  181.         "Oh hey!",
  182.         "Wonderful to see you!"
  183.     }
  184. }
  185.  
  186. local acceptedGreetings ={
  187.     "hello crafty",
  188.     "hi crafty",
  189.     "greetings crafty",
  190.     "hello crafty-chan"
  191. }
  192.  
  193. local function warpFuel(location)
  194.     local targetNumber = automata.estimateWarpCost(location) - turtle.getFuelLevel()
  195.     if targetNumber <= 0 then return true end
  196.     local solution={}
  197.  
  198.     for k,v in pairs(fuelList) do
  199.         if targetNumber <= 0 then break end
  200.         for i=16,1,-1 do
  201.             if turtle.getItemDetail(i) ~= nil and k == turtle.getItemDetail(i).name then
  202.                 if turtle.getItemDetail(i).count * v >= targetNumber then
  203.                     solution[#solution+1] = {i,math.ceil(targetNumber/v)}
  204.                     targetNumber=0
  205.                     break
  206.                 else
  207.                     solution[#solution+1] = {i,turtle.getItemDetail(i).count}
  208.                     targetNumber = targetNumber - (turtle.getItemDetail(i).count*v)
  209.                 end
  210.             end
  211.             os.sleep(0)
  212.         end
  213.     end
  214.    
  215.     if targetNumber > 0 then return false
  216.     else
  217.         for k,v in pairs(solution) do
  218.             turtle.select(v[1])
  219.             turtle.refuel(v[2])
  220.             os.sleep(0)
  221.         end
  222.         return true
  223.     end
  224. end
  225.  
  226. local function deposit(itemIndex)
  227.     local inDrawers=false
  228.     for _,v2 in pairs(storageModems.drawers.list()) do
  229.         if v2.name == turtle.getItemDetail(itemIndex).name then
  230.             storageModems.drawers.pullItems(turtleStorageName,itemIndex)
  231.             inDrawers=true
  232.         break
  233.         end
  234.     end
  235.  
  236.     if not inDrawers then storageModems.mainStorage.pullItems(turtleStorageName,itemIndex) end
  237. end
  238.  
  239. local function emptyCheck(id)
  240.     local tempSlot
  241.     for i=1,16 do
  242.         if turtle.getItemDetail(i) == nil then
  243.             if tempSlot==nil then tempSlot=i end
  244.         elseif id ~= nil and turtle.getItemDetail(i).name == id and turtle.getItemDetail(i).count < turtle.getItemDetail(i,true).maxCount then
  245.             return i
  246.         end
  247.     end
  248.  
  249.     return tempSlot
  250. end
  251.  
  252. local function withdrawMats(materials, amount)
  253.     if type(materials) =="string" then materials={[materials]=true} end
  254.  
  255.     --print("withdrawing")
  256.     for k,v in pairs(materials) do print(k) end
  257.     local startingMats={}
  258.     for _,modem in pairs(storageModems) do
  259.         for slot,item in pairs(modem.list()) do
  260.             if materials[item.name] then
  261.                 --print(modem,slot,item.count)
  262.                 startingMats[#startingMats+1] = {modem,slot,item.count,item.name}
  263.             end
  264.         end
  265.     end
  266.  
  267.  
  268.    
  269.     --sort the results
  270.     --I'll just use insertion sort for now
  271.     if #startingMats > 1 then
  272.         for i=2,#startingMats do
  273.             local key = i
  274.             while key > 1 and (startingMats[key-1][3] < startingMats[key][3]) do
  275.                
  276.                 local sortTemp = startingMats[key-1]
  277.                 startingMats[key-1] = startingMats[key]
  278.                 startingMats[key]=sortTemp
  279.                 key=key-1
  280.             end
  281.         end
  282.     end
  283.  
  284.     print("-----")
  285.     for k,v in pairs(startingMats) do print(k) end
  286.  
  287.     --withdraw the item
  288.     local targetNumber = amount
  289.     for i=1,#startingMats do
  290.         if targetNumber<= 0 then break end
  291.        
  292.         --print("amount:", amount)
  293.         --print("targetNumber:", targetNumber)
  294.         --print(startingMats[i][3])
  295.         local detail = startingMats[i][1].getItemDetail(startingMats[i][2])
  296.         while (detail ~= nil and detail.count > 0) and targetNumber>0 do
  297.             local moved = startingMats[i][1].pushItems(turtleStorageName,startingMats[i][2],targetNumber, emptyCheck(startingMats[i][4]))
  298.             targetNumber = targetNumber-moved
  299.         end
  300.     end
  301. end
  302.  
  303.  
  304.  
  305.  
  306. local function refuelFromStorage(targetNum)
  307.     local targetNumber = targetNum - turtle.getFuelLevel()
  308.     local solution={}
  309.     for fuel,fuelVal in pairs(fuelList) do
  310.         if targetNumber <= 0 then break end
  311.         for _,modem in pairs(storageModems) do
  312.             if targetNumber <= 0 then break end
  313.             for slot,item in pairs(modem.list()) do
  314.                
  315.                 if item.name == fuel then
  316.                     if item.count*fuelVal >= targetNumber then
  317.                         targetNumber=0
  318.                         solution[#solution+1] = {modem,slot, math.ceil(targetNumber/fuelVal)}
  319.                         break
  320.                     else
  321.                         targetNumber=targetNumber-(item.count*fuelVal)
  322.                         solution[#solution+1] = {modem,slot, item.count}
  323.                     end
  324.                 end
  325.                 os.sleep(0)
  326.             end
  327.         end
  328.     end
  329.  
  330.     if targetNumber<=0 then
  331.         local fuelSlot
  332.         for i=16,1,-1 do
  333.             if turtle.getItemDetail(i) == nil then turtle.select(i)
  334.             break end
  335.         end
  336.  
  337.         for _,v in pairs(solution) do
  338.             v[1].pushItems(turtleStorageName,v[2],v[3], fuelSlot)
  339.             turtle.refuel()
  340.             os.sleep(0)
  341.         end
  342.         return true
  343.     else
  344.         return false
  345.     end
  346. end
  347.  
  348. local function makeItem(details, target)
  349.     local materials,results,input,output
  350.  
  351.     if details.material ~= nil then materials={[details.material]=true}
  352.     elseif type(details.materials) =="string" then materials={[details.materials]=true}
  353.     elseif details.materials ~= nil then materials = details.materials
  354.     elseif type(details[1])== "string" then materials={[details[1]]=true} else materials=details[1]
  355.     end
  356.    
  357.     if details.result ~= nil then results={[details.result]=true}
  358.     elseif type(details.results) =="string" then results={[details.results]=true}
  359.     elseif details.results ~= nil then results = details.results
  360.     elseif type(details[2])== "string" then results={[details[2]]=true} else results=details[2]
  361.     end
  362.  
  363.     if details.input ~= nil then input = details.input else input = 1 end
  364.     if details.output ~= nil then output = details.output else output = target.size() end
  365.     local matSlots = {}
  366.     for i=1,16 do
  367.         if turtle.getItemDetail(i) ~= nil and
  368.         (materials[turtle.getItemDetail(i).name])
  369.         then
  370.             matSlots[#matSlots+1] = i
  371.         end
  372.     end
  373.    
  374.     local resultCell=0
  375.     local function emptyCheck()
  376.         for i=1,16 do
  377.             if turtle.getItemDetail(i) == nil then
  378.                 if resultCell == 0 then resultCell=i end
  379.             elseif (results[turtle.getItemDetail(i).name] and turtle.getItemDetail(i).count < turtle.getItemDetail(i,true).maxCount) then
  380.                 resultCell=i
  381.                 break
  382.             end
  383.         end
  384.     end
  385.     local pushSafe= (output==1)
  386.  
  387.     for _,v in pairs(matSlots) do
  388.         emptyCheck()
  389.         turtle.select(v)
  390.        
  391.         while not stopped do
  392.             while paused do if stopped then return end os.sleep(0) end
  393.             if output~=1 then pushSafe = (target.getItemDetail(1)==nil) end
  394.             if target.getItemDetail(output) ~= nil and pushSafe and not materials[target.getItemDetail(1).name] then
  395.                 turtle.select(resultCell)
  396.  
  397.                 target.pushItems(peripheral.getName(target),output,nil,1)
  398.                 suck()
  399.                 local itemDetail = turtle.getItemDetail(resultCell,true)
  400.                 if not results[itemDetail.name] or itemDetail.count==itemDetail.maxCount then emptyCheck() end
  401.                 turtle.select(v)
  402.             end
  403.            
  404.             if target.getItemDetail(input) == nil and target.getItemDetail(1) == nil then
  405.                 local check = turtle.getItemDetail(v)
  406.                 if check ~= nil and materials[check.name] then
  407.                     drop()
  408.                     if input~= 1 then target.pushItems(peripheral.getName(target),1,nil,input) end
  409.                 else break
  410.                 end
  411.             end
  412.             os.sleep(0)
  413.         end
  414.     end
  415. end
  416.  
  417. local function warp(location, forced)
  418.     if automata.distanceToPoint(location) == 0 then if location==mainPoint then storageSync() end  return true end
  419.  
  420.     local function tryWarp(destination)
  421.         local success = automata.warpToPoint(destination)
  422.  
  423.         if not success then
  424.             local nearestPoint
  425.  
  426.             for _,v in pairs(automata.points()) do
  427.                 if nearestPoint == nil or automata.distanceToPoint(v)<automata.distanceToPoint(nearestPoint) then nearestPoint=v end
  428.             end
  429.             chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
  430.                 {text="I'm sorry, but something went wrong when trying to warp! I'm closest to "},
  431.                 {text=nearestPoint,color="gold"},
  432.                 {", though. Please come pick me up!"}
  433.             }), ownerIGN, "Crafty")
  434.             os.sleep(0)
  435.             return false
  436.         else
  437.             if destination==mainPoint then storageSync() end
  438.         return true
  439.         end
  440.     end
  441.  
  442.     if stopped and not forced then return false end
  443.     while paused and not forced do if stopped then return false end os.sleep(0) end
  444.  
  445.     if automata.estimateWarpCost(location) >= turtle.getFuelLevel() or warpFuel(location) then
  446.         return tryWarp(location)
  447.     elseif automata.estimateWarpCost(mainPoint) >= turtle.getFuelLevel()  or warpFuel(mainPoint) then
  448.         chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
  449.             {text="Have to refuel before I can get to "},
  450.             {text=location,color="gold"},
  451.             {text=", but I'll be right there!"}
  452.         }),ownerIGN, "Crafty")
  453.         if not tryWarp(mainPoint) then
  454.             return false
  455.         end
  456.        
  457.         if refuelFromStorage(automata.estimateWarpCost(location)) then
  458.             if refuelFromStorage(automata.estimateWarpCost(location)*2)then
  459.                 chatBox.sendMessageToPlayer("Alright, all fueled up and ready to go!", ownerIGN, "Crafty")
  460.             else
  461.                 chatBox.sendMessageToPlayer("We don't have enough fuel for a return trip. Should I make the jump?", ownerIGN, "Crafty")
  462.                 local jumping = true
  463.  
  464.                 parallel.waitForAny(
  465.                     function()
  466.                         while true do
  467.                             local _, username, message, uuid, isHidden = os.pullEvent("chat")
  468.  
  469.                             if isHidden and uuid == "58b2110a-ceb4-4781-9359-1a764ac57edc" then
  470.                                 lowerString = string.lower(message)
  471.                                 if lowerString:find("deny") == 1 or lowerString:find("crafty deny") == 1
  472.                                 or lowerString:find("no") == 1 or lowerString:find("crafty no") == 1
  473.                                 or lowerString:find("cancel") == 1 then
  474.  
  475.                                     jumping = false
  476.                                     chatBox.sendMessageToPlayer("Alright, I'll stay at the base!", ownerIGN, "Crafty")
  477.                                     break
  478.                                 elseif message:find("confirm") or message:find("yes") then
  479.                                     chatBox.sendMessageToPlayer("Ok, warping now!", ownerIGN, "Crafty")
  480.                                     break
  481.                                 end
  482.                             end
  483.                         end
  484.                     end,
  485.                     function ()
  486.                         os.sleep(60)
  487.                         chatBox.sendMessageToPlayer("I didn't get a response, should I warp?", ownerIGN, "Crafty")
  488.                         os.sleep(60)
  489.                         chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
  490.                             {text="I'm going to warp now, but I'll be over by "},
  491.                             {text=location,color="gold"},
  492.                             {text=" so you can pick me up there."}
  493.                         }), ownerIGN, "Crafty")
  494.                     end
  495.                 )
  496.  
  497.                 if jumping then return tryWarp(location) end
  498.             end
  499.            
  500.         else
  501.             chatBox.sendMessageToPlayer("I'm sorry, we don't have enough fuel to make it to the crafting station! Please bring more and try again.", ownerIGN, "Crafty")
  502.             return false
  503.         end
  504.     else
  505.         local nearestPoint
  506.  
  507.         for _,v in pairs(automata.points()) do
  508.             if nearestPoint == nil or automata.distanceToPoint(v)<automata.distanceToPoint(nearestPoint) then nearestPoint=v end
  509.         end
  510.  
  511.         chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON({
  512.             {text="I'm sorry, but I can't warp right now! I don't have enough fuel! I'm closest to "},
  513.             {text=nearestPoint,color="gold"},
  514.             {", though. Please come pick me up, or at least refuel me."}
  515.         }), ownerIGN, "Crafty")
  516.         return false
  517.     end
  518. end
  519.  
  520.  
  521. local function simpleProcessMats(args)
  522.     if args[4] ~= nil and args[4]:lower()=="true" and not altReturn then
  523.         altReturn=true
  524.         automata.savePoint("tempHome")
  525.     end
  526.  
  527.     --go to supply area
  528.     if not warp(mainPoint) then return end
  529.  
  530.     local amount
  531.     if tonumber(args[3]) ~= nil then amount = tonumber(args[3]) else amount = 64 end
  532.     local details = programTable[args[2]]
  533.    
  534.  
  535.     --Withdraw materials
  536.    
  537.     withdrawMats(details.materials,amount)
  538.  
  539.     -- go to area
  540.     if not warp(details.location) then return end
  541.  
  542.     --find device
  543.     local target = sideSearch(details.target)
  544.     if not target then
  545.         if warp(mainPoint) then
  546.             for i=1,16 do
  547.                 if details.results[turtle.getItemDetail(i).name] then
  548.                     deposit(i)
  549.                 end
  550.             end
  551.         end
  552.  
  553.         if altReturn then warp("tempHome") end
  554.         return
  555.     end
  556.  
  557.     --start creating items
  558.     makeItem(details,target)
  559.  
  560.     --return and deposit items, or if argument 4 is true, return to tempHome
  561.     if (not altReturn) and warp(mainPoint) then
  562.         for i=1,16 do
  563.             if turtle.getItemDetail(i) ~= nil and details.results[turtle.getItemDetail(i).name] then
  564.                 deposit(i)
  565.             end
  566.         end
  567.         warp(mainPoint)
  568.     else
  569.         warp("tempHome")
  570.     end
  571.  
  572.  
  573. end
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580. local function makeEssence(args)
  581.     local essenceList = {
  582.         fire = "ars_nouveau:fire_essence",
  583.         manipulation="ars_nouveau:manipulation_essence",
  584.         manip="ars_nouveau:manipulation_essence",
  585.         conjuration="ars_nouveau:conjuration_essence",
  586.         conjure="ars_nouveau:conjuration_essence",
  587.         abjuration="ars_nouveau:abjuration_essence",
  588.         abjure="ars_nouveau:abjuration_essence",
  589.         water="ars_nouveau:water_essence",
  590.         air="ars_nouveau:air_essence",
  591.         earth="ars_nouveau:earth_essence",
  592.         anima="ars_nouveau:anima_essence"
  593.     }
  594.  
  595.     local essence=nil
  596.     if args[3] ~= nil then
  597.         if essenceList[args[3]] ~= nil then essence = essenceList[args[3]]
  598.         else
  599.             for k,v in pairs(essenceList) do
  600.                 if args[3] == v then essence = v end
  601.             end
  602.         end
  603.     end
  604.    
  605.     if essence == nil then
  606.         chatBox.sendMessageToPlayer("I'm sorry, Ivy! I don't know what essence that is! As a reminder, the format is $crafty essence <essence type> <optional amount> <alternate return (true or false)>", ownerIGN, "Crafty")
  607.     else
  608.         if args[5] ~= nil and args[5]:lower()=="true" and not altReturn then
  609.             altReturn=true
  610.             automata.savePoint("tempHome")
  611.         end
  612.  
  613.         --withdraw gems
  614.         if not warp(mainPoint) then return end
  615.         local amount=64
  616.         if tonumber(args[4]) ~= nil then amount = tonumber(args[4]) end
  617.  
  618.         withdrawMats("ars_nouveau:source_gem",amount)
  619.  
  620.  
  621.         --prepare pedestals
  622.         if not warp("essenceMats") then return end
  623.         local pedestals={}
  624.         for i=0,2 do pedestals[#pedestals+1] = peripheral.wrap("ars_nouveau:arcane_pedestal_"..tostring(i)) end
  625.         local chest=peripheral.wrap("sophisticatedstorage:chest_0")
  626.  
  627.         local pedestalRecipes = {
  628.             --Insert desired results here
  629.             ["ars_nouveau:abjuration_essence"] = {
  630.                 "minecraft:fermented_spider_eye",
  631.                 "minecraft:sugar",
  632.                 "minecraft:milk_bucket"
  633.             },
  634.             ["ars_nouveau:conjuration_essence"] = {
  635.                 "ars_nouveau:wilden_horn",
  636.                 "ars_nouveau:starbuncle_shards",
  637.                 "minecraft:book"
  638.             },
  639.             ["ars_nouveau:water_essence"] = {
  640.                 "minecraft:water_bucket",
  641.                 "minecraft:kelp",
  642.                 "minecraft:snow_block"
  643.             },
  644.             ["ars_nouveau:air_essence"] = {
  645.                 "minecraft:feather",
  646.                 "minecraft:arrow",
  647.                 "ars_nouveau:wilden_wing",
  648.             },
  649.             ["ars_nouveau:earth_essence"] = {
  650.                 "minecraft:iron_ingot",
  651.                 "minecraft:dirt",
  652.                 "minecraft:wheat_seeds"
  653.             },
  654.             ["ars_nouveau:fire_essence"] = {
  655.                 "minecraft:torch",
  656.                 "minecraft:gunpowder",
  657.                 "minecraft:flint_and_steel"
  658.             },
  659.             ["ars_nouveau:manipulation_essence"] = {
  660.                 "minecraft:stone_button",
  661.                 "minecraft:clock",
  662.                 "minecraft:redstone"
  663.             },
  664.             ["ars_elemental:anima_essence"] = {
  665.                 "minecraft:wither_skeleton_skull",
  666.                 "minecraft:bone_meal",
  667.                 "minecraft:golden_apple"
  668.             }
  669.         }
  670.  
  671.         for i=1,3 do
  672.             if pedestals[i].getItemDetail(1) == nil or pedestals[i].getItemDetail(1).name ~= pedestalRecipes[essence][i] then
  673.                 pedestals[i].pushItems("sophisticatedstorage:chest_0", 1)
  674.  
  675.                 for k,v in pairs(chest.list()) do
  676.                     if v.name == pedestalRecipes[essence][i] then
  677.                         pedestals[i].pullItems("sophisticatedstorage:chest_0",k)
  678.                         break
  679.                     end
  680.                 end
  681.             end
  682.  
  683.             local failed = false
  684.             if pedestals[i].getItemDetail(1) == nil then
  685.                 chatBox.sendMessageToPlayer("I'm sorry, but I couldn't find an item by the id of "..pedestalRecipes[essence],ownerIGN,"Crafty")
  686.                 failed=true
  687.             elseif pedestals[i].getItemDetail(1).name ~= pedestalRecipes[essence][i] then
  688.                 chatBox.sendMessageToPlayer("I'm sorry, but something went wrong and I couldn't replace the essence material on pedestal".. tostring(i),ownerIGN,"Crafty")
  689.                 failed=true
  690.             end
  691.  
  692.             if failed then
  693.                 if not altReturn and warp(mainPoint) then
  694.                     for i2=1,16 do
  695.                         if turtle.getItemDetail(i2) ~= nil and turtle.getItemDetail(i2).name == "ars_nouveau:source_gem" then deposit(i2) end
  696.                     end
  697.                 elseif altReturn then warp("tempHome")
  698.                 end
  699.                 return
  700.             end
  701.         end
  702.  
  703.  
  704.         if not warp("imbuer") then return end
  705.         local imbuer = sideSearch("ars_nouveau:imbuement_chamber")
  706.         makeItem({material="ars_nouveau:source_gem",result=essence},imbuer)
  707.         if not warp("essenceMats") then return end
  708.         for i=1,3 do
  709.             pedestals[i].pushItems("sophisticatedstorage:chest_0", 1)
  710.         end
  711.  
  712.         if (not altReturn) and warp(mainPoint) then
  713.             for i=1,16 do
  714.                 if turtle.getItemDetail(i) ~= nil and turtle.getItemDetail(i).name == essence then
  715.                     deposit(i)
  716.                 end
  717.             end
  718.             warp(mainPoint)
  719.         else
  720.             warp("tempHome")
  721.         end
  722.     end
  723. end
  724.  
  725. programTable = {
  726.     sourceGems={
  727.         target="ars_nouveau:imbuement_chamber",
  728.         materials = {
  729.             --insert valid ingredients here
  730.             ["minecraft:amethyst_shard"]=true,
  731.             ["minecraft:lapis_lazuli"]=true
  732.         },
  733.         results = {
  734.             --Insert desired results here
  735.             ["ars_nouveau:source_gem"] = true
  736.         },
  737.         location="imbuer"
  738.     },
  739.     fleshAuto = {
  740.         target="integrateddynamics:drying_basin",
  741.         materials = {
  742.             --insert valid ingredients here
  743.             ["minecraft:rotten_flesh"]=true
  744.         },
  745.         results = {
  746.             ["minecraft:leather"]=true
  747.         },
  748.         location="basin"
  749.     },
  750.     essence={func=makeEssence,acceptArgs=true},
  751.     sort={func=function ()
  752.         if not warp(mainPoint,true) then return end
  753.  
  754.         storageSync()
  755.  
  756.         local apotheosis = peripheral.wrap("sophisticatedstorage:controller_1")
  757.         local ironsSpells = peripheral.wrap("entangled:tile_1")
  758.  
  759.         --First create a list for drawers to check names against
  760.         local drawerList = {}
  761.         for k,v in pairs(storageModems.drawers.list()) do
  762.             drawerList[v.name] = k
  763.         end
  764.  
  765.         --next sort the main chests, also storing a list
  766.         local chestList = {}
  767.         for k,v in pairs(storageModems.mainStorage.list()) do
  768.             while paused do sleep(0) end
  769.             if stopped then
  770.                 chatBox.sendMessageToPlayer("Sorry, I had to stop sorting early!",ownerIGN,"Crafty")
  771.                 return end
  772.             if drawerList[v.name] ~= nil then
  773.                 local sortAmount = v.count
  774.                 while sortAmount > 0 do
  775.                     local sentItems = storageModems.mainStorage.pushItems(storageNames.drawers, k, nil, drawerList[v.name])
  776.                     sortAmount = sortAmount-sentItems
  777.                     if sentItems==0 then break end
  778.                 end
  779.                
  780.             elseif v.name:find("irons_spellbooks:") ~= nil then
  781.                
  782.                 local sortAmount = v.count
  783.                 while sortAmount > 0 do
  784.                     local sentItems = ironsSpells.pullItems(storageNames.mainStorage,k)
  785.                     sortAmount = sortAmount-sentItems
  786.                     if sentItems==0 then break end
  787.                 end
  788.             elseif v.name:find("apotheosis:") ~= nil then
  789.                 local sortAmount = v.count
  790.                 while sortAmount > 0 do
  791.                     local sentItems = apotheosis.pullItems(storageNames.mainStorage,k)
  792.                     sortAmount = sortAmount-sentItems
  793.                     if sentItems==0 then break end
  794.                 end
  795.                
  796.             elseif chestList[v.name] ~= nil then
  797.                 local sortAmount = v.count
  798.                 while sortAmount > 0 do
  799.                     local sentItems = storageModems.mainStorage.pushItems(storageNames.mainStorage,k,nil,chestList[v.name])
  800.                     sortAmount = sortAmount-sentItems
  801.                     if sentItems==0 then break end
  802.                 end
  803.             else chestList[v.name] = k
  804.             end
  805.             -- os.sleep(0)
  806.         end
  807.  
  808.         --sort other things back into chests and drawers
  809.         for k,v in pairs(ironsSpells.list()) do
  810.             while paused do sleep(0) end
  811.             if stopped then
  812.                 chatBox.sendMessageToPlayer("Sorry, I had to stop sorting early!",ownerIGN,"Crafty")
  813.                 return end
  814.             if drawerList[v.name] ~= nil then
  815.                
  816.                 local sortAmount = v.count
  817.                 while sortAmount > 0 do
  818.                     local sentItems = ironsSpells.pushItems(storageNames.drawers,k,nil,drawerList[v.name])
  819.                     sortAmount = sortAmount-sentItems
  820.                     if sentItems==0 then break end
  821.                 end
  822.             elseif chestList[v.name] ~= nil and (v.name:find("irons_spellbooks:") == nil) then
  823.                
  824.                 local sortAmount = v.count
  825.                 while sortAmount > 0 do
  826.                     local sentItems = ironsSpells.pushItems(storageNames.mainStorage,k,nil,chestList[v.name])
  827.                     sortAmount = sortAmount-sentItems
  828.                     if sentItems==0 then break end
  829.                 end
  830.             end
  831.         end
  832.        
  833.         for k,v in pairs(apotheosis.list()) do
  834.             while paused do sleep(0) end
  835.             if stopped then
  836.                 chatBox.sendMessageToPlayer("Sorry, I had to stop sorting early!",ownerIGN,"Crafty")
  837.                 return end
  838.             if drawerList[v.name] ~= nil then
  839.                 local sortAmount = v.count
  840.                 while sortAmount > 0 do
  841.                     local sentItems = apotheosis.pushItems(storageNames.drawers,k,nil,drawerList[v.name])
  842.                     sortAmount = sortAmount-sentItems
  843.                     if sentItems==0 then break end
  844.                 end
  845.             end
  846.         end
  847.         chatBox.sendMessageToPlayer("I have finished sorting!",ownerIGN,"Crafty")
  848.     end},
  849.     update = {
  850.         func=function ()
  851.             chatBox.sendMessageToPlayer("Alright, updating now!",ownerIGN,"Crafty")
  852.             if shell.run("pastebin get ZQbBNLkB tempCrafty") then
  853.                 shell.run("rm crafty")
  854.                 shell.run("rename tempCrafty crafty")
  855.                 chatBox.sendMessageToPlayer("Restarting now, see you soon!", ownerIGN, "Crafty")
  856.                 os.reboot()
  857.             else
  858.                 return false
  859.             end
  860.         end
  861.     },
  862.  
  863.     --Powah Energizing
  864.     energize={
  865.         func=function(args)
  866.             local recipeList = {
  867.                 hardened = {
  868.                     id="powah:steel_energized",
  869.                     "minecraft:iron_ingot",
  870.                     "minecraft:gold_ingot"
  871.                 },
  872.                 blazing={
  873.                     id="powah:crystal_blazing",
  874.                     "minecraft:blaze_powder",
  875.                     "minecraft:blaze_powder",
  876.                     "minecraft:blaze_powder",
  877.                     "minecraft:blaze_powder",
  878.                     altRecipe={
  879.                         "minecraft:blaze_rod",
  880.                     }
  881.                 },
  882.                 niotic={
  883.                     id="powah:crystal_niotic",
  884.                     "minecraft:diamond"
  885.                 },
  886.                 spirited={
  887.                     id="powah:crystal_spirited",
  888.                     "minecraft:emerald"
  889.                 },
  890.                 nitro={
  891.                     id="powah:crystal_nitro",
  892.                     "minecraft:nether_star",
  893.                     "minecraft:redstone_block",
  894.                     "minecraft:redstone_block",
  895.                     "powah:blazing_crystal_block",
  896.                 }
  897.             }
  898.  
  899.             recipeList.esteel=recipeList.hardened
  900.             recipeList.energized=recipeList.hardened
  901.        
  902.             local result=nil
  903.             if args[3] ~= nil then
  904.                 if recipeList[args[3]] ~= nil then result = recipeList[args[3]]
  905.                 else
  906.                     for k,v in pairs(recipeList) do
  907.                         if args[3] == v.id then result = v
  908.                         end
  909.                     end
  910.                 end
  911.             end
  912.            
  913.             if result == nil then
  914.                 chatBox.sendMessageToPlayer("I'm sorry, Ivy! I don't know what that is! As a reminder, the format is $crafty energize <powah material> <optional amount> <alternate return (true or false)>",ownerIGN,"Crafty")
  915.             else
  916.                 local amount
  917.                 if tonumber(args[4]) ~= nil then amount=tonumber(args[4]) else amount = 64 end
  918.                 if args[5] ~= nil and args[5]:lower()=="true" and not altReturn then
  919.                     altReturn=true
  920.                     automata.savePoint("tempHome")
  921.                 end
  922.  
  923.                 if not warp(mainPoint) then return false end
  924.  
  925.                 local itemTable={}
  926.                 local withdrawTable = {}
  927.                 for i=1,#result do
  928.                     if itemTable[result[i]] == nil then itemTable[result[i]]=true end
  929.                     if withdrawTable[result[i]] == nil then withdrawTable[result[i]] = amount else withdrawTable[result[i]] = withdrawTable[result[i]]+amount end
  930.                 end
  931.  
  932.                 for k,v in pairs(withdrawTable) do withdrawMats(k,v) end
  933.  
  934.  
  935.                 if not warp("energizer") then
  936.                     for i=1,16 do
  937.                         if itemTable[turtle.getItemDetail(i).name] then
  938.                             deposit(i)
  939.                         end
  940.                         return false
  941.                     end
  942.                 end
  943.  
  944.                 local energizer=peripheral.find("powah:energizing_orb")
  945.  
  946.                 local matSlots = {}
  947.  
  948.                 local blipTest=false
  949.                 while not stopped do
  950.                     while paused do if stopped then return end os.sleep(0) end
  951.  
  952.  
  953.                     if energizer.getItemDetail(1) ~= nil then
  954.                         energizer.pushItems("turtle_6",1,nil,emptyCheck(energizer.getItemDetail(1).name))
  955.                     end
  956.                    
  957.                     for i=1,#result do
  958.                         if matSlots[i] == nil or turtle.getItemDetail(matSlots[i]) == nil or turtle.getItemDetail(matSlots[i]).name ~= result[i] then
  959.                             for i2=1,16 do
  960.                                 if turtle.getItemDetail(i2)~=nil and turtle.getItemDetail(i2).name == result[i] then matSlots[i]=i2 end
  961.                             end
  962.                         end
  963.                        
  964.                         local itemDetails = energizer.getItemDetail(i+1)
  965.                         if itemDetails ~= nil and itemDetails.name ~= result[i] then
  966.                             energizer.pushItems("turtle_6",i+1,nil,emptyCheck(energizer.getItemDetail(i+1).name))
  967.                         end
  968.                        
  969.                         itemDetails=energizer.getItemDetail(i+1)
  970.                         if itemDetails == nil and turtle.getItemDetail(matSlots[i])~= nil and turtle.getItemDetail(matSlots[i]).name == result[i] then
  971.                             energizer.pullItems("turtle_6",matSlots[i],nil,i+1)
  972.                         end
  973.                     end
  974.  
  975.  
  976.                     local continue=false
  977.                     for i=1,energizer.size() do
  978.                         if energizer.getItemDetail(i)~= nil then
  979.                             continue=true
  980.                         end
  981.                     end
  982.  
  983.                     if not continue then
  984.                         if blipTest==false then blipTest=true
  985.                         else break end
  986.                     end
  987.                 end
  988.  
  989.                 if (not altReturn) and warp(mainPoint) then
  990.                     for i=1,16 do
  991.                         if turtle.getItemDetail(i) ~= nil and (turtle.getItemDetail(i).name == result.id or itemTable[turtle.getItemDetail(i).name]) then
  992.                             deposit(i)
  993.                         end
  994.                     end
  995.                     warp(mainPoint)
  996.                 else
  997.                     warp("tempHome")
  998.                 end
  999.             end
  1000.         end,
  1001.         acceptArgs=true
  1002.     }
  1003. }
  1004.  
  1005.  
  1006. local simpleCommands
  1007. simpleCommands = {
  1008.     echo=function (message, args)
  1009.         local sayThis = message:gsub(args[1].." "..args[2].." ","")
  1010.         chatBox.sendMessageToPlayer(sayThis, ownerIGN, "Crafty")
  1011.     end,
  1012.     say=function (message, args)
  1013.         local sayThis = message:gsub(args[1].." "..args[2].." ","")
  1014.         chatBox.sendMessage(sayThis, "Crafty")
  1015.     end,
  1016.     sayrange=function (message, args)
  1017.         local sayThis = message:gsub(args[1].." "..args[2].." "..args[3].." ","")
  1018.         local range = tonumber(args[3])
  1019.         chatBox.sendMessage(sayThis, "Crafty",nil,nil, range)
  1020.     end,
  1021.     save=function (message, args)
  1022.         local saveThis = message:gsub(args[1].." "..args[2].." ","")
  1023.         automata.savePoint(saveThis)
  1024.     end,
  1025.     warp=function (message, args)
  1026.         local warpPoint = message:gsub(args[1].." "..args[2].." ","")
  1027.         for _,v in pairs(automata.points()) do
  1028.            if warpPoint:lower() == v:lower() then warp(v,true) end
  1029.         end
  1030.     end,
  1031.     stop=function ()
  1032.         if working then
  1033.             local tempLoc
  1034.             for _,v in pairs(automata.points()) do
  1035.                 if automata.distanceToPoint(v) == 0 then tempLoc = v end
  1036.             end
  1037.  
  1038.             if tempLoc==nil then
  1039.                 automata.savePoint("pauseLoc")
  1040.                 tempLoc="tempLoc"
  1041.             end
  1042.  
  1043.             pauseLoc=tempLoc
  1044.         end
  1045.         paused=true stopped=true
  1046.     end,
  1047.     pause=function ()
  1048.         if working and not paused then
  1049.             local tempLoc
  1050.             for _,v in pairs(automata.points()) do
  1051.                 if automata.distanceToPoint(v) == 0 then tempLoc = v end
  1052.             end
  1053.  
  1054.             if tempLoc==nil then
  1055.                 automata.savePoint("pauseLoc")
  1056.                 tempLoc="tempLoc"
  1057.             end
  1058.  
  1059.             pauseLoc=tempLoc
  1060.         end
  1061.  
  1062.         paused=true
  1063.     end,
  1064.     skip = function ()
  1065.         stopped=true
  1066.     end,
  1067.     clear = function ()
  1068.         clearQueue=true
  1069.         queue={}
  1070.     end,
  1071.     resume=function ()
  1072.         if pauseLoc ~= nil then warp(pauseLoc, true) end
  1073.         paused=false
  1074.     end,
  1075.     fuel=function (_, args)
  1076.         local reply = {
  1077.             {text="I currently have "},
  1078.             {text=tostring(turtle.getFuelLevel()), color="gold"},
  1079.             {text=" fuel remaining."}
  1080.         }
  1081.         if args[3] ~= nil then
  1082.             for _,v in pairs(automata.points()) do
  1083.                 if args[3]:lower() == v:lower() then
  1084.                     reply[#reply+1] = {text=" Getting to "..v.." will take "}
  1085.                     reply[#reply+1] = {text=tostring(automata.estimateWarpCost(v)), color="gold"}
  1086.                     reply[#reply+1] = {text=" fuel."}
  1087.                 end
  1088.             end
  1089.         end
  1090.  
  1091.         chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(reply), ownerIGN, "Crafty")
  1092.     end,
  1093.     points=function ()
  1094.         local reply = {
  1095.             {text="I have memorized the following points: "},
  1096.         }
  1097.  
  1098.         for _,v in pairs(automata.points()) do
  1099.             reply[#reply+1] = {text="\n"..v, color="gold"}
  1100.         end
  1101.         chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(reply), ownerIGN, "Crafty")
  1102.     end,
  1103.     move=function(_,args)
  1104.         moveTable={
  1105.             forward=turtle.forward,
  1106.             back=turtle.back,
  1107.             left=turtle.turnLeft,
  1108.             right=turtle.turnRight,
  1109.             up=turtle.up,
  1110.             down=turtle.down,
  1111.             scan=function()
  1112.                 local scannedBlock, scanned = turtle.inspect()
  1113.                 local scanText
  1114.                 if not scannedBlock then scanText={{text="There is nothing there!"}}
  1115.                 else
  1116.                     scanText={{text="I currently see: "}}
  1117.                     scanText[#scanText+1] = {text=scanned.name,hoverEvent={
  1118.                         action="show_item",
  1119.                         contents={id=scanned.name}
  1120.                     }}
  1121.                 end
  1122.                 chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(scanText),ownerIGN,"Crafty")
  1123.             end,
  1124.             scanup=function()
  1125.                 local scannedBlock, scanned = turtle.inspectUp()
  1126.                 local scanText
  1127.                 if not scannedBlock then scanText={{text="There is nothing there!"}}
  1128.                 else
  1129.                     scanText={{text="I currently see: "}}
  1130.                     scanText[#scanText+1] = {text=scanned.name,hoverEvent={
  1131.                         action="show_item",
  1132.                         contents={id=scanned.name}
  1133.                     }}
  1134.                 end
  1135.                 chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(scanText),ownerIGN,"Crafty")
  1136.             end,
  1137.             scandown=function()
  1138.                 local scannedBlock, scanned = turtle.inspectDown()
  1139.                 local scanText
  1140.                 if not scannedBlock then scanText={{text="There is nothing there!"}}
  1141.                 else
  1142.                     scanText={{text="I currently see: "}}
  1143.                     scanText[#scanText+1] = {text=scanned.name,hoverEvent={
  1144.                         action="show_item",
  1145.                         contents={id=scanned.name}
  1146.                     }}
  1147.                 end
  1148.                 chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(scanText),ownerIGN,"Crafty")
  1149.             end
  1150.             }
  1151.         for i=3,#args do
  1152.             if moveTable[args[i]] then moveTable[args[i]]() end
  1153.         end
  1154.     end,
  1155.     invcheck=function ()
  1156.         local invText = {{text="My inventory currently is:\n"}}
  1157.         for i=1,16 do
  1158.             local invSlotString ={
  1159.                 text="["..tostring(i).."]"
  1160.             }
  1161.  
  1162.             if turtle.getItemDetail(i) ~= nil then
  1163.                 invSlotString.hoverEvent={
  1164.                     action="show_item",
  1165.                     contents={}
  1166.                 }
  1167.                 invSlotString.bold=true
  1168.                 invSlotString.hoverEvent.contents.id=turtle.getItemDetail(i).name
  1169.             end
  1170.  
  1171.             if i%4 == 0 then invSlotString.text = invSlotString.text.."\n"
  1172.             else invSlotString.text=invSlotString.text.." " end
  1173.  
  1174.             invText[#invText+1] = invSlotString
  1175.         end
  1176.  
  1177.         chatBox.sendFormattedMessageToPlayer(textutils.serialiseJSON(invText),ownerIGN,"Crafty")
  1178.     end,
  1179.     select=function (_,args)
  1180.         if tonumber(args[3])~= nil then turtle.select() end
  1181.     end
  1182. }
  1183. --aliases
  1184. simpleCommands["warpto"] = simpleCommands.warp
  1185. simpleCommands.clearqueue = simpleCommands.clear
  1186.  
  1187.  
  1188.  
  1189. --MAIN BRAINS
  1190. parallel.waitForAny(
  1191.     function()
  1192.     local username, message, uuid, isHidden
  1193.    
  1194.     while true do
  1195.         _, username, message, uuid, isHidden = os.pullEvent("chat")
  1196.        
  1197.         if isHidden and uuid == "58b2110a-ceb4-4781-9359-1a764ac57edc" then
  1198.            
  1199.             local args = {}
  1200.             for word in message:gmatch("%S+") do args[#args+1] = word end
  1201.  
  1202.             if args[1]:lower() == "crafty" and args[2] ~= nil then
  1203.                 if args[2]:lower() == "quit" or args[2]:lower()=="forcequit" then return
  1204.  
  1205.                 elseif simpleCommands[args[2]:lower()] ~= nil then simpleCommands[args[2]:lower()](message, args)
  1206.  
  1207.                 else
  1208.                     for k,v in pairs(programTable) do
  1209.                         if args[2]:lower() == k:lower() then
  1210.                             local funcArgs = {}
  1211.                             if type(v) == "function" then funcArgs= {name=k,func=v, args=message}
  1212.                             elseif v.func ~= nil then
  1213.                                 if v.acceptArgs then funcArgs = {name=k, func=v.func,args=args}
  1214.                                 elseif v.acceptMessage then funcArgs = {name=k, func=v.func, args=message}
  1215.                                 else funcArgs={name=k, func=v.func} end
  1216.                             else
  1217.                                 funcArgs= {name=k,func=simpleProcessMats,args=args}
  1218.                             end
  1219.  
  1220.                             queue[#queue+1] = funcArgs
  1221.                         end
  1222.                     end
  1223.                 end
  1224.             end
  1225.  
  1226.         elseif message:lower():gsub("[^%w%s]+", ""):find("crafty say hello") and uuid == "58b2110a-ceb4-4781-9359-1a764ac57edc" then
  1227.             chatBox.sendMessage("Hello, I'm Crafty! Ivy's new robot meant to assist with many tasks and automation! It's a huge pleasure to meet you all! ^.^", "Crafty")
  1228.  
  1229.         elseif message:lower():find("crafty") then
  1230.             for k,v in pairs(acceptedGreetings) do
  1231.                 if message:lower():gsub("[^%w%s]+", ""):find(v) then
  1232.                     if responseTable[uuid] ~= nil then chatBox.sendMessage(responseTable[uuid][math.random(#responseTable[uuid])],"Crafty")
  1233.                     else chatBox.sendMessage(responseTable.general[math.random(#responseTable.general)])
  1234.                     end
  1235.                 end
  1236.             end
  1237.         end
  1238.  
  1239.     end end,
  1240.     function() while true do
  1241.         local tasks = {}
  1242.         if next(queue) ~= nil then
  1243.             tasks=queue
  1244.             queue={}
  1245.         end
  1246.         if next(tasks) ~= nil then
  1247.             working=true
  1248.             for k,v in pairs(tasks) do
  1249.                 if not clearQueue then
  1250.                     if v.args ~= nil then v.func(v.args) else v.func() end
  1251.                 end
  1252.                 stopped=false
  1253.             end
  1254.         else working=false
  1255.         end
  1256.  
  1257.         stopped = false
  1258.         clearQueue=false
  1259.         os.sleep(0)
  1260.     end end
  1261. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement