nSun

CC ZombieLeader

Sep 4th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.29 KB | None | 0 0
  1. local iniFile = "/.settings/ZombieLeader"
  2. local test = os.getComputerID() == 21
  3. local LightController = peripheral.wrap(test and "computer_12" or "computer_608")
  4. local DisplayMonitor = test and "monitor_7" or "monitor_206"
  5.  
  6. if fs.exists(iniFile) then
  7.     settings.load(iniFile)
  8. end
  9. local state = settings.get("ZombieLeader.state",true)
  10. local light = settings.get("ZombieLeader.light",false)
  11. settings.set("ZombieLeader.state",state)
  12. settings.set("ZombieLeader.light",light)
  13. settings.save(iniFile)
  14.  
  15. local function setLight(b)
  16.     if b then
  17.         LightController.turnOn()
  18.     else
  19.         LightController.shutdown()
  20.     end
  21. end
  22.  
  23. rs.setOutput("top",state)
  24. setLight(light)
  25.  
  26. local mon = peripheral.wrap(DisplayMonitor)
  27. mon.setTextScale(1)
  28. local w,h = mon.getSize()
  29. local tw,th = term.getSize()
  30.  
  31. local function output(line,str)
  32.     term.setCursorPos(1,line)
  33.     term.clearLine()
  34.     term.write(str)
  35. end
  36.  
  37. local function strTime(sec)
  38.     sec = sec or os.clock()
  39.     local str,d,h,m,s=""
  40.     d=math.floor(sec/86400)
  41.     h=math.floor(sec/3600)%24
  42.     m=math.floor(sec/60)%60
  43.     s=math.floor(sec%60)
  44.     if d>0 then str = d>1 and d.." days " or "1 day" end
  45.     if h>0 then str = str..h.."h" end
  46.     if m>0 then str = str..(m>9 and m or "0"..m) end
  47.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  48.     return str
  49. end
  50. local eacute = string.char(233)
  51. local function stats(_d,_g,_z,_v,_m)
  52.     _d = _d or ""
  53.     _g = _g or ""
  54.     _z = _z or ""
  55.     _v = _v or ""
  56.     _m = _m or ""
  57.     local txt = {
  58.         "D"..eacute.."lai: ".._d,
  59.         "G"..eacute.."n"..eacute.."ration: ".._g,
  60.         "Zombie: ".._z,
  61.         "Villageois: ".._v,
  62.         "Mioche: ".._m,
  63.     }
  64.     local _y
  65.     for _y=1,#txt do
  66.         mon.setCursorPos(2,_y)
  67.         mon.clearLine()
  68.         mon.write(txt[_y])
  69.     end
  70. end
  71.  
  72. local function setC(fg,bg)
  73.     mon.setTextColor(fg)
  74.     mon.setBackgroundColor(bg)
  75. end
  76.  
  77. local function box()
  78.     mon.setCursorPos(2,6)
  79.     mon.clearLine()
  80.     setC(colors.black, colors.white)
  81.     mon.write(string.char(159)..string.rep(string.char(143),6))
  82.     setC(colors.white, colors.black)
  83.     mon.write(string.char(144))
  84.     local i
  85.     for i=7,11 do
  86.         mon.setCursorPos(2,i)
  87.         mon.clearLine()
  88.         if i%2==1 then
  89.             setC(colors.black, colors.white)
  90.             mon.write(string.char(149))
  91.             setC(colors.white, colors.black)
  92.             mon.write(string.rep(" ",6)..string.char(149))
  93.         else
  94.             setC(colors.black, colors.white)
  95.             mon.write(string.char(157)..string.rep(string.char(140),6))
  96.             setC(colors.white, colors.black)
  97.             mon.write(string.char(145))
  98.         end
  99.     end
  100.     mon.setCursorPos(2,12)
  101.     mon.clearLine()
  102.     mon.write(string.char(130)..string.rep(string.char(131),6)..string.char(129))
  103. end
  104.  
  105. --[[FT: 18x12
  106.      123456789012345678
  107. 1   > Délai:           <
  108. 2   > Génération:      <
  109. 3   > Zombie:          <
  110. 4   > Villageois:      <
  111. 5   > Mioche:          <
  112. 6   > +------+         <
  113. 7   > | Mode |tueur    <
  114. 8   > +------+         <
  115. 9   > |Turtle|attack   <
  116. 10  > +------+         <
  117. 11  > |Lampes|on       <
  118. 12  > +------+         <
  119. --]]
  120. local btn_txt = {
  121.     [7]= " Mode ",
  122.     [9]= "Turtle",
  123.     [11]="Lampes",
  124. }
  125.  
  126. local function btn(mouse_y)
  127.     mouse_y = mouse_y or 0
  128.     local ts=os.clock()
  129.     mon.setCursorPos(3,7)
  130.     setC(mouse_y==7 and colors.black or colors.gray, mouse_y==7 and colors.yellow or colors.lightGray)
  131.     mon.write(btn_txt[7])
  132.     mon.setCursorPos(3,9)
  133.     setC(mouse_y==9 and colors.black or colors.gray, mouse_y==9 and colors.yellow or colors.lightGray)
  134.     mon.write(btn_txt[9])
  135.     mon.setCursorPos(3,11)
  136.     setC(mouse_y==11 and colors.black or colors.gray, mouse_y==11 and colors.yellow or colors.lightGray)
  137.     mon.write(btn_txt[11])
  138.  
  139.     --(Mode) Switch Direction
  140.     if mouse_y==7 then
  141.         state = not state
  142.         rs.setOutput("top",state)
  143.         settings.set("ZombieLeader.state",state)
  144.         settings.save(iniFile)
  145.         mon.setCursorPos(10,7)
  146.         setC(colors.white,colors.black)
  147.         mon.write(state and "Trieur" or "Tueur ")
  148.     --(Turtle) Toggle On/Off Grinder
  149.     elseif mouse_y==9 then
  150.     --(Lampes) Toogle lights
  151.     elseif mouse_y==11 then
  152.         light = not light
  153.         setLight(light)
  154.         settings.set("ZombieLeader.light",light)
  155.         settings.save(iniFile)
  156.         mon.setCursorPos(10,11)
  157.         setC(colors.white,colors.black)
  158.         mon.write(light and "On " or "Off")
  159.     else
  160.         return
  161.     end
  162.     if os.clock()<ts+.1 then
  163.         sleep(.1)
  164.     end
  165.     mon.setCursorPos(3,mouse_y)
  166.     setC(colors.gray, colors.lightGray)
  167.     mon.write(btn_txt[mouse_y])
  168. end
  169.  
  170. local function header()
  171.     term.setBackgroundColor(colors.white)
  172.     term.setTextColor(colors.black)
  173.     output(1,"#"..os.getComputerID().." - "..os.getComputerLabel())
  174.     output(2,"Running: "..strTime())
  175.     term.setBackgroundColor(colors.black)
  176.     term.setTextColour(colors.gray)
  177.     output(3,string.rep(string.char(131),tw))
  178.     term.setTextColor(colors.white)
  179. end
  180.  
  181. term.clear()
  182. header()
  183. setC(colors.white,colors.black)
  184. stats()
  185. box()
  186. local t = os.startTimer(1)
  187. while true do
  188.     btn()
  189.     mon.setCursorPos(10,7)
  190.     setC(colors.white,colors.black)
  191.     mon.write(state and "Trieur" or "Tueur " )
  192.     mon.setCursorPos(10,11)
  193.     mon.setTextColor(LightController.isOn() and colors.white or colors.gray)
  194.     mon.write(LightController.isOn() and "On " or "Off")
  195.     mon.setTextColor(colors.white)
  196.  
  197.     local e,p,x,y = os.pullEventRaw()
  198.     if e=="terminate" then
  199.         print("")
  200.         print("/ZombieLeader - "..string.char(169).." SukaiPoppuGo")
  201.         error("Terminated",0)
  202.         return
  203.     elseif e=="timer" then
  204.         t = os.startTimer(1)
  205.         header()
  206.     --Toggle direction
  207.     elseif e=="monitor_touch" then
  208.         btn(y)
  209.     end
  210. end
Advertisement
Add Comment
Please, Sign In to add comment