Advertisement
temposabel

mainmoni

Dec 21st, 2021 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. function getmodems(mode)
  2. mode = mode or "default"
  3.  
  4. if mode == "default" then
  5. allp = peripheral.getNames()
  6. d = {}
  7. x = 0
  8. for i,value in ipairs(allp) do
  9. c = peripheral.getType(value)
  10. if c == "modem" then
  11. c = peripheral.wrap(value)
  12. x = x + 1
  13. d[x] = c
  14. end
  15. end
  16. d["a"] = x
  17. d["amount"] = x
  18. return d
  19. elseif mode == "sides" or mode =="s" then
  20. allp = peripheral.getNames()
  21. d = {}
  22. x = 0
  23. for i,value in ipairs(allp) do
  24. c = peripheral.getType(value)
  25. if c == "modem" then
  26. x = x + 1
  27. d[x] = value
  28. end
  29. end
  30. d["a"] = x
  31. d["amount"] = x
  32. return d
  33. end
  34. end
  35.  
  36. function getmsg()
  37. while true do
  38. d = {}
  39. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  40. d["e"] = event
  41. d["s"] = side
  42. d["f"] = frequency
  43. d["rf"] = replyFrequency
  44. d["m"] = message
  45. d["d"] = distance
  46. return d
  47. end
  48. end
  49.  
  50. function transmitall(p,rp,message)
  51. modems = getmodems()
  52. print(modems["a"])
  53. if modems["a"] == 0 then else
  54. for modem = 1,modems["a"] do
  55. cm = modems[modem]
  56. cm.transmit(p,rp,message)
  57. end
  58. end
  59. end
  60.  
  61. function relay(p,rp,message,exclude)
  62. sides = getmodems("s")
  63. if modems["a"] == 0 then else
  64. for side = 1,modems["a"] do
  65. cs = sides[side]
  66. if cs == exclude then else
  67. cm.transmit(p,rp,message)
  68. end
  69. end
  70. end
  71. end
  72.  
  73. function fill()
  74. paintutils.drawFilledBox(1, 1, 1000, 1000, colors.gray)
  75. end
  76.  
  77. function cooldown (time)
  78.  
  79. for i = 1,time do
  80. term.clear()
  81. term.setCursorPos(5,3)
  82. print(time-i+1)
  83. sleep(1)
  84. end
  85. return 0
  86. end
  87. function createbutton(x,y,w,h,color,message)
  88.  
  89. d = {}
  90.  
  91. function d:init(x,y,w,h,color,message)
  92. self.x1 = x
  93. self.x2 = x+w
  94. self.y1 = y
  95. self.y2 = y+h
  96. self.color = color
  97. self.message = message
  98. end
  99.  
  100. function d:isclickon (x,y)
  101.  
  102. if self.x1 <= x and x <= self.x2 and self.y1 <= y and y <= self.y2 then
  103. return true
  104. else
  105. return false
  106. end
  107.  
  108.  
  109. end
  110.  
  111. function d:draw ()
  112. --print(self.x1)
  113. paintutils.drawFilledBox(self.x1,self.y1,self.x2,self.y2,self.color)
  114. term.setTextColor(colors.white)
  115.  
  116.  
  117. term.setBackgroundColor(colors.black)
  118. end
  119.  
  120. d:init(x,y,w,h,color,message)
  121. return d
  122. end
  123.  
  124. function toggle()
  125.  
  126. if farmon() then
  127. local h = fs.open("open.txt", "w")
  128. h.write("0")
  129. h.close()
  130. else
  131. local h = fs.open("open.txt", "w")
  132. h.write("1")
  133. h.close()
  134. end
  135.  
  136. end
  137.  
  138. function farmon()
  139. local h = fs.open("open.txt", "r")
  140. local a = tonumber(h.readLine())
  141. --print("value in fle is: " .. tostring(a))
  142. h.close()
  143.  
  144. if a == 1 then
  145. return true
  146. else
  147. return false
  148. end
  149. end
  150.  
  151. function farmona()
  152. local h = fs.open("running.txt", "r")
  153. local a = tonumber(h.readLine())
  154. --print("value in fle is: " .. tostring(a))
  155. h.close()
  156.  
  157. return a
  158. end
  159.  
  160. function togglea(newnumber)
  161.  
  162. local h = fs.open("running.txt", "w")
  163. h.write(newnumber)
  164. h.close()
  165.  
  166. end
  167.  
  168. function drawtext(text,x,y)
  169. term.setCursorPos(x,y)
  170. term.setBackgroundColor(colors.black)
  171. print(text)
  172. end
  173.  
  174. term.redirect(peripheral.wrap("left"))
  175. moni = peripheral.wrap("left")
  176. moni.setTextScale(2)
  177.  
  178.  
  179. but1 = createbutton(25,2,1,1,colors.green,"")
  180. but2 = createbutton(15,4,3,1,colors.green,"")
  181. but3 = createbutton(17,4,2,1,colors.red,"")
  182. but4 = createbutton(17,4,2,1,colors.yellow,"")
  183. but5 = createbutton(25,2,1,1,colors.yellow,"")
  184. local on = false
  185. local skip = false
  186. local first = true
  187. local waiting = false
  188.  
  189. while true do
  190.  
  191. local time = os.time()
  192. local formattedTime = textutils.formatTime(time, false)
  193.  
  194. term.clear()
  195. fill()
  196. but1:draw()
  197.  
  198.  
  199. if farmon() then
  200. iso = "on"
  201. else
  202. iso = "off"
  203. end
  204.  
  205. drawtext("Bone processing:",2,2)
  206.  
  207. drawtext(iso,20,2)
  208.  
  209. if not on then
  210. but2:draw()
  211. drawtext("Start farm:",2,4)
  212. if not first then
  213. if but2:isclickon(xPos,yPos) then
  214. togglea(1)
  215. xPos = 0
  216. yPos = 0
  217. on = true
  218. skip = true
  219. sleep(0.05)
  220. shell.run("bg pastebin run 9wqiNK6g")
  221. end
  222. end
  223. else
  224. paintutils.drawFilledBox(2,4,20,8)
  225.  
  226. cn = farmona()
  227. if cn == 0 then
  228. on = false
  229. waiting = false
  230.  
  231. elseif cn == 1 then
  232. waiting = false
  233. but3:draw()
  234. drawtext("Running",3,5)
  235. if but3:isclickon(xPos,yPos) then
  236. xPos = 0
  237. yPos = 0
  238. skip = true
  239. waiting = true
  240.  
  241.  
  242. togglea(2)
  243. end
  244.  
  245. elseif cn == 2 then
  246. but5:draw()
  247. but4:draw()
  248. drawtext("Stopping.",3,5)
  249. sleep(0.5)
  250. drawtext("Stopping..",3,5)
  251. sleep(0.5)
  252. drawtext("Stopping...",3,5)
  253. sleep(0.5)
  254.  
  255. end
  256.  
  257. end
  258.  
  259.  
  260. --drawtext(formattedTime,14,5)
  261.  
  262.  
  263. if not skip then
  264. event, side, xPos, yPos = os.pullEvent("monitor_touch")
  265. if but1:isclickon(xPos,yPos) then
  266. toggle()
  267. xPos = 0
  268. yPos = 0
  269. end
  270. end
  271. if not waiting then
  272. skip = false
  273. end
  274. first = false
  275.  
  276. --print(but1:isclickon(mx,my))
  277. --print(but2:isclickon(mx,my))
  278.  
  279.  
  280. end
  281.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement