yosomith

mobControl1

Feb 10th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. local term = peripheral.wrap("top")
  2. term.setTextScale(1.5)
  3. local mob={}
  4.  
  5. function setTable(name, freq, xmin, xmax, ymin, ymax)
  6. mob[name] = {}
  7. mob[name]["freq"] = freq
  8. mob[name]["active"] = false
  9. mob[name]["xmin"] = xmin
  10. mob[name]["ymin"] = ymin
  11. mob[name]["xmax"] = xmax
  12. mob[name]["ymax"] = ymax
  13. end
  14.  
  15. function fillTable()
  16. setTable("Chicken", colors.red, 17, 24, 4, 5)
  17. setTable("Cow", colors.white, 17, 20, 8, 9)
  18. setTable("Pig", colors.yellow, 17, 20, 6, 7)
  19. setTable("Sheep", colors.blue, 17, 26, 2, 3)
  20. end
  21.  
  22. function fill(x,y,color,text)
  23. term.setBackgroundColor(color)
  24. term.setCursorPos(x,y)
  25. term.write(text)
  26. term.setBackgroundColor(colors.black)
  27. end
  28.  
  29. function screen()
  30. local y = 2
  31. local currColor
  32. for name,data in pairs(mob) do
  33. local on = data["active"]
  34. if on == true then currColor = colors.lime else currColor = colors.red end
  35. fill(17,y,currColor, name)
  36. y = y+2
  37. end
  38. end
  39.  
  40. function checkxy(x, y)
  41. for name, data in pairs(mob) do
  42. if y>=data["ymin"] and y <= data["ymax"] then
  43. if x>=data["xmin"] and x<= data["xmax"] then
  44. data["active"] = not data["active"]
  45. print(name)
  46. end
  47. end
  48. end
  49. end
  50.  
  51. function setWire()
  52. local wire = 0
  53. for name, data in pairs(mob) do
  54. if data["active"] == false then
  55. wire = colors.combine(wire, data["freq"])
  56. end
  57. end
  58. redstone.setBundledOutput("bottom", wire)
  59. end
  60.  
  61. fillTable()
  62. setWire()
  63. while true do
  64. term.clear()
  65. screen()
  66. -- fill(17,2,colors.lime, "Chicken")
  67. local e,side,x,y = os.pullEvent("monitor_touch")
  68. print(x..":"..y)
  69. checkxy(x,y)
  70. setWire()
  71. sleep(.1)
  72. end
Advertisement
Add Comment
Please, Sign In to add comment