View difference between Paste ID: CujaEfHP and 6PExyY5p
SHOW: | | - or go back to the newest paste.
1
-- Mob Guestbook
2
-- by SukaiPoppuGo
3
--
4
-- Require mod plethora
5
--
6
-- Log mobs generated by mob_spawner
7
--
8
9
------------------------------
10
-- pause at startup
11
print("init")
12
sleep(os.clock()<2 and 2 or 0)
13
print("run")
14
15
------------------------------
16-
    1, 1,
16+
-- params
17-
    w, h-4,
17+
18-
    true
18+
19
20
------------------------------
21
-- datas
22
settings.load("guestbook")
23-
    1,h-4,
23+
24-
    w,4,
24+
25-
    true
25+
------------------------------
26
-- display
27
local book = window.create(
28
    term.current(),
29
    1,1, w,h-4, true
30
)
31
32
local output = window.create(
33
    term.current(),
34
    1,h-4, w,4, true
35
)
36
37
local function display()
38
    local old = term.redirect(book)
39
    term.setBackgroundColor(colors.white)
40
    term.setCursorPos(1,1)
41
    term.clear()
42
    for id,date in pairs(guestbook) do
43
        term.setTextColor(colors.gray)
44
        print(id)
45
        term.setTextColor(colors.black)
46
        print(date)
47
        term.setTextColour(colors.lightGray)
48
        print(" "..string.rep("-",w-2))
49
    end
50
    term.redirect(old)
51
end
52
53
------------------------------
54
-- peripherals
55
local p = peripheral.wrap("right")
56
local function scan()
57
    for i,mob in ipairs(p.sense()) do
58
        if mob.name == mobType
59
        and not guestbook[mob.id]
60
        and mob.y == 0
61
        and mob.x >= 1 and mob.x <= 2
62
        and mob.z >= 1 and mob.z <= 2
63
        then
64
            local old = term.redirect(output)
65
            term.setTextColor(colors.lightGray)
66
            print("New mob", mob.name, mob.displayName)
67
            print(mob.id)
68
            term.redirect(old)
69
            guestbook[mob.id] = string.format("day %s, at %s", os.day(), os.time())
70
            settings.set("guestbook", guestbook)
71
            settings.save("guestbook")
72
        end
73
    end
74
end
75
76
------------------------------
77
-- Main
78
repeat
79
    scan()
80
    display()
81
    book.redraw()
82
    output.redraw()
83
    sleep(20)
84
until false