nSun

CC ZombieLog

Sep 4th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.72 KB | None | 0 0
  1. local test = os.getComputerID() == 26
  2. local spawner = test and {x=-715,y=58,z=598} or {x=-586,y=13,z=132}
  3.  
  4. local drive = peripheral.wrap(test and "drive_1" or "drive_148")
  5. local dataDir = drive.getMountPath().."/"
  6. local mon = peripheral.wrap(test and "monitor_9" or "monitor_220")
  7. local display = peripheral.wrap(test and "monitor_7" or "monitor_206")
  8. local w,h = mon.getSize()
  9. local _w,_h = term.getSize()
  10.  
  11. local wi = peripheral.find("WorldInterface")
  12. local ed = peripheral.find("EntityDetector")
  13.  
  14. local function getBlockInfos(_x,_y,_z)
  15.     if wi.getBlockDatatags then
  16.         return wi.getBlockDatatags(_x,_y,_z)
  17.     else
  18.         return wi.getBlockInfos(_x,_y,_z)
  19.     end
  20. end
  21.  
  22. local function getEntityList(_r,_x,_y,_z)
  23.     if ed.getEntityListAdvanced then
  24.         return ed.getEntityListAdvanced(_r,_x,_y,_z)
  25.     else
  26.         return ed.getEntityList(_r,_x,_y,_z)
  27.     end
  28. end
  29.  
  30. local function output(line,str)
  31.     term.setCursorPos(1,line)
  32.     term.clearLine()
  33.     term.write(str)
  34. end
  35. local function strTime(sec)
  36.     sec = sec or os.clock()
  37.     local str,d,h,m,s=""
  38.     d=math.floor(sec/86400)
  39.     h=math.floor(sec/3600)%24
  40.     m=math.floor(sec/60)%60
  41.     s=math.floor(sec%60)
  42.     if d>0 then str = d>1 and d.." days " or "1 day " end
  43.     if h>0 then str = str..h.."h" end
  44.     if m>0 then str = str..(m>9 and m or "0"..m) end
  45.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  46.     return str
  47. end
  48.  
  49. local function header()
  50.     term.setBackgroundColor(colors.white)
  51.     term.setTextColor(colors.black)
  52.     output(1,"#"..os.getComputerID().." - "..os.getComputerLabel())
  53.     output(2,"Running: "..strTime())
  54.     term.setBackgroundColor(colors.black)
  55.     term.setTextColour(colors.gray)
  56.     output(3,string.rep(string.char(131),_w))
  57.     term.setTextColor(colors.white)
  58. end
  59.  
  60. term.clear()
  61. header()
  62. term.redirect(mon)
  63.  
  64. local function getSpawnerDelay()
  65.     local s = getBlockInfos(spawner.x,spawner.y,spawner.z)
  66.     return s.datatags.Delay
  67. end
  68.  
  69. local function displayLog(_x,_y,str)
  70.     display.setCursorPos(_x,_y)
  71.     display.setBackgroundColor(colors.black)
  72.     display.setTextColor(colors.white)
  73.     display.write(str)
  74. end
  75. displayLog(9,1,"          ")
  76. displayLog(14,2,"     ")
  77. displayLog(10,3,"         ")
  78. displayLog(14,4,"     ")
  79. displayLog(10,5,"         ")
  80.  
  81. local total = 0
  82. local batch = 0
  83. local prevDelay = 10000
  84. local tick = os.startTimer(.1)
  85. term.clear()
  86. term.setCursorPos(1,h-1)
  87. print("start")
  88. while true do
  89.     local delay = getSpawnerDelay()
  90.     displayLog(9,1,strTime(math.floor((delay/20)+.5)).."          ")
  91.     if prevDelay < delay then
  92.         batch = batch+1
  93.         displayLog(14,2,math.floor(batch).."     ")
  94.         local batchNo = "-"..batch.."-"
  95.         local padL = string.rep(" ",math.floor((w-string.len(batchNo))/2))
  96.         local padR = string.rep(" ",math.ceil((w-string.len(batchNo))/2))
  97.         term.setBackgroundColor(colors.gray)
  98.         term.write(padL..batchNo..padR)
  99.         term.setBackgroundColor(colors.black)
  100.         print()
  101.         sleep(.2)
  102.         --Scan mobs
  103.         local mobCount = {
  104.             zombie=0,
  105.             villager=0,
  106.             baby=0,
  107.         }
  108.         local mobs = getEntityList(7,spawner.x+.5,spawner.y-1.5,spawner.z+.5)
  109.         if #mobs>0 then
  110.             local count,i,mob=0
  111.             for i,mob in pairs(mobs) do
  112.                 if mob.name=="Zombie" then
  113.                     count = count+1
  114.                     local kind = ""
  115.                     local file = "zombie"
  116.                     if mob.datatags.IsChickenJockey then
  117.                         kind = "chickenJockey"
  118.                         file = file.."_chickenJockey"
  119.                         mobCount.baby=mobCount.baby+1
  120.                     elseif mob.datatags.IsBaby then
  121.                         kind = "baby "
  122.                         file = file.."_baby"
  123.                         mobCount.baby=mobCount.baby+1
  124.                     end
  125.                     if mob.datatags.IsVillager then
  126.                         kind = kind.."villager "
  127.                         file = file.."_villager"
  128.                         mobCount.villager=mobCount.villager+1
  129.                     end
  130.                     if not fs.exists(dataDir..file) then
  131.                         local fh = fs.open(dataDir..file,"w")
  132.                         fh.write(textutils.serialise(mob))
  133.                         fh.close()
  134.                     end
  135.                     if kind == "" then
  136.                         kind = "zombie"
  137.                         mobCount.zombie=mobCount.zombie+1
  138.                     end
  139.                     print(kind)
  140.                 end
  141.             end
  142.             displayLog(10,3,math.floor(mobCount.zombie).."         ")
  143.             displayLog(14,4,math.floor(mobCount.villager).."     ")
  144.             displayLog(10,5,math.floor(mobCount.baby).."         ")
  145.             local x,y = term.getCursorPos()
  146.             total = total + count
  147.             term.setCursorPos(1,h)
  148.             term.setBackgroundColor(colors.white)
  149.             term.setTextColor(colors.black)
  150.             term.clearLine()
  151.             term.write("Total: "..total)
  152.             term.setBackgroundColor(colors.black)
  153.             term.setTextColor(colors.white)
  154.             term.setCursorPos(x,y)
  155.         end
  156.     end
  157.     prevDelay = delay
  158.     tick = os.startTimer(1)
  159.     e = os.pullEventRaw()
  160.     if e=="terminate" then
  161.         term.redirect(term.native())
  162.         term.setCursorPos(1,5)
  163.         print("/log - "..string.char(169).." SukaiPoppuGo")
  164.         error("Terminated",0)
  165.         return
  166.     elseif e=="timer" then
  167.         term.redirect(term.native())
  168.         header()
  169.         term.redirect(mon)
  170.     end
  171. end
Add Comment
Please, Sign In to add comment