Advertisement
DiamondDaDog

Untitled

May 5th, 2024 (edited)
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. local basalt = require("basalt")
  2.  
  3. Vaults = 2
  4.  
  5.  
  6. fs.makeDir("vault_cache")
  7.  
  8. Controller = peripheral.wrap("top")
  9.  
  10. DirectionOut = true
  11. DirectionIn = false
  12.  
  13. function DistanceToRotationDuration(speed, distance)
  14.     return (math.ceil(distance / (speed / 512)) + 2) / 20
  15. end
  16.  
  17. function Split(inputstr, sep)
  18.     if sep == nil then
  19.             sep = "%s"
  20.     end
  21.     local t={}
  22.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  23.             table.insert(t, str)
  24.     end
  25.     return t
  26. end
  27.  
  28.  
  29. function SetPusherLock(state)
  30.     Controller.setOutput("top", state)
  31. end
  32.  
  33. function SetHandDirection(dir)
  34.     Controller.setOutput("right", not dir)
  35. end
  36.  
  37. function SetGrabberLock(state)
  38.     Controller.setOutput("back", state)
  39. end
  40.  
  41. function SetChassisDirection(dir)
  42.     Controller.setOutput("left", not dir)
  43. end
  44.  
  45. function SetChassisLock(state)
  46.     Controller.setOutput("front", state)
  47. end
  48.  
  49. function Reset()
  50.     SetHandDirection(DirectionIn)
  51.     SetPusherLock(false)
  52.     SetGrabberLock(false)
  53.     sleep(5)
  54.     SetPusherLock(true)
  55.     SetGrabberLock(true)
  56.  
  57.     SetChassisDirection(DirectionIn)
  58.     SetChassisLock(false)
  59.     sleep(5)
  60.     SetChassisLock(true)
  61. end
  62.  
  63. function GrabVault(index)
  64.     Duration = DistanceToRotationDuration(128, index * 3 + 3)
  65.  
  66.     SetChassisDirection(DirectionOut)
  67.     SetChassisLock(false)
  68.     sleep(Duration)
  69.     SetChassisLock(true)
  70.  
  71.     SetHandDirection(DirectionOut)
  72.     SetGrabberLock(false)
  73.     sleep(2)
  74.     SetHandDirection(DirectionIn)
  75.     sleep(2)
  76.     SetGrabberLock(true)
  77.  
  78.     SetChassisDirection(DirectionIn)
  79.     SetChassisLock(false)
  80.     sleep(Duration)
  81.     SetChassisLock(true)
  82.  
  83.     SetHandDirection(DirectionOut)
  84.     SetPusherLock(false)
  85.     sleep(2)
  86.     SetHandDirection(DirectionIn)
  87.     sleep(2)
  88.     SetPusherLock(true)
  89. end
  90.  
  91. function ReturnVault(index)
  92.     Duration = DistanceToRotationDuration(128, index * 3 + 3)
  93.  
  94.     SetHandDirection(DirectionOut)
  95.     SetGrabberLock(false)
  96.     sleep(2)
  97.     SetHandDirection(DirectionIn)
  98.     sleep(2)
  99.     SetGrabberLock(true)
  100.  
  101.     SetChassisDirection(DirectionOut)
  102.     SetChassisLock(false)
  103.     sleep(Duration)
  104.     SetChassisLock(true)
  105.  
  106.     SetHandDirection(DirectionOut)
  107.     SetPusherLock(false)
  108.     sleep(2)
  109.     SetHandDirection(DirectionIn)
  110.     sleep(2)
  111.     SetPusherLock(true)
  112.  
  113.     SetChassisDirection(DirectionIn)
  114.     SetChassisLock(false)
  115.     sleep(Duration)
  116.     SetChassisLock(true)
  117. end
  118.  
  119. local main = basalt.createFrame()
  120.  
  121. local button = main:addButton() --> Here we add our first button
  122. button:setPosition(4, 4) -- We want to change the default position of our button
  123. button:setSize(16, 3) -- And the default size.
  124. button:setText("Click me!") --> This method sets the text displayed on our button
  125.  
  126. local function buttonClick() --> Create a function we want to call when the button gets clicked
  127.     basalt.debug("I got clicked!")
  128. end
  129.  
  130. -- Now we just need to register the function to the button's onClick event handlers, this is how we can achieve that:
  131. button:onClick(buttonClick)
  132.  
  133. basalt.autoUpdate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement