Advertisement
Doob

dropper

Jul 9th, 2015
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. local side = 4
  2. local maxStack = 16
  3. local component = require('component')
  4. local event = require('event')
  5. local serialization = require('serialization')
  6. local redstone = component.redstone
  7. local chest = component.container_chest
  8.  
  9. local tLoot = {
  10.   {'stone', 1},
  11.   {'cobblestone', 16}
  12. }
  13.  
  14. local tBlackList = {
  15.   'Creeper',
  16.   'Bat',
  17.   'Slime',
  18.   'Skeleton',
  19.   'Spider',
  20.   'Zombie',
  21.   'Enderman',
  22.   'Witch',
  23.   'Pig',
  24.   'Sheep',
  25.   'Cow',
  26.   'Chicken',
  27.   'Wolf'
  28. }
  29.  
  30. local function saveTbl(tbl, fl)
  31.   file = io.open(fl, 'w')
  32.   file:write(serialization.serialize(tbl))
  33.   file:close()
  34. end
  35.  
  36. local function loadTbl(fl)
  37.   file = io.open(fl, 'r')
  38.   if not file then
  39.     file = io.open(fl, 'w')
  40.     file:write('{}')
  41.     return {}
  42.   else
  43.     return serialization.unserialize(file:read('*a'))
  44.   end
  45.   file:close()
  46. end
  47.  
  48. local function check(p)
  49.   for i = 1, #tBlackList do
  50.     if p == tBlackList[i] then
  51.       return false
  52.     end
  53.   end
  54.   return true
  55. end
  56.  
  57. local function findItem(fitem)
  58.   for j = 1, chest.getInventorySize() do
  59.     if chest.getStackInSlot(j) ~= nil then
  60.       if chest.getStackInSlot(j).name == fitem then
  61.         return true, j
  62.       end
  63.     end
  64.   end
  65. end
  66.  
  67. local function rsBlink(s, a)
  68.   for f = 1, a do
  69.     redstone.setOutput(s, 15)
  70.     os.sleep(0)
  71.     redstone.setOutput(s, 0)
  72.   end
  73. end
  74.  
  75. local tDate = loadTbl('players.log')
  76.  
  77. while true do
  78.   e, _, _, _, _, player = event.pull()
  79.   if e == 'motion' and check(player) then
  80.     if tDate[player] == nil then
  81.       tDate[player] = os.time()
  82.     end
  83.     if os.time() >= tDate[player] then
  84.       for k = 1, #tLoot do
  85.         status, slot = findItem(tLoot[k][1])
  86.         if status then
  87.           chest.pushItem(side, slot, tLoot[k][2])
  88.         end
  89.       end
  90.       saveTbl(tDate, 'players.log')
  91.       for l = 1, 9 do
  92.         rsBlink(2, maxStack)
  93.       end
  94.       tDate[player] = os.time()+6220800
  95.     end
  96.   elseif e == 'key_down' then
  97.     saveTbl(tDate, 'players.log')
  98.     break
  99.   end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement