Advertisement
SteamPunk_Devil

[Release]Tank Mon

Mar 1st, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.62 KB | None | 0 0
  1. --SteamPunk_Devil's Tank Monitor!
  2. print("SteamPunk_Devil's Tank Monitor V0.01")
  3. os.unloadAPI("API/steAmPI")
  4. os.loadAPI("API/steAmPI")
  5.  
  6. while true do
  7.     sleep(.1)
  8.  
  9.     local PeriList = peripheral.getNames()
  10.     local TankList = {}
  11.     local OtherPeriList = {}
  12.     local MonList = {}
  13.     --local o = 1
  14.     --local u = 1
  15.     --local m = 1
  16.     for i = 1, #PeriList do
  17.         if string.match(PeriList[i],"rcirontankvalvetile") then
  18.             TankList[#TankList + 1] = PeriList[i]
  19.             --u = u + 1
  20.         elseif string.match(PeriList[i],"monitor") then
  21.             MonList[#MonList + 1] = PeriList[i]
  22.             --m = m + 1
  23.         else
  24.             OtherPeriList[#OtherPeriList + 1] = PeriList[i]
  25.             --print(textutils.serialize(OtherPeriList))
  26.         end
  27.     end
  28.  
  29.    
  30.     local Tank1 = peripheral.wrap(TankList[1])
  31.     local Tank2 = peripheral.wrap(TankList[2])
  32.     local Tank3 = peripheral.wrap(TankList[3])
  33.     local Tank4 = peripheral.wrap(TankList[4])
  34.     local Mon = peripheral.wrap(MonList[1])
  35.      
  36.     local X1Pos = 2
  37.     local X2Pos =18
  38.     local Y1Pos = 2
  39.     local Y1BarPos = 3
  40.     local Y2Pos = 5
  41.     local Y2BarPos = 6
  42.  
  43.  
  44.     DoubleArray1 = Tank1.getTankInfo("unknown")  
  45.     SingleArray1 = DoubleArray1[1]
  46.  
  47.     DoubleArray2 = Tank2.getTankInfo("unknown")  
  48.     SingleArray2 = DoubleArray2[1]
  49.  
  50.     DoubleArray3 = Tank3.getTankInfo("unknown")  
  51.     SingleArray3 = DoubleArray3[1]
  52.  
  53.     DoubleArray4 = Tank4.getTankInfo("unknown")  
  54.     SingleArray4 = DoubleArray4[1]
  55.  
  56.  
  57.  
  58.     tank1 = SingleArray1
  59.     tank1["XPos"] = X1Pos
  60.     tank1["YPos"] = Y1Pos
  61.     tank1["YBarPos"] = Y1BarPos
  62.  
  63.  
  64.     tank2 = SingleArray2
  65.     tank2["XPos"] = X2Pos
  66.     tank2["YPos"] = Y1Pos
  67.     tank2["YBarPos"] = Y1BarPos
  68.  
  69.     tank3 = SingleArray3
  70.     tank3["XPos"] = X1Pos
  71.     tank3["YPos"] = Y2Pos
  72.     tank3["YBarPos"] = Y2BarPos
  73.  
  74.     tank4 = SingleArray4
  75.     tank4["XPos"] = X2Pos
  76.     tank4["YPos"] = Y2Pos
  77.     tank4["YBarPos"] = Y2BarPos
  78.  
  79.     Mon.clear()
  80.     if #TankList >= 1 then
  81.         steAmPI.FluPrinter(tank1)
  82.     else
  83.         Mon.setCursorPos(X1Pos, Y1Pos)
  84.         Mon.setTextColor(128)
  85.         Mon.write("  Empty   ")
  86.         Mon.setCursorPos(X1Pos, Y1BarPos)
  87.         Mon.setBackgroundColor(128)
  88.         Mon.write("          ")
  89.         Mon.setBackgroundColor(32768)
  90.     end
  91.  
  92.     if #TankList >= 2 then
  93.         steAmPI.FluPrinter(tank2)
  94.     else
  95.         Mon.setCursorPos(X2Pos, Y1Pos)
  96.         Mon.setTextColor(128)
  97.         Mon.write("  Empty   ")
  98.         Mon.setCursorPos(X2Pos, Y1BarPos)
  99.         Mon.setBackgroundColor(128)
  100.         Mon.write("          ")
  101.         Mon.setBackgroundColor(32768)
  102.     end
  103.  
  104.     if #TankList >= 3 then
  105.         steAmPI.FluPrinter(tank3)
  106.     else
  107.         Mon.setCursorPos(X1Pos, Y2Pos)
  108.         Mon.setTextColor(128)
  109.         Mon.write("  Empty   ")
  110.         Mon.setCursorPos(X1Pos, Y2BarPos)
  111.         Mon.setBackgroundColor(128)
  112.         Mon.write("          ")
  113.         Mon.setBackgroundColor(32768)
  114.     end
  115.  
  116.     if #TankList >= 4 then
  117.         steAmPI.FluPrinter(tank4)
  118.     else
  119.         Mon.setCursorPos(X2Pos, Y2Pos)
  120.         Mon.setTextColor(128)
  121.         Mon.write("  Empty   ")
  122.         Mon.setCursorPos(X2Pos, Y2BarPos)
  123.         Mon.setBackgroundColor(128)
  124.         Mon.write("          ")
  125.         Mon.setBackgroundColor(32768)
  126.     end
  127.     os.startTimer(0.2) --start the timer
  128.  
  129.     local MonTouch = {os.pullEvent()}
  130.         if MonTouch[1] == "monitor_touch" then
  131.             if MonTouch[3] >= X1Pos and MonTouch[3] <= X1Pos + 10 and MonTouch[4] >= Y1Pos and MonTouch[4] <= Y1Pos + 1 then
  132.                 OnPushData(tank1, Mon)
  133.             elseif MonTouch[3] >= X2Pos and MonTouch[3] <= X2Pos + 10 and MonTouch[4] >= Y1Pos and MonTouch[4] <= Y1Pos + 1 then
  134.                 OnPushData(tank2, Mon)
  135.             elseif MonTouch[3] >= X1Pos and MonTouch[3] <= X1Pos + 10 and MonTouch[4] >= Y2Pos and MonTouch[4] <= Y2Pos + 1 then
  136.                 OnPushData(tank3, Mon)
  137.             elseif MonTouch[3] >= X2Pos and MonTouch[3] <= X2Pos + 10 and MonTouch[4] >= Y2Pos and MonTouch[4] <= Y2Pos + 1 then
  138.                 OnPushData(tank4, Mon) 
  139.             else
  140.     end
  141.         else
  142.             --skip
  143.   end
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement