Grauly

CC_OMT Control v2

Jan 29th, 2020 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. local mon = peripheral.wrap("bottom")
  2.  
  3. local turrets = {
  4.     peripheral.wrap("OMTBase_4");
  5.     peripheral.wrap("OMTBase_5");
  6.     peripheral.wrap("OMTBase_6");
  7.     peripheral.wrap("OMTBase_7");
  8. }
  9.  
  10. local attackPlayers = false
  11. local attackMobs = true
  12. local attackNeutrals = false
  13.  
  14.  --function declaration
  15.  
  16. function clearMonitor()
  17.     mon.setTextColor(colors.white)
  18.     mon.clear()
  19.     mon.setCursorPos(1,1)
  20. end
  21.  
  22. function nextLine()
  23.     x,y = mon.getCursorPos()
  24.     mon.setCursorPos(1,y+1)
  25.     mon.setTextColor(colors.white)
  26. end
  27.  
  28. function toggleAttackPlayers()
  29.     local attack = not turrets[1].attacksPlayers()
  30.     for i=1, #turrets do
  31.         turrets[i].setAttacksPlayers(attack)
  32.     end
  33. end
  34.  
  35. function toggleAttackMobs()
  36.     local attack = not turrets[1].attacksMobs()
  37.     for i=1, #turrets do
  38.         turrets[i].setAttacksMobs(attack)
  39.     end
  40. end
  41.  
  42. function toggleAttackNeutrals()
  43.     local attack = not turrets[1].attacksNeutrals()
  44.     for i=1, #turrets do
  45.         turrets[i].setAttacksNeutrals(attack)
  46.     end
  47. end
  48.  
  49. function printTurretInfo()
  50.     for i=1, #turrets do
  51.         mon.write("Turret: "..i.." "..(math.floor(turrets[i].getEnergyStored()/turrets[i].getMaxEnergyStored()*10*100)/10).."% Energy Stored")
  52.         nextLine()
  53.     end
  54.     nextLine()
  55. end
  56.  
  57.  
  58.  
  59. function n()
  60.     if turrets[1].attacksNeutrals() == true then
  61.         return colors.green
  62.     else
  63.         return colors.red
  64.     end
  65. end
  66.  
  67. function p()
  68.     if turrets[1].attacksPlayers() == true then
  69.         return colors.green
  70.     else
  71.         return colors.red
  72.     end
  73. end
  74.  
  75. function m()
  76.     if turrets[1].attacksMobs() == true then
  77.         return colors.green
  78.     else
  79.         return colors.red
  80.     end
  81. end
  82.  
  83. --button Color Write
  84. function bCW(s,c)
  85.     mon.setBackgroundColor(c)
  86.     mon.write(s)
  87.     mon.setBackgroundColor(colors.black)
  88. end
  89.  
  90. function printControls()
  91.     --start printing at line 9
  92.     mon.setCursorPos(1,9)
  93.     mon.write("+--Neut--+-Players-+---Mob--+")
  94.     nextLine()
  95.     for i=1,2,1 do
  96.         mon.write("|")
  97.         bCW("        ",n())
  98.         mon.write("|")
  99.         bCW("         ",p())
  100.         mon.write("|")
  101.         bCW("        ",m())
  102.         mon.write("|")
  103.         nextLine()
  104.     end
  105.     mon.write("+--------+---------+--------+")
  106.     --meaning that the buttons are at: (2,10) -> (9,11) | (11,10) -> (19,11) | (21,10) - > (29,11)  (x,y)
  107. end
  108.  
  109. function routine()
  110.     clearMonitor()
  111.     printTurretInfo()
  112.     printControls()
  113.    
  114.    
  115.    
  116. end
  117.  
  118. while true do
  119.     local timer = os.startTimer(1)
  120.     local event,a1,a2,a3 = os.pullEvent()
  121.     if event == "timer" then
  122.         routine()
  123.     elseif event == "monitor_touch" then
  124.         routine()
  125.         local x = a2
  126.         local y = a3
  127.         if y == 10 or y == 11 then
  128.             if x >= 2 and x <= 11 then
  129.                 --Neutrals Button
  130.                 toggleAttackNeutrals()
  131.             elseif x >= 11 and x <= 19 then
  132.                 --Players Button
  133.                 toggleAttackPlayers()
  134.             elseif x >= 21 and x <= 29 then
  135.                 --Mobs Button
  136.                 toggleAttackMobs()
  137.             end
  138.         end
  139.     end
  140. end
Add Comment
Please, Sign In to add comment