View difference between Paste ID: QRRD1d7g and R9h37KZa
SHOW: | | - or go back to the newest paste.
1
local wi = peripheral.find("WorldInterface")
2
3
local function printerCount()
4
  local h = wi.getBlockDatatags(-584,29,123)
5
  if h.datatags.id~="ccprinter" then
6
    error("Missing printer in coords -584,29,123",0)
7
    exit()
8
  end
9
  if #h.datatags.Items>=13 then
10
    --tous les slots sont occupés
11
    return 6
12
  elseif #h.datatags.Items==0 then
13
    --tous les slots sont vides
14
    return 0
15
  else
16
    local count,_,s = 0
17
    for _,s in pairs(h.datatags.Items) do
18
      if s.Slot >= 7 then
19
        count = count+1
20
      end
21
    end
22
    return count
23
  end
24
end
25
26
local function hopperCount()
27
  local h = wi.getBlockDatatags(-584,28,123)
28
  if h.datatags.id~="Hopper" then
29
    error("Missing hopper in coords -584,28,123",0)
30
    exit()
31
  end
32
  return #h.datatags.Items
33
end
34
35
local function printTickets()
36
  local count,i = 0
37
  while count < 5 do
38
    count = hopperCount()
39
    if count < 5 then
40
      for i=1,5-count do
41
        shell.run("/ticket")
42
      end
43
    end
44
  end
45
end
46
47
local e,p
48
local countdown = 0
49
local batch = os.startTimer(.1)
50
local tick = os.startTimer(1)
51
while true do
52
  term.setCursorPos(1,1)
53
  term.clear()
54
  term.write("Countdown: "..countdown)
55
  
56
  e,p = os.pullEvent("timer")
57
  if e=="timer" and p==batch then
58
    os.cancelTimer(tick)
59
    if printerCount()<6 then
60
      printTickets()
61
      countdown = 10
62
    else
63
      countdown = 40
64
    end
65
    batch = os.startTimer(countdown)
66
    tick = os.startTimer(1)
67
  elseif e=="timer" and p==tick then
68
    countdown = math.max(0,countdown-1)
69
    tick = os.startTimer(1)
70
  end
71
end