Advertisement
Shaka01

full remote sender

Jan 27th, 2024
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.76 KB | None | 0 0
  1. if not fs.exists("API") then
  2.     shell.run("pastebin", "get", "EzkfU5ZM", "API")
  3. end
  4. if not fs.exists("basalt.lua") then
  5.     shell.run("wget", "run", "http://basalt.madefor.cc/install.lua", "packed")
  6.     -- wget run https://basalt.madefor.cc/install.lua release latest.lua
  7.     -- shell.run("pastebin", "run", "ESs1mg7P")
  8.     -- wget run http://basalt.madefor.cc/install.lua packed
  9.     -- pastebin run ESs1mg7P
  10. end
  11.  
  12. basalt = require("basalt")
  13. shaka = require("API")
  14. term.setCursorBlink(false)
  15. startLocation = true
  16. local value
  17. local index
  18.  
  19. local turtleSides = {"Front", "Back", "Top", "Bottom", "Left", "Right"}
  20.  
  21.  
  22. turtleID = 43 -- remove this !!!!!!!!!!!
  23.  
  24.  
  25. local function findTransporter()
  26.     shaka.clearScreen()
  27.     local main = basalt.createFrame()
  28.     shaka.changeColors(colors.black, colors.yellow)
  29.     print("Waiting for connection..")
  30.     local id, msg = rednet.receive("transporterPing")
  31.     if id then
  32.         turtleID = id
  33.         rednet.send(id, "you're not alone", "transporterAnswer")
  34.     end
  35. end
  36.  
  37. -- Function to send movement orders via Rednet
  38. local function sendMovementOrder(orderName)
  39.     rednet.send(turtleID, orderName, "recordRemote")  -- Send the order via Rednet
  40. end
  41.  
  42. local function recordInventory()
  43.     local direction = nil
  44.     local dropDirection = nil
  45.     local turtleCommand = nil
  46.     local selectedItem = nil
  47.     local itemSelection = 0
  48.     local amount = nil
  49.     shaka.changeColors(colors.black, colors.white)
  50.     term.clear()
  51.     term.setCursorPos(1, 1)
  52.     shaka.changeColors(colors.gray, colors.yellow)
  53.     term.clearLine()
  54.     shaka.centerText("Drop or take items?", 1)
  55.     shaka.changeColors(colors.black, colors.white)
  56.     shaka.nextLine()
  57.     shaka.nextLine()
  58.     local savedX, savedY = term.getCursorPos()
  59.     print("1. Drop")
  60.     print("2. Take")
  61.  
  62.     while true do
  63.         local event, answer = os.pullEvent("key")
  64.         os.pullEvent("key_up")
  65.         if answer == keys.one then
  66.             term.setCursorPos(1, 1)
  67.             shaka.changeColors(colors.gray, colors.yellow)
  68.             term.clearLine()
  69.             shaka.centerText("Choose drop mode")
  70.             shaka.changeColors(colors.black, colors.white)
  71.             term.setCursorPos(savedX, savedY)
  72.             term.clearLine()
  73.             print("1. Drop all items")
  74.             print("2. Filter dropped items")
  75.             while true do
  76.                 local event, dropAnswer = os.pullEvent("key")
  77.                 os.pullEvent("key_up")
  78.                 if dropAnswer == keys.one then
  79.                     direction = "drop"
  80.                     break
  81.                 elseif dropAnswer == keys.two then
  82.                     direction = "dropFiltered"
  83.                     break
  84.                 end
  85.             end
  86.             shaka.clearScreen()
  87.             shaka.changeColors(colors.gray, colors.yellow)
  88.             term.clearLine()
  89.             shaka.centerText("Drop items where?")
  90.             shaka.changeColors(colors.black, colors.white)
  91.             term.setCursorPos(savedX, savedY)
  92.             break
  93.         elseif answer == keys.two then
  94.             shaka.clearScreen()
  95.             shaka.changeColors(colors.gray, colors.yellow)
  96.             term.clearLine()
  97.             shaka.centerText("Take from where?")
  98.             shaka.nextLine()
  99.             shaka.nextLine()
  100.             shaka.changeColors(colors.black, colors.white)
  101.             direction = "suck"
  102.             break
  103.         end
  104.     end
  105.  
  106.  
  107.     local _, frontY = term.getCursorPos()
  108.     print("1. Front")
  109.     local _, upY = term.getCursorPos()
  110.     print("2. Up")
  111.     local _, downY = term.getCursorPos()
  112.     print("3. Down")
  113.    
  114.     while true do
  115.    
  116.         local event, dropDirection, isHeld = os.pullEvent("key")
  117.         os.pullEvent("key_up")
  118.         if dropDirection == keys.one then
  119.             turtleCommand = "front"
  120.             local x, y = term.getCursorPos()
  121.             term.setCursorPos(1, frontY)
  122.             term.clearLine()
  123.             shaka.changeColors(colors.green, colors.black)
  124.             print("1. Front")
  125.             term.setCursorPos(x, y)
  126.             break
  127.         elseif dropDirection == keys.two then
  128.             turtleCommand = "up"
  129.             local x, y = term.getCursorPos()
  130.             term.setCursorPos(1, upY)
  131.             term.clearLine()
  132.             shaka.changeColors(colors.green, colors.black)
  133.             print("2. Up")
  134.             term.setCursorPos(x, y)
  135.             break
  136.         elseif dropDirection == keys.three then
  137.             turtleCommand = "down"
  138.             local x, y = term.getCursorPos()
  139.             term.setCursorPos(1, downY)
  140.             term.clearLine()
  141.             shaka.changeColors(colors.green, colors.black)
  142.             print("3. Down")
  143.             term.setCursorPos(x, y)
  144.             break
  145.         end
  146.        
  147.     end
  148.    
  149.     if direction == "dropFiltered" then
  150.         repeat
  151.             shaka.clearScreen()
  152.             shaka.changeColors(colors.gray, colors.yellow)
  153.             term.clearLine()
  154.             shaka.centerText("Which item?")
  155.             shaka.nextLine()
  156.             shaka.nextLine()
  157.             shaka.changeColors(colors.black, colors.white)
  158.             sendMovementOrder("showAvailable")
  159.             sender, msg = rednet.receive("showAvailableItems", 2)
  160.             if msg then
  161.                 msg = textutils.unserialize(msg)
  162.                 if msg[1] ~= nil then
  163.                     for k, v in pairs(msg) do
  164.                         print(k..". "..v)
  165.                     end
  166.                 else
  167.                     print("Place item into turtle inventory and hit enter.")
  168.                 end
  169.             else
  170.                 shaka.changeColors(colors.red, colors.black)
  171.                 print("Lost connection! Restarting.")
  172.                 sleep(2)
  173.                 os.reboot()
  174.             end
  175.             shaka.nextLine()
  176.             local x, y = term.getCursorPos()
  177.             local maxX, maxY = term.getSize()
  178.             term.setCursorPos(1, maxY - 3)
  179.             shaka.changeColors(colors.black, colors.gray)
  180.             print("Enter without entry to refresh turtle inventory")
  181.             term.setCursorPos(x, y)
  182.             shaka.changeColors(colors.black, colors.white)
  183.             itemSelection = tonumber(read())
  184.         until itemSelection ~= nil
  185.         for k, v in pairs(msg) do
  186.             if itemSelection == k then
  187.                 selectedItem = v
  188.             end
  189.         end
  190.     end
  191.    
  192.     if direction ~= "drop" then
  193.         shaka.changeColors(colors.gray, colors.yellow)
  194.         shaka.nextLine()
  195.         term.clearLine()
  196.         shaka.centerText("Amount?")
  197.         shaka.nextLine()
  198.         shaka.changeColors(colors.black, colors.white)
  199.         print("No entry for as many as possible\n")
  200.        
  201.         amount = read()
  202.     end
  203.    
  204.     if amount == nil or amount == "" then
  205.         amount = "all"
  206.     end
  207.    
  208.     if selectedItem == nil then
  209.         selectedItem = "nada"
  210.     end
  211.    
  212.     if turtleCommand then
  213.     shaka.changeColors(colors.gray, colors.green)
  214.     print("\nSaved!")
  215.     sleep(1)
  216.     end
  217.     sendMovementOrder(direction.." "..turtleCommand.." "..amount.." "..selectedItem)
  218. end
  219.  
  220. local function switchRedstone()
  221.     local dir = nil
  222.     local state = nil
  223.     local pulseTime = 0
  224.     term.clear()
  225.     term.setCursorPos(1,1)
  226.     shaka.changeColors(colors.gray, colors.yellow)
  227.     term.clearLine()
  228.    
  229.     shaka.centerText("Change rs on which side?")
  230.     shaka.changeColors(colors.black, colors.white)
  231.     shaka.nextLine()
  232.     shaka.nextLine()
  233.         print("  ^   Front - W")
  234.         print("<   > Left/Right - A/D")
  235.         print("  v   Back - S\n")
  236.         print("Space: Top")
  237.         print("Shift: Bottom\n")
  238.     while true do
  239.         local event, selection = os.pullEvent("key")
  240.         os.pullEvent("key_up")
  241.         if selection == keys.space then
  242.             dir = "top"
  243.             break
  244.         elseif selection == keys.leftShift then
  245.             dir = "bottom"
  246.             break
  247.         elseif selection == keys.a then
  248.             dir = "left"
  249.             break
  250.         elseif selection == keys.d then
  251.             dir = "right"
  252.             break
  253.         elseif selection == keys.w then
  254.             dir = "front"
  255.             break
  256.         elseif selection == keys.s then
  257.             dir = "back"
  258.             break
  259.         end
  260.     end
  261.     shaka.changeColors(colors.black, colors.green)
  262.     print("Selected:", dir)
  263.     shaka.nextLine()
  264.     shaka.changeColors(colors.gray, colors.yellow)
  265.     term.clearLine()
  266.     print("Operation?\n")
  267.     shaka.changeColors(colors.black, colors.white)
  268.     local x, y = term.getCursorPos()
  269.     print("1. On")
  270.     print("2. Off")
  271.     print("3. Pulse on -> off")
  272.     shaka.changeColors(colors.black, colors.yellow)
  273.     while true do
  274.         local event, selection = os.pullEvent("key")
  275.         os.pullEvent("key_up")
  276.         if selection == keys.one then
  277.             state = "on"
  278.             break
  279.         elseif selection == keys.two then
  280.             state = "off"
  281.             break
  282.         elseif selection == keys.three then
  283.             state = "pulse"
  284.             for i = 0, 3 do
  285.             term.setCursorPos(x, y + i)
  286.             term.clearLine()
  287.             end
  288.             term.setCursorPos(x, y)
  289.             shaka.changeColors(colors.black, colors.white)
  290.             print("Pulse for how long?\n")
  291.             pulseTime = read()
  292.             break
  293.         end
  294.     end
  295.     print("Selected:", state)
  296.     sendMovementOrder("redstone " ..dir.. " " ..state.." "..pulseTime)
  297.     sleep(1)
  298. end
  299.  
  300. local function addSleep()
  301.     shaka.clearScreen()
  302.     shaka.changeColors(colors.black, colors.yellow)
  303.     print("How many seconds?\n")
  304.     sleep(0.3)
  305.     local sleepTime = read()
  306.     sendMovementOrder("sleep " ..sleepTime)
  307.     print("\nSuccess!")
  308.     sleep(1)
  309. end
  310.  
  311. local function genericMenu(title, optionsTable, listBoolean, keepScreenBoolean)
  312.     local selection = nil
  313.     local dir = nil
  314.     if keepScreenBoolean ~= true then
  315.         shaka.clearScreen()
  316.     else
  317.         shaka.nextLine()
  318.         shaka.nextLine()
  319.     end
  320.     shaka.changeColors(colors.gray, colors.yellow)
  321.     term.clearLine()
  322.     shaka.centerText(title)
  323.     local xPos, yPos = term.getCursorPos()
  324.     term.setCursorPos(1, yPos + 2)
  325.     if listBoolean then
  326.         shaka.changeColors(colors.black, colors.white)
  327.         for i = 1, #optionsTable do
  328.             print(i..") "..optionsTable[i])
  329.         end
  330.         while true do
  331.             local event, choice = os.pullEvent("key")
  332.             os.pullEvent("key_up")
  333.             if choice == keys.one then
  334.                 selection = 1
  335.                 break
  336.             elseif choice == keys.two then
  337.                 selection = 2
  338.                 break
  339.             elseif choice == keys.three then
  340.                 selection = 3
  341.                 break
  342.             elseif choice == keys.four then
  343.                 selection = 4
  344.                 break
  345.             elseif choice == keys.five then
  346.                 selection = 5
  347.                 break
  348.             elseif choice == keys.six then
  349.                 selection = 6
  350.                 break
  351.             end
  352.         end
  353.         term.setCursorPos(1, selection + yPos + 1)
  354.         shaka.changeColors(colors.green, colors.yellow)
  355.         if optionsTable[selection] then
  356.         print(selection..") " ..optionsTable[selection])
  357.         end
  358.     else
  359.         shaka.changeColors(colors.black, colors.white)
  360.         print("  ^   Front - W")
  361.         print("<   > Left/Right - A/D")
  362.         print("  v   Back - S\n")
  363.         print("Space: Top")
  364.         print("Shift: Bottom\n")
  365.         while true do
  366.             event, selection = os.pullEvent("key")
  367.             os.pullEvent("key_up")
  368.             if selection == keys.space then
  369.                 selection = "top"
  370.                 break
  371.             elseif selection == keys.leftShift then
  372.                 selection = "bottom"
  373.                 break
  374.             elseif selection == keys.a then
  375.                 selection = "left"
  376.                 break
  377.             elseif selection == keys.d then
  378.                 selection = "right"
  379.                 break
  380.             elseif selection == keys.w then
  381.                 selection = "front"
  382.                 break
  383.             elseif selection == keys.s then
  384.                 selection = "back"
  385.                 break
  386.             end
  387.         end
  388.         shaka.changeColors(colors.black, colors.green)
  389.         print("Selected:", selection)
  390.     end
  391.     sleep(0.5)
  392.     return selection or nil
  393. end
  394.  
  395. local function redstoneTrigger()
  396.     local chosenSide = genericMenu("Wait for RS on which side?", turtleSides)
  397.     local state = genericMenu("Trigger when on or off?", {"on", "off"}, true)
  398.     sendMovementOrder("redstoneTrigger "..chosenSide.." "..state) --side string, state number[1=on, 2=off]
  399.     -- print("redstoneTrigger "..chosenSide.." "..state)
  400.     -- sleep(3)
  401. end
  402.  
  403. local function createBasaltMenu(tableName, title)
  404.     local main = basalt.createFrame()
  405.     local x, y = main:getSize()
  406.     local itemList = main:addList()
  407.     local button = main:addButton()
  408.         :setBackground(colors.lightGray)
  409.     local label = main:addLabel()
  410.         :setSize(x, 2)
  411.         :setText(title)
  412.         :setTextAlign("center")
  413.         :setBackground(colors.lightGray)
  414.        
  415.     local function stopMenu()
  416.         value = itemList:getValue()
  417.         index = itemList:getItemIndex()
  418.         basalt.stop()
  419.     end
  420.  
  421.     for k, v in pairs(tableName) do
  422.         itemList:addItem(v)
  423.     end
  424.    
  425.     local function buttonLabel()
  426.         value = itemList:getValue()
  427.         button:setText(value.text)
  428.     end
  429.    
  430.     local function keyControl(self, event, key)
  431.         key = keys.getName(key)
  432.         buttonLabel()
  433.         local pos = itemList:getItemIndex()
  434.         if key == "up" then
  435.             if pos == 1 then
  436.                 return false
  437.             else
  438.                 itemList:selectItem(pos - 1)
  439.                 buttonLabel()
  440.             end
  441.         elseif key == "down" then
  442.             if pos == itemList:getItemCount() then
  443.                 return
  444.             else
  445.                 itemList:selectItem(pos + 1)
  446.                 buttonLabel()
  447.             end
  448.         elseif key == "enter" then
  449.             stopMenu()
  450.         end
  451.     end
  452.    
  453.  
  454.    
  455.     button
  456.         :setPosition(1, y)
  457.         :setSize(x, 1)
  458.         :setText("Click or use arrows")
  459.         :onClick(stopMenu)
  460.  
  461.     itemList
  462.         :setSize(x, y - 3)
  463.         :setBackground(colors.gray)
  464.         :setPosition(1, 3)
  465.         :setFocus()
  466.         :onClickUp(buttonLabel)
  467.         :setScrollable(true)
  468.         :onKey(keyControl)
  469.         :setSelectionColor(colors.black, colors.lime)
  470.  
  471.     basalt.autoUpdate()
  472. end
  473.  
  474. local function blockTrigger()
  475.     local sideTable = {"front", "up", "down"}
  476.     local chosenSide = genericMenu("Block on which side?", sideTable, true)
  477.     chosenSide = sideTable[chosenSide]
  478.     sendMovementOrder("blockInformation "..chosenSide)
  479.     local sender, msg = rednet.receive("blockAnswer")
  480.     createBasaltMenu(msg, "Please choose data:")
  481.  
  482.     if value then
  483.         sendMovementOrder("blockTrigger " ..chosenSide.." ".. value.text)
  484.     else
  485.         -- print("nope")
  486.         -- sleep(3)
  487.     end
  488. end
  489.  
  490. function getLimiter(bool)
  491.     local aboveOrBelow = nil
  492.     if bool then
  493.         aboveOrBelow = genericMenu("Trigger above or below?", {"Above", "Below"}, true, false)
  494.     else
  495.         aboveOrBelow = genericMenu("Trigger above or below?", {"Above", "Below"}, true, true)
  496.     end
  497.     if aboveOrBelow == 1 then
  498.         aboveOrBelow = "above"
  499.     elseif aboveOrBelow == 2 then
  500.         aboveOrBelow = "below"
  501.     end
  502.     return aboveOrBelow
  503. end
  504.  
  505.  
  506. local function basaltInvMenu()
  507.     local itemIndex
  508.     local upDownChoice = nil
  509.     local itemNumber
  510.     local ready = false
  511.     local inputSize = 7
  512.     local itemTable = {}
  513.     local prettyTable = {}
  514.     local count = -1
  515.     local main = basalt.createFrame()
  516.         :setBackground(colors.gray)
  517.        
  518.    
  519.     local itemList = main:addDropdown()
  520.         :setPosition(8, 1)
  521.         :setDropdownSize(26 - 8, 15)
  522.         :setBackground(colors.lightGray)
  523.         :setSize(26 - 7, 1)
  524.         :setZIndex(100)
  525.    
  526.     local itemCount = main:addInput()
  527.         :setInputType("number")
  528.         :setSize(inputSize, 1)
  529.         :setInputLimit(inputSize - 1)
  530.         :setPosition(2, 8)
  531.         :setBackground(colors.black)
  532.         :setForeground(colors.white)
  533.         :setDefaultText("Enter #")
  534.         :setFocus()
  535.        
  536.     local confirmButton = main:addButton()
  537.         :setSize(7, 3)
  538.         :setPosition(19, 6)
  539.         :setBackground(colors.red)
  540.         :setText("Confirm")
  541.        
  542.     local inputX = itemCount:getX()
  543.     local inputY = itemCount:getY()
  544.     local aboveOrBelowWindow = main:addFrame()
  545.         :setSize(inputSize, 2)
  546.         :setPosition(inputX, inputY - 2)
  547.         :setTransparency(false)
  548.         :setBackground(colors.gray)
  549.        
  550.         local upArrow = aboveOrBelowWindow:addButton()
  551.             :setSize(inputSize, 1)
  552.             :setPosition(1, 1)
  553.             :setText("above")
  554.             :setBackground(colors.lightGray)
  555.                
  556.         local downArrow = aboveOrBelowWindow:addButton()
  557.             :setSize(inputSize, 1)
  558.             :setPosition(1, 2)
  559.             :setText("below")
  560.             :setBackground(colors.lightGray)
  561.    
  562.        
  563.        
  564.         local function clickUp()
  565.             upArrow:setBackground(colors.green)
  566.             downArrow:setBackground(colors.lightGray)
  567.             upDownChoice = "above"
  568.         end
  569.        
  570.         local function clickDown()
  571.             upArrow:setBackground(colors.lightGray)
  572.             downArrow:setBackground(colors.green)
  573.             upDownChoice = "below"
  574.         end
  575.        
  576.         local function keyBoardSelection(self, event, key)
  577.             if key == keys.up then
  578.                 clickUp()
  579.             elseif key == keys.down then
  580.                 clickDown()
  581.             end
  582.         end
  583.        
  584.     local dirList = main:addDropdown()
  585.         :setPosition(1, 1)
  586.         :setSize(7, 1)
  587.         :setBackground(colors.white)
  588.         :setZIndex(101)
  589.    
  590.     -- local chosenSide = genericMenu("Inventory on which side?")
  591.     -- local inventoryAction = genericMenu("Which inventory trigger?", {"Count of specific item", "Total fill percentage"}, true, true)
  592.     -- sendMovementOrder("displayExternal")
  593.     -- rednet.send(turtleID, "front", "sideAnswer") --- change to chosenSide !!!!! -----------------------------------
  594.    
  595.     local directions = {"front", "top", "bottom"}
  596.     for k, v in pairs(directions) do
  597.         dirList:addItem(v)
  598.     end
  599.    
  600.     local function stopMenu()
  601.         local itemIndex = itemList:getItemIndex()
  602.         local itemNumber = itemCount:getValue()
  603.         local dirIndex = dirList:getItemIndex()
  604.         -- local zTest = aboveOrBelowWindow:getZIndex()
  605.         -- basalt.debug(zTest)
  606.        
  607.         if itemIndex and itemNumber and dirIndex then
  608.             sendMovementOrder("inventoryTrigger " ..directions[dirIndex].. " " ..itemTable[itemIndex].." "..upDownChoice.." "..itemNumber)
  609.         end
  610.         basalt.stop()
  611.     end
  612.    
  613.    
  614.     local function changeButton(self)
  615.         count = itemCount:getValue()
  616.         basalt.debug(count)
  617.         if count >= 0 then
  618.             if upDownChoice ~= nil then
  619.                 confirmButton:setBackground(colors.green)
  620.                 ready = true
  621.             end
  622.         else
  623.             confirmButton:setBackground(colors.red)
  624.         end
  625.     end
  626.    
  627.     local function showItems(self)
  628.         prettyTable = {}
  629.         itemList:clear()
  630.         local selectedIndex = dirList:getItemIndex()
  631.         sendMovementOrder("displayExternal")
  632.         local sender = rednet.receive("sideQuestion")
  633.         rednet.send(turtleID, directions[selectedIndex], "sideAnswer")
  634.         sender, itemTable = rednet.receive("items_Available")
  635.         itemTable = textutils.unserialize(itemTable)
  636.        
  637.         local function compareSubstring(a, b)
  638.             local substringA = string.sub(a, string.find(a, ":") + 1)
  639.             local substringB = string.sub(b, string.find(b, ":") + 1)
  640.             return substringA < substringB
  641.         end
  642.        
  643.         table.sort(itemTable, compareSubstring)
  644.        
  645.         for k, v in pairs(itemTable) do
  646.             prettyTable[k] = shaka.prettyName(itemTable[k])
  647.         end
  648.        
  649.         for k, v in pairs(prettyTable) do
  650.             itemList:addItem(v)
  651.         end
  652.        
  653.     end
  654.    
  655.     showItems()
  656.    
  657.     upArrow:onClick(clickUp)
  658.         -- :onLoseFocus(changeButton)
  659.         :onClick(changeButton)
  660.        
  661.     downArrow:onClick(clickDown)
  662.         -- :onLoseFocus(changeButton)
  663.         :onClick(changeButton)
  664.    
  665.     itemCount
  666.         :onKey(keyBoardSelection)
  667.         :onLoseFocus(changeButton)
  668.        
  669.     confirmButton
  670.         :onClick(stopMenu)
  671.    
  672.     dirList
  673.         :onChange(showItems)
  674.  
  675.     basalt.autoUpdate()
  676. end
  677.        
  678. local function inventoryTrigger()
  679.     local chosenSide = genericMenu("Inventory on which side?")
  680.     local inventoryAction = genericMenu("Which inventory trigger?", {"Count of specific item", "Total fill percentage"}, true, true)
  681.     sendMovementOrder("displayExternal")
  682.     local sender = rednet.receive("sideQuestion")
  683.     rednet.send(sender, chosenSide, "sideAnswer")
  684.    
  685.     if tonumber(inventoryAction) == 1 then
  686.         local sender, itemTable = rednet.receive("items_Available")
  687.         itemTable = textutils.unserialize(itemTable)
  688.         local prettyTable = {}
  689.         local function compareSubstring(a, b)
  690.             local substringA = string.sub(a, string.find(a, ":") + 1)
  691.             local substringB = string.sub(b, string.find(b, ":") + 1)
  692.             return substringA < substringB
  693.         end
  694.         table.sort(itemTable, compareSubstring)
  695.         for k, v in pairs(itemTable) do
  696.             prettyTable[k] = shaka.prettyName(itemTable[k])
  697.         end
  698.         shaka.clearScreen()
  699.         createBasaltMenu(prettyTable, "Which item?")
  700.         limiter = getLimiter()
  701.         shaka.nextLine()
  702.         shaka.changeColors(colors.gray, colors.yellow)
  703.         term.clearLine()
  704.         print("Item count to trigger on?")
  705.         shaka.changeColors(colors.black, colors.white)
  706.         shaka.nextLine()
  707.         local countAnswer = tonumber(read())
  708.         shaka.clearScreen()
  709.         shaka.changeColors(colors.black, colors.green)
  710.         print("Success!")
  711.         shaka.changeColors(colors.black, colors.white)
  712.         print("\nSide:", chosenSide)
  713.         print("\nItem:", prettyTable[index])
  714.         print("\nTrigger: "..limiter.." "..countAnswer)
  715.         sendMovementOrder("inventoryTrigger " ..chosenSide.. " " ..itemTable[index].." "..limiter.." "..countAnswer)
  716.        
  717.         shaka.changeColors(colors.black, colors.gray)
  718.         print("\nPress any key to continue..")
  719.         os.pullEvent("key")
  720.     else
  721.         shaka.clearScreen()
  722.         limiter = getLimiter(true)
  723.         shaka.nextLine()
  724.         shaka.nextLine()
  725.         shaka.changeColors(colors.gray, colors.yellow)
  726.         term.clearLine()
  727.         print("Which percentage?")
  728.         local percentage = read()
  729.         print("inventoryTrigger " ..chosenSide.. " fillPercent "..limiter.." "..percentage)
  730.         sendMovementOrder("inventoryTrigger " ..chosenSide.. " fillPercent "..limiter.." "..percentage)
  731.     end
  732. end
  733.  
  734. local function triggerMenu()
  735.     shaka.clearScreen()
  736.     local options = {"Redstone", "Block", "Inventory"}
  737.     shaka.changeColors(colors.gray, colors.yellow)
  738.     term.clearLine()
  739.     shaka.centerText("Trigger on which event?\n")
  740.     term.setCursorPos(1, 3)
  741.     local startY = 3
  742.     shaka.changeColors(colors.black, colors.white)
  743.  
  744.   -- display the menu options
  745.   for i=1,#options do
  746.     print(i..") "..options[i])
  747.   end
  748.  
  749.   shaka.nextLine()
  750.   -- get user input
  751.   local a, b = term.getCursorPos()
  752.   term.write("Select an option")
  753.   while true do
  754.     local event, choice = os.pullEvent("key")
  755.     os.pullEvent("key_up")
  756.     if choice == keys.one then
  757.         term.setCursorPos(1, startY)
  758.         shaka.changeColors(colors.green, colors.yellow)
  759.         term.clearLine()
  760.         print("1) " ..options[1])
  761.         term.setCursorPos(a, b)
  762.         shaka.changeColors(colors.black, colors.green)
  763.         term.clearLine()
  764.         print("Selected "..options[1])
  765.         sleep(1)
  766.         redstoneTrigger()
  767.         return choice
  768.     elseif choice == keys.two then
  769.         term.setCursorPos(1, startY + 1)
  770.         shaka.changeColors(colors.green, colors.yellow)
  771.         term.clearLine()
  772.         print("2) " ..options[2])
  773.         term.setCursorPos(a, b)
  774.         shaka.changeColors(colors.black, colors.green)
  775.         term.clearLine()
  776.         print("Selected "..options[2])
  777.         sleep(1)
  778.         blockTrigger()
  779.         return choice
  780.     elseif choice == keys.three then
  781.         term.setCursorPos(1, startY + 2)
  782.         shaka.changeColors(colors.green, colors.yellow)
  783.         term.clearLine()
  784.         print("3) " ..options[3])
  785.         term.setCursorPos(a, b)
  786.         shaka.changeColors(colors.black, colors.green)
  787.         term.clearLine()
  788.         print("Selected "..options[3])
  789.         sleep(1)
  790.         inventoryTrigger()
  791.         return choice
  792.     end
  793.     term.setCursorPos(a, b + 2)
  794.     term.write("Invalid option. Try again.")
  795.     sleep(1)
  796.     term.clearLine()
  797.   end
  798. end
  799.  
  800. local function main()
  801.     shaka.clearScreen()
  802.     -- Display movement options
  803.     shaka.changeColors(colors.gray, colors.black)
  804.     term.clearLine()
  805.  
  806.     -- Display title
  807.    
  808.     print("Turtle Movement Options:\n")
  809.     shaka.changeColors(colors.black, colors.green)
  810.     -- Display movement options with arrows
  811.     print("  ^   Forward - W")
  812.     print("<   > Left/Right - A/D")
  813.     print("  v   Backward - S\n")
  814.     print("Space: Up")
  815.     print("Shift: Down\n")
  816.  
  817.     -- Display other options
  818.     shaka.changeColors(colors.black, colors.yellow)
  819.     print("I    Inventory Action")
  820.     print("R    Redstone Action")
  821.     print("F    Sleep Action")
  822.     print("T    Wait for Trigger\n")
  823.     term.setTextColor(colors.orange)
  824.     print("Q    Undo last move")
  825.     _, XLoc = term.getCursorPos()
  826.     term.clearLine()
  827.     print("X    Finish recording\n")
  828.  
  829.     while true do
  830.         -- Get user input
  831.         local event, key = os.pullEvent("key")
  832.         if key == keys.w then
  833.                 sendMovementOrder("forward")
  834.             elseif key == keys.a then
  835.                 sendMovementOrder("left")
  836.             elseif key == keys.s then
  837.                 sendMovementOrder("back")
  838.             elseif key == keys.d then
  839.                 sendMovementOrder("right")
  840.             elseif key == keys.space then
  841.                 sendMovementOrder("up")
  842.             elseif key == keys.leftShift then
  843.                 sendMovementOrder("down")
  844.             elseif key == keys.i then
  845.                 recordInventory()
  846.                 main()
  847.                 break
  848.             elseif key == keys.x then
  849.                 sendMovementOrder("allDone")
  850.                 local sender, msg = rednet.receive("remoteEnd")
  851.                 if msg == "yep" then
  852.                     shaka.clearScreen()
  853.                     textutils.slowPrint("Finished recording..")
  854.                     sleep(1)
  855.                     break
  856.                 elseif msg == "nope" then
  857.                     rednet.send(sender, "y", "remoteEnd")
  858.                     local turtle_id, reply = rednet.receive("arrivedAtStart")
  859.                     local x, y = term.getCursorPos()
  860.                     term.setCursorPos(1, XLoc)
  861.                     term.clearLine()
  862.                     shaka.changeColors(colors.black, colors.orange)
  863.                     print("X    Finish recording\n")
  864.                     term.setCursorPos(x, y)
  865.                 end
  866.             elseif key == keys.q then
  867.                 sendMovementOrder("delete")
  868.                 sender, msg = rednet.receive("instructionDeleteConfirm", 2)
  869.                 shaka.changeColors(colors.black, colors.red)
  870.                 if msg then
  871.                     local x, y = term.getCursorPos()
  872.                     local _, maxY = term.getSize()
  873.                     term.setCursorPos(1, maxY - 1)
  874.                     term.clearLine()
  875.                     if msg == "start" then
  876.                         term.write("Back at start")
  877.                     else
  878.                         term.write("Deleted: "..msg)
  879.                     end
  880.                     sleep(1)
  881.                     term.clearLine()
  882.                     term.setCursorPos(x, y)
  883.                 else
  884.                     print("Failure")
  885.                 end
  886.             elseif key == keys.r then
  887.                 switchRedstone()
  888.                 main()
  889.                 break
  890.             elseif key == keys.f then
  891.                 addSleep()
  892.                 main()
  893.                 break
  894.             elseif key == keys.t then
  895.                 triggerMenu()
  896.                 main()
  897.                 break
  898.         end
  899.     end
  900. end
  901.  
  902. local function positionUpdate()
  903.     while true do
  904.         local sender, msg = rednet.receive("positionUpdate")
  905.         if msg == "start" then
  906.             local x, y = term.getCursorPos()
  907.             term.setCursorPos(1, XLoc)
  908.             term.clearLine()
  909.             shaka.changeColors(colors.black, colors.orange)
  910.             print("X    Finish recording\n")
  911.             term.setCursorPos(x, y)
  912.         else
  913.             local x, y = term.getCursorPos()
  914.             term.setCursorPos(1, XLoc)
  915.             term.clearLine()
  916.             shaka.changeColors(colors.black, colors.orange)
  917.             print("X    Go to start\n")
  918.             term.setCursorPos(x, y)
  919.         end
  920.     end
  921. end
  922.  
  923. -- local function turtleControls()
  924.     -- local normalBG = colors.green
  925.     -- local clickedBG = colors.yellow
  926.     -- local main = basalt.createFrame()
  927.     -- local joypad = main:addFrame()
  928.         -- :setBackground(colors.black)
  929.         -- :setSize(5, 3)
  930.         -- :setPosition(4, 3)
  931.         -- :setFocus()
  932.         -- :setBorder(colors.blue)
  933.        
  934.     -- local arrows = {buttonForward, buttonBack, buttonLeft, buttonRight}
  935.     -- local function forward()
  936.         -- sendMovementOrder("forward")
  937.     -- end
  938.    
  939.     -- local function back()
  940.         -- sendMovementOrder("back")
  941.     -- end
  942.    
  943.    
  944.     -- local arrowButtons = {
  945.         -- joypad:addButton():setText("^")
  946.         -- :setPosition(3, 1)
  947.         -- :onClick(forward)
  948.         -- :onKey(keyColorPressed)
  949.         -- :onKeyUp(keyColorNormal)
  950.         -- ,
  951.         -- joypad:addButton():setText("v")
  952.         -- :setPosition(3, 3)
  953.         -- :onClick(back)
  954.         -- ,
  955.         -- joypad:addButton():setText("<")
  956.         -- :setPosition(1, 2)
  957.         -- ,
  958.         -- joypad:addButton():setText(">")
  959.         -- :setPosition(5, 2)
  960.     -- }
  961.    
  962.     -- local function keyColorNormal(self, event, key)
  963.             -- basalt.debug("up")
  964.             -- for k, v in pairs(arrowButtons) do
  965.                 -- v:setBackground(normalBG)
  966.             -- end
  967.             -- arrowButtons[1]:setBackground(normalBG)
  968.     -- end
  969.    
  970.     -- local function keyColorPressed(self, event, key)
  971.         -- if (key == keys.w) then
  972.             -- basalt.debug("yo")
  973.             -- arrowButtons[1]:setBackground(clickedBG)
  974.         -- elseif key == keys.a then
  975.             -- arrowButtons[3]:setBackground(clickedBG)
  976.         -- elseif key == keys.s then
  977.             -- arrowButtons[2]:setBackground(clickedBG)
  978.         -- elseif key == keys.d then
  979.             -- arrowButtons[4]:setBackground(clickedBG)
  980.         -- end
  981.     -- end 
  982.     -- joypad
  983.     -- :onKey(keyColorPressed)
  984.     -- :onKeyUp(keyColorNormal)
  985.    
  986.     -- for k, v in pairs(arrowButtons) do
  987.         -- local function normalColor()
  988.             -- v:setBackground(normalBG)
  989.         -- end
  990.         -- normalColor()
  991.         -- local function clickColor()
  992.             -- v:setBackground(clickedBG)
  993.             -- basalt.debug("Button "..k)
  994.         -- end
  995.         -- v:setSize(1,1)
  996.         -- v:onClick(clickColor)
  997.         -- v:onRelease(normalColor)
  998.     -- end 
  999.    
  1000. -- end
  1001.  
  1002.  
  1003.  
  1004. -- turtleControls()
  1005.  
  1006. local function test()
  1007.     local main = basalt.createFrame()
  1008.     local inputField = main:addInput()
  1009.    
  1010.     local function changedInput()
  1011.         local value = inputField:getValue()
  1012.         basalt.debug(value)
  1013.     end
  1014.    
  1015.     inputField:onChange(changedInput)
  1016.     basalt.autoUpdate()
  1017. end
  1018.  
  1019.  
  1020. local args = { ... }
  1021.  
  1022. if args[1] == "1" then
  1023.     -- blockTrigger()
  1024.     inventoryTrigger()
  1025. elseif args[1] == "2" then
  1026.     basaltInvMenu()
  1027.     -- test()
  1028. else
  1029. findTransporter()
  1030.  
  1031. -- while true do
  1032. parallel.waitForAny(main, positionUpdate)
  1033. end
  1034. -- end
  1035. -- main()
  1036. -- print(triggerMenu())
  1037. -- os.reboot()
  1038. -- basalt.autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement