MarsP4ste

Lift Controller--Minecraft-Warp Drive Mod

Apr 10th, 2020 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. ---Lift Controller
  2. ---Original by Baumstamm
  3. ---Edited by MarsGame
  4.  
  5.  
  6. ---Define Settings
  7. monitorSide= "top" ---where is the monitor
  8. liftSide= "left" ---where is the lift
  9. fontScale= 0.5 ---set font scale, default is perfect for 1 block widh monitors
  10. landTime= 3 ---how long to wait before switching back to UP-Mode
  11.  
  12. ---Further down is the Code for the program, you don't need to change there anything, as the program should work perfectly.
  13.  
  14. ---Check for Advanced Computer
  15. if not term.isColor() then
  16.     print("Advanced computer required")
  17.     error()
  18. end
  19.  
  20.  
  21. ---Set Settings
  22. monitor = peripheral.wrap(monitorSide)
  23. lift = peripheral.wrap(liftSide)
  24. monitor.setTextScale(fontScale)
  25. term.setBackgroundColor(colors.lightGray)
  26. term.clear()
  27.  
  28.  
  29. ---System Variables
  30. liftON=""
  31. liftMODE="up"
  32. xSize, ySize = term.getSize()
  33.  
  34.  
  35. ---create Funktions
  36. function lift_land()
  37.     lift.mode("down")
  38.     liftMODE="down"
  39.     writeToScreen()
  40.     sleep(landTime)
  41.     lift.mode("up")
  42.     liftMODE="up"
  43.     writeToScreen()
  44. end
  45.  
  46. function lift_on()
  47.     lift.enable(true)
  48.     liftON=true
  49.     writeToScreen()
  50. end
  51.  
  52. function lift_off()
  53.     lift.enable(false)
  54.     liftON=false
  55.     writeToScreen()
  56. end
  57.  
  58. function startup()
  59.     if lift.enable() then
  60.         liftON=true
  61.     else
  62.         liftON=false
  63.     end
  64.     writeToScreen()
  65. end
  66.  
  67. function writeToScreen()
  68.     local text = "Lift Contr."
  69.    
  70.     if liftON then
  71.         term.setBackgroundColor(colors.green)
  72.         term.clear()
  73.        
  74.         term.setBackgroundColor(colors.red)
  75.         term.setCursorPos((xSize/2)-(text:len()/2)+1,1)
  76.         print(text)
  77.        
  78.         if liftMODE == "up" then
  79.             term.setBackgroundColor(colors.lightGray)
  80.             text="Lift Down"
  81.             term.setCursorPos((xSize/2)-(text:len()/2)+1,3)
  82.             print(text)
  83.         else
  84.             term.setBackgroundColor(colors.red)
  85.             text="! Lift Down !"
  86.             term.setCursorPos((xSize/2)-(text:len()/2)+1,3)
  87.             print(text)
  88.         end
  89.    
  90.         term.setBackgroundColor(colors.orange)
  91.         text="Turn LIFT off"
  92.         term.setCursorPos((xSize/2)-(text:len()/2)+1,5)
  93.         print(text)
  94.     else
  95.         term.setBackgroundColor(colors.red)
  96.         term.clear()
  97.        
  98.         term.setBackgroundColor(colors.red)
  99.         term.setCursorPos((xSize/2)-(text:len()/2)+1,1)
  100.         print(text)
  101.        
  102.         term.setBackgroundColor(colors.green)
  103.         text="Turn LIFT on"
  104.         term.setCursorPos((xSize/2)-(text:len()/2)+1,5)
  105.         print(text)
  106.     end
  107.    
  108. end
  109.  
  110. function resizeMonitor()
  111.     while true do
  112.         local event, side = os.pullEvent("monitor_resize")
  113.         os.reboot()
  114.     end
  115. end
  116.  
  117. ---Start Programm
  118. parallel.waitForAny(resizeMonitor, startup)
  119.  
  120. ---Check for Input
  121. while true do
  122.     event,side,x,y=os.pullEvent("monitor_touch")
  123.     if x>0 and x<xSize and y==3 and liftON then
  124.         lift_land()
  125.     elseif x>0 and x<xSize and y==5 and not liftON then
  126.         lift_on()
  127.     elseif x>0 and x<xSize and y==5 and liftON then
  128.         lift_off()
  129.     end
  130. end
Add Comment
Please, Sign In to add comment