Ziplouff

CraftNet wood monitor v2

May 21st, 2015
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.60 KB | None | 0 0
  1. --OAK 105
  2. --SPRUCE 104
  3. mouseWidth = 0
  4. mouseHeight = 0
  5. rednet.open("bottom")
  6. monitor = peripheral.wrap("back")
  7. monitor.clear()
  8. monitor.setCursorPos(1,1)
  9. w,h=monitor.getSize()
  10. print(w)
  11. print(h)
  12.  
  13.  
  14. requestG = {"JungleG", "AcaciaG", "RubberG", "BirchG"}
  15. i=1
  16. bt1=false
  17. bt2=false
  18. bt3=false
  19. bt4=false
  20. can=false
  21. connected=false
  22. monitor.setBackgroundColour(colors.black)
  23.  
  24. function write(linex, liney, color, text)
  25.    monitor.setCursorPos(linex,liney)
  26.    monitor.clearLine()
  27.    monitor.setTextColor(color)
  28.    monitor.write(text)
  29.    monitor.setTextColor(colors.white)
  30. end
  31.  
  32. function request(id, message)
  33.    rednet.send(id, message)
  34. end
  35.  
  36. function Connected()
  37.    monitor.clear()
  38.    write(1, 1, colors.orange, "Connecting to DataServer:81...")
  39.    request(81, "isAlive")
  40.  
  41.    id, message = rednet.receive(5)
  42.  
  43.     if(id==81) then
  44.         if(message=="yes") then
  45.             connected=true
  46.             sleep(1)
  47.                 write(1, 2, colors.lime, "Connected !")
  48.             sleep(1)
  49.             write(1, 3, colors.orange, "Starting CraftNet:W_CONTROL..")
  50.             sleep(5)
  51.             getbtn()
  52.         end
  53.     end
  54.     if(connected==false) then
  55.         sleep(1)
  56.         write(1, 2, colors.red, "Error try again in 5seconds!")  
  57.         sleep(5)
  58.         Connected()
  59.     end
  60. end
  61.  
  62.  
  63. function getbtn()
  64.    
  65.   request(81, requestG[i])
  66.  
  67.   id, message = rednet.receive(5)
  68.  
  69.   if(id==81) then
  70.     if(message=="true") then
  71.       can=false
  72.       if(i==1) then
  73.          bt1ac()
  74.       elseif(i==2) then
  75.          bt2ac()
  76.       elseif(i==3) then
  77.          bt3ac()
  78.       elseif(i==4) then
  79.          bt4ac()
  80.       end
  81.     else
  82.       can=false
  83.       if(i==1) then
  84.          bt1inac()
  85.       elseif(i==2) then
  86.          bt2inac()
  87.       elseif(i==3) then
  88.          bt3inac()
  89.       elseif(i==4) then
  90.          bt4inac()
  91.       end
  92.     end
  93.   end
  94. if(i==4) then
  95. print(can)
  96. print(i)
  97. end
  98. if(i <= 4) then
  99.    i=i+1
  100.    getbtn()
  101. end
  102.  
  103. end -- end function getbtn
  104.  
  105. local function addcol(col, side)
  106.    rs.setBundledOutput(side, colors.combine(rs.getBundledOutput(side),col))
  107. end
  108. local function remcol(col, side)
  109.   rs.setBundledOutput(side, colors.subtract(rs.getBundledOutput(side),col))
  110. end
  111.  
  112.  
  113. function bt1inac()
  114. monitor.setBackgroundColour((colours.red))
  115. write(1, 1, colors.white, "INACTIVE : Jungle Wood")
  116. remcol(colors.white, "right")
  117. if(can==true) then
  118.   request(81, "Jungle")
  119. end
  120. bt1=false
  121. can=true
  122. monitor.setBackgroundColour(colors.black)
  123. --text
  124. end
  125.  
  126. function bt1ac()
  127. monitor.setBackgroundColour(colors.lime)
  128. write(1, 1, colors.white, "ACTIVE : Jungle Wood")
  129. addcol(colors.white, "right")
  130. if(can==true) then
  131. request(81, "Jungle")
  132. end
  133. bt1=true
  134. can=true
  135. monitor.setBackgroundColour(colors.black)
  136. end
  137.  
  138. function bt2inac()
  139. monitor.setBackgroundColour(colors.red)
  140. remcol(colors.yellow, "right")
  141. write(1, 2, colors.white, "INACTIVE : Acacia Wood")
  142. monitor.setBackgroundColour(colors.black)
  143. if(can==true) then
  144. request(81, "Acacia")
  145. end
  146. bt2=false
  147. can=true
  148. end
  149.  
  150. function bt2ac()
  151. monitor.setBackgroundColour(colors.lime)
  152. addcol(colors.yellow, "right")
  153. write(1, 2, colors.white, "ACTIVE : Acacia Wood")
  154. monitor.setBackgroundColour(colors.black)
  155.   if(can==true) then
  156.     request(81, "Acacia")
  157.   end
  158. bt2=true
  159. can=true
  160. end
  161.  
  162. function bt3inac()
  163. monitor.setBackgroundColour(colors.red)
  164. remcol(colors.lime, "right")
  165. write(1, 3, colors.white, "INACTIVE : Rubber Wood")
  166. monitor.setBackgroundColour(colors.black)
  167. if(can==true) then
  168. request(81, "Rubber")
  169. end
  170. bt3=false
  171. can=true
  172. end
  173.  
  174. function bt3ac()
  175. monitor.setBackgroundColour(colors.lime)
  176. addcol(colors.lime, "right")
  177. write(1, 3, colors.white, "ACTIVE : Rubber Wood")
  178. monitor.setBackgroundColour(colors.black)
  179.   if(can==true) then
  180.     request(81, "Rubber")
  181.   end
  182. bt3=true
  183. can=true
  184. end
  185.  
  186. function bt4inac()
  187. monitor.setBackgroundColour(colors.red)
  188. remcol(colors.pink, "right")
  189. write(1, 4, colors.white, "INACTIVE : Birch  Wood")
  190. monitor.setBackgroundColour(colors.black)
  191. if(can==true) then
  192. request(81, "Birch")
  193. end
  194. bt4=false
  195. can=true
  196. end
  197.  
  198. function bt4ac()
  199. monitor.setBackgroundColour(colors.lime)
  200. addcol(colors.pink, "right")
  201. write(1, 4, colors.white, "ACTIVE : Birch  Wood")
  202. monitor.setBackgroundColour(colors.black)
  203.   if(can==true) then
  204.     request(81, "Birch")
  205.   end
  206. bt4=true
  207. can=true
  208. end
  209.  
  210. monitor.setBackgroundColour((colours.black))
  211. --background screen color
  212.  
  213.  
  214. --START
  215. Connected()
  216.  
  217. function checkClickPosition()
  218.     print(can)
  219.   if mouseWidth > 0 and mouseWidth < 30 and mouseHeight == 1 then
  220.     -- button one clicked
  221.    if(bt1==false) then
  222.      bt1=true
  223.      addcol(colors.white, "right")
  224.      bt1ac()
  225.    else
  226.      bt1=false
  227.      remcol(colors.white, "right")
  228.      bt1inac()
  229.    end
  230.   elseif mouseWidth > 0 and mouseWidth <30 and mouseHeight == 2 then
  231.    if(bt2==false)then
  232.      bt2=true
  233.      addcol(colors.yellow, "right")
  234.      bt2ac()
  235.    else
  236.      bt2=false
  237.      remcol(colors.yellow, "right")
  238.      bt2inac()
  239.    end  
  240. elseif mouseWidth > 0 and mouseWidth <30 and mouseHeight == 3 then
  241.    if(bt3==false)then
  242.      bt3=true
  243.      addcol(colors.lime, "right")
  244.      bt3ac()
  245.    else
  246.      bt3=false
  247.      remcol(colors.lime, "right")
  248.      bt3inac()
  249.    end  
  250. elseif mouseWidth > 0 and mouseWidth <30 and mouseHeight == 4 then
  251.    if(bt4==false)then
  252.      bt4=true
  253.      addcol(colors.pink, "right")
  254.      bt4ac()
  255.    else
  256.      bt4=false
  257.      remcol(colors.pink, "right")
  258.      bt4inac()
  259.    end  
  260.   end -- ends the if loop
  261. end -- ends the function
  262.    
  263. repeat
  264.   event,p1,p2,p3 = os.pullEvent()
  265.    if event=="monitor_touch" then
  266.      mouseWidth = p2 -- sets mouseWidth
  267.      mouseHeight = p3 -- and mouseHeight
  268.      checkClickPosition() -- this runs our function
  269.    end
  270.  
  271. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment