nSun

CC kill

Sep 4th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. --globals
  2. local iniFile="/.settings/kill"
  3.  
  4. --ini
  5. local align,mon,i=false
  6. for i=1,4 do
  7.     print("align")
  8.     mon = peripheral.wrap("back")
  9.     if not mon then
  10.         turtle.turnRight()
  11.     else
  12.         print("align confirm")
  13.         align = true
  14.         break
  15.     end
  16. end
  17.  
  18. if not align then
  19.     error("La turtle est désorientée.",0)
  20.     return
  21. end
  22.  
  23. if fs.exists(iniFile) then
  24.     settings.load(iniFile)
  25. end
  26. local state = settings.get("Kill.state",true)
  27. settings.set("Kill.state",state)
  28. settings.save(iniFile)
  29.  
  30. --display
  31. mon.setTextScale(1)
  32. local _w,_h = term.getSize()
  33. local w,h = mon.getSize()
  34. local function output(line,str,m)
  35.     m = m or term
  36.     m.setCursorPos(1,line)
  37.     m.clearLine()
  38.     m.write(str)
  39. end
  40. local function dots(str,n)
  41.     local c = math.floor(os.clock()*2)
  42.     return string.rep(str,c%n+1)
  43. end
  44. local function strTime(sec)
  45.     sec = sec or os.clock()
  46.     local str,d,h,m,s=""
  47.     d=math.floor(sec/86400)
  48.     h=math.floor(sec/3600)%24
  49.     m=math.floor(sec/60)%60
  50.     s=math.floor(sec%60)
  51.     if d>0 then str = d>1 and d.." days " or "1 day " end
  52.     if h>0 then str = str..h.."h" end
  53.     if m>0 then str = str..(m>9 and m or "0"..m) end
  54.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  55.     return str
  56. end
  57.  
  58. local function header()
  59.     term.setBackgroundColor(colors.white)
  60.     term.setTextColor(colors.black)
  61.     output(1,"#"..os.getComputerID().." - "..os.getComputerLabel())
  62.     output(2,"Running: "..strTime())
  63.     term.setBackgroundColor(colors.black)
  64.     term.setTextColour(colors.gray)
  65.     output(3,string.rep(string.char(131),_w))
  66.     term.setTextColor(colors.white)
  67. end
  68.  
  69. term.clear()
  70. header()
  71.  
  72. --process
  73. local function kill()
  74.     local continue = true
  75.     while continue do
  76.         local i,kick = 1,0
  77.         for i=1,4 do
  78.             output(4,"Attack"..dots("!",3))
  79.             mon.setCursorPos(10,9)
  80.             mon.setTextColor(colors.red)
  81.             mon.setBackgroundColor(colors.black)
  82.             mon.write("Attack"..dots("!",3).."   ")
  83.             mon.setTextColor(colors.white)
  84.             if turtle.attack() then
  85.                 kick = kick+1
  86.             end
  87.             header()
  88.             sleep(.5)
  89.         end
  90.         continue = kick>0
  91.     end
  92. end
  93.  
  94. while true do
  95.     if state and turtle.attack() then
  96.         kill()
  97.     end
  98.     header()
  99.     output(4,state and "Waiting" or "Off")
  100.     mon.setCursorPos(10,9)
  101.     mon.setTextColor(state and colors.white or colors.gray)
  102.     mon.setBackgroundColor(colors.black)
  103.     mon.write(state and "Waiting  " or "Off      ")
  104.     local t = os.startTimer(1)
  105.     local e,p,x,y = os.pullEventRaw()
  106.     if e=="terminate" then
  107.         print("")
  108.         print("/kill - "..string.char(169).." SukaiPoppuGo")
  109.         error("Terminated",0)
  110.         return
  111.     elseif e=="timer" then
  112.         header()
  113.     elseif e=="monitor_touch"
  114.     and p=="back"
  115.     and y == 9 then
  116.         state = not state
  117.         settings.set("Kill.state",state)
  118.         settings.save(iniFile)
  119.     end
  120. end
Advertisement
Add Comment
Please, Sign In to add comment