Advertisement
EkielZan

touchscreen

Nov 24th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.09 KB | None | 0 0
  1. -- Computer ID = 6
  2. --# load the touchpoint API
  3. os.unloadAPI("touchpoint")
  4. os.loadAPI("touchpoint")
  5. local monitorSide = "back"
  6. local wlmSide = "right"
  7. local rcSide = "top"
  8. -- Connecting Peripheral
  9. local wirelessModem = peripheral.wrap(wlmSide)
  10. local replyChannel = 1
  11. local listenChannel = 3
  12. --Fill this table with the names of mobs
  13. --local inputs = {"Zombie", "Enderman", "Wither Skeleton", "Peach Forager", "Creeper", "Blaze"}
  14. local inputs = {"Enderman"}
  15. local currMob = "NONE"
  16. local t = touchpoint.new(monitorSide)
  17. --Init
  18. spawnerStatus = false
  19. ligthStatus = false
  20. grinderStatus = false
  21. doorStatus = false
  22. exactSp = ""
  23.  
  24. function callTurtle(message,argument)
  25.   myMes={message=message, argument=argument}
  26.   mySerMes=textutils.serialize(myMes)
  27.   wirelessModem.transmit(3, 1, mySerMes)
  28.   wirelessModem.open(1)--Open channel 1 so that we can listen on it
  29.   --local event, modemSide, senderChannel, replyChannel, mySerMes, senderDistance = os.pullEvent("modem_message")
  30.   --myUnsMes=textutils.unserialize(mySerMes)
  31.   --print (myUnsMes)
  32.   --return myUnsMes
  33. end
  34.  
  35. function setMob2Spawn(mobId)
  36.   callTurtle("setMob2Spawn",mobId)
  37. end
  38.  
  39. function removeMob()
  40.   callTurtle("removeMob",0)
  41. end
  42.  
  43. function powerOnDrawBridge()
  44.   t:toggleButton("Door")
  45.   rs.setBundledOutput(rcSide,colors.orange)
  46.   if doorStatus == true then
  47.     print ("Door Opened")
  48.   else
  49.     print ("Door Closed")
  50.   end
  51.   sleep(0.5)
  52.   rs.setBundledOutput(rcSide,0)
  53.   doorStatus = not doorStatus
  54. end
  55. -- Check if this is really working
  56. function powerOnGrinder()
  57.   t:toggleButton("Grinder")
  58.   rs.setBundledOutput(rcSide,colors.red)
  59.   if grinderStatus == true then
  60.     print ("Grinder Activated")
  61.   else
  62.     print ("Grinder Deactivated")
  63.   end
  64.   sleep(0.5)
  65.   rs.setBundledOutput(rcSide,0)
  66.   grinderStatus = not grinderStatus
  67. end
  68.  
  69. function ligthSwitch()
  70.   t:toggleButton("Light")
  71.   rs.setBundledOutput(rcSide,colors.white)
  72.   if ligthStatus == true then
  73.     print ("Light Activated")
  74.   else
  75.     print ("Light Deactivated")
  76.   end
  77.   sleep(0.5)
  78.   rs.setBundledOutput(rcSide,0)
  79.   ligthStatus = not ligthStatus
  80. end
  81.  
  82. function powerOnSpawner()
  83.   t:toggleButton("Spawner")
  84.   rs.setBundledOutput(rcSide,colors.black)
  85.   if spawnerStatus == true then
  86.     print ("Spawner Activated")
  87.   else
  88.     print ("Spawner Deactivated")
  89.   end
  90.   sleep(0.5)
  91.   rs.setBundledOutput(rcSide,0)
  92.   spawnerStatus = not spawnerStatus
  93. end
  94.  
  95. function testCable()
  96.   rs.setBundledOutput(rcSide,0)
  97.   ligthStatus = rs.testBundledInput(rcSide, colors.magenta)
  98.   if ligthStatus == true then
  99.     t:toggleButton("Light")
  100.   end
  101.   doorStatus = rs.testBundledInput(rcSide, colors.lightBlue)
  102.   if doorStatus == true then
  103.     t:toggleButton("Door")
  104.   end
  105.   grinderStatus = rs.testBundledInput(rcSide, colors.yellow)
  106.   if grinderStatus == false then
  107.     t:toggleButton("Grinder")
  108.   end
  109.   spawnerStatus = rs.testBundledInput(rcSide, colors.lime)
  110.   if spawnerStatus == false then
  111.     t:toggleButton("Spawner")
  112.   end
  113. end
  114.  
  115. function creatingScreen()
  116.   local title="Light"  
  117.   local sx=2
  118.   local fx =(sx+#title+1)
  119.   t:add(title, ligthSwitch, sx, 2, fx, 4, colors.red, colors.lime)
  120.   title="Door"  
  121.   sx=fx+2
  122.   fx =(sx+#title+2)
  123.   t:add(title, powerOnDrawBridge, sx, 2, fx, 4, colors.red, colors.lime)
  124.   title="Grinder"  
  125.   sx=fx+2
  126.   fx =(sx+#title+2)
  127.   t:add(title, powerOnGrinder, sx, 2, fx, 4, colors.red, colors.lime)
  128.   title="Spawner"  
  129.   sx=fx+2
  130.   fx =(sx+#title+2)
  131.   t:add(title, powerOnSpawner, sx, 2, fx, 4, colors.red, colors.lime)
  132.   sx=2
  133.   sy=6
  134.   for mobId, mobName in pairs(inputs) do
  135.     fx= sx + #mobName + 1
  136.     fy=sy+2
  137.     t:add(mobName, function () setMob2Spawn(mobId) end, sx, sy, fx, fy, colors.red, colors.lime)
  138.     sx = fx + 2
  139.     if fx > 30 then
  140.       sx=2
  141.       sy=sy+4
  142.     end
  143.   end
  144. --print("Draw Menu")
  145.   t:draw()
  146. end
  147. --Run
  148. --print("Screen Creation")
  149. creatingScreen()
  150. testCable()
  151.  
  152. while true do
  153.   local event, p1 = t:handleEvents(os.pullEvent())
  154.   if event == "button_click" then
  155.     t.buttonList[p1].func()
  156.   end
  157.   if event == "modem_message" then
  158.   myUnsMes=textutils.unserialize(mySerMes)
  159.   print (myUnsMes)
  160.   end
  161. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement