Advertisement
Guest User

farm.lua

a guest
Mar 29th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local event = require("event")
  2. local fs = require('filesystem')
  3. local component = require("component")
  4. local m = component.modem
  5. local sides = require("sides")
  6. local colors = require("colors")
  7. local ae = require("ae")
  8. local timerID = -1
  9. local rsSignal = {0, 25, 52, 77, 98}
  10. local config = {}
  11.  
  12. function start(msg)
  13.   if (timerID ~= -1) then
  14.     print("Already running")
  15.     return
  16.   end
  17.   timerID =  event.timer(30, tick, math.huge)
  18.   c = loadConfig()
  19.   config = c or {}
  20. end
  21.  
  22. function stop(msg)
  23.   if (timerID == -1) then
  24.     print("Not running")
  25.     return
  26.   end
  27.   event.cancel(timerID)
  28.   timerID = -1
  29. end
  30.  
  31. function getSapling()
  32.   item = ae.getItem("Forestry:sapling", 0) or {}
  33.   return item.size or 0
  34. end
  35.  
  36. function updateFarm()
  37.   wood = getSapling()
  38.   if(wood >= 40000) then
  39.     m.broadcast(500, 4)
  40.     return
  41.   end
  42.   if(wood >= 30000) then
  43.     m.broadcast(500, 3)
  44.     return
  45.   end
  46.   if(wood >= 20000) then
  47.     m.broadcast(500, 2)
  48.     return
  49.   end
  50.   if(wood >= 10000) then
  51.     m.broadcast(500, 1)
  52.     return
  53.   end
  54.   m.broadcast(500, 0)
  55. end
  56.  
  57. function tick()
  58.   updateFarm()
  59. end
  60.  
  61. function loadConfig()
  62.   local env = {}
  63.   local result, reason = loadfile('/etc/farm.cfg', 't', env)
  64.   if result then
  65.     result, reason = xpcall(result, debug.traceback)
  66.     if result then
  67.       return env
  68.     end
  69.   end
  70.   return nil, reason
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement