Advertisement
repka3

cmdquarry.lua

Apr 26th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. term.clear()
  2. print("Programma per comandi singoli quarry-repka, al termine emette un segnale redstone di finish")
  3. print("")
  4.  
  5. redstone_quarry="left"
  6. redstone_finish="back"
  7. r_avanti=colors.red
  8. r_indietro=colors.blue
  9. r_sx=colors.pink
  10. r_dx=colors.lime
  11. r_finish=colors.red
  12. t_pausa_mining=15
  13. m=peripheral.wrap("top")
  14. function draw_line_term(monitor,x, y, length, color)
  15. monitor.setBackgroundColor(color)
  16. monitor.setCursorPos(x,y)
  17. monitor.write(string.rep(" ", length))
  18. end
  19.  
  20. function progress_bar_term(monitor,x, y,length, curr, maxVal, bar_color, bg_color)
  21. draw_line_term(monitor,x, y, length, bg_color) --backgoround bar
  22. local howmuch=maxVal/length
  23. local barSize = math.floor((curr/howmuch))
  24. draw_line_term(monitor,x, y, barSize, bar_color) --progress so far
  25. monitor.setCursorPos(x+math.floor(length/2)-1 ,y-1)
  26. local perc=math.floor(curr*100/maxVal)
  27. monitor.setBackgroundColor(colors.black)
  28. monitor.write(perc.."%")
  29. monitor.setCursorPos(x+math.floor(length/2)-4,y+2)
  30. monitor.write(curr.." / "..maxVal)
  31.  
  32. end
  33.  
  34. function impulso(lato,colore)
  35. redstone.setBundledOutput(lato,colore)
  36. sleep(1)
  37. redstone.setBundledOutput(lato,0)
  38. end
  39.  
  40. function muovi(colore,volte,skip)
  41. for i=1,volte,1 do
  42. print("Muovendo "..i.."/"..volte)
  43. impulso(redstone_quarry,colore)
  44. m.clear()
  45. progress_bar_term(m,2,2,25,i,volte,colors.lime,colors.lightGray)
  46. if skip=="n" then
  47. sleep(4)
  48. else
  49. print("Sto minando..")
  50. m.setCursorPos(2,5)
  51. m.write("Sto minando...")
  52. sleep(t_pausa_mining)
  53. end
  54. end
  55. end
  56. redstone.setBundledOutput(redstone_quarry,0)
  57. redstone.setBundledOutput(redstone_finish,0)
  58. print("Direzione?")
  59. print("1 - Avanti")
  60. print("2 - Indietro")
  61. print("3 - Sinistra")
  62. print("4 - Destra")
  63. local dir=read()
  64. print("")
  65. print("Quanti movimenti? es:10")
  66. local vol=read()
  67. print("")
  68. print("Vuoi fermarti a minare? y/n")
  69. local skip=read()
  70.  
  71. if dir=="1" then
  72. print("Avanti di "..vol.." !")
  73. muovi(r_avanti,vol,skip)
  74. elseif dir=="2" then
  75. print("Indietro di "..vol.." !")
  76. muovi(r_indietro,vol,skip)
  77. elseif dir=="3" then
  78. print("Sinistra di "..vol.." !")
  79. muovi(r_sx,vol,skip)
  80. elseif dir=="4" then
  81. print("Destra di "..vol.." !")
  82. muovi(r_dx,vol,skip)
  83. else
  84. print("ERRORE COMANDO SCONOSCIUTO")
  85. end
  86. print("Finito :)")
  87. redstone.setBundledOutput(redstone_finish,r_finish)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement