SHOW:
|
|
- or go back to the newest paste.
1 | --This is just a test prorgam so I can get familiar with various computercraft peripherals. Please excuse the mess. | |
2 | ||
3 | -- load the API | |
4 | os.loadAPI("ocs/apis/sensor") | |
5 | ||
6 | ||
7 | ||
8 | -- Change the peripheral names accordingly | |
9 | -- Prox = sensor (requires a proximity card) | mon = monitor | glass = terminal glass bridge | printer = printer | |
10 | prox = sensor.wrap("top") | |
11 | mon = peripheral.wrap("left") | |
12 | glass = peripheral.wrap("right") | |
13 | -- Set this to 0 to disable printing | |
14 | printReadout = 1 | |
15 | printer = peripheral.wrap("bottom") | |
16 | ||
17 | -- get the targets | |
18 | local targets = prox.getTargets() | |
19 | ||
20 | --Redirects output to monitor | |
21 | term.redirect(mon) | |
22 | term.clear() | |
23 | term.setCursorPos(1,1) | |
24 | term.setTextColor(colors.yellow) | |
25 | print("Sensor Readout - Entities:") | |
26 | - | glass.addBox(400,1,80,40,0xFFFFFF, 0.2) |
26 | + | |
27 | - | glass.addText(400,2,"Radar Readout:", 0xF2B233) |
27 | + | |
28 | glass.clear() | |
29 | --List | |
30 | glass.addBox(348,1,180,200,0xFFFFFF, 0.2) | |
31 | glass.addText(350,2,"Radar Readout:", 0xF2B233) | |
32 | glassY = 12 | |
33 | - | printer.newPage() |
33 | + | |
34 | - | printer.setPageTitle("Radar Printout Page " .. pgCt) |
34 | + | |
35 | - | -- Y value tracker for printer - will start a new page once it gets to the bottom |
35 | + | |
36 | - | printY = 1 |
36 | + | |
37 | if printReadout == 1 then | |
38 | - | -- Updates the cursor position on the page = for printer |
38 | + | printer.newPage() |
39 | - | printer.setCursorPos(1,printY) |
39 | + | printer.setPageTitle("Radar Printout Page " .. pgCt) |
40 | -- Y value tracker for printer - will start a new page once it gets to the bottom | |
41 | printY = 1 | |
42 | ||
43 | -- Updates the cursor position on the page = for printer | |
44 | printer.setCursorPos(1,printY) | |
45 | end | |
46 | -- Checks if the page is full. If so, it starts a new page | |
47 | function printCheck () | |
48 | if printY > 21 then | |
49 | -- Ends the page | |
50 | printer.endPage() | |
51 | -- Adds one to the page counter | |
52 | pgCt = pgCt + 1 | |
53 | -- Starts a new page | |
54 | printer.newPage() | |
55 | printer.setPageTitle("Radar Printout Page " .. pgCt) | |
56 | -- Resets printer Y position to 1 | |
57 | printY = 1 | |
58 | printer.setCursorPos(1,printY) | |
59 | end | |
60 | end | |
61 | ||
62 | -- loop through targets from sensor | |
63 | for name, basicDetails in pairs(targets) do | |
64 | ||
65 | -- get more details about them | |
66 | - | glass.addText(400,glassY,"Found player: "..name, 0xBA8E23) |
66 | + | |
67 | -- Changes the text color to yellow if it lists a player. Otherwise, it's white | |
68 | - | printer.setCursorPos(1,printY) |
68 | + | |
69 | - | printer.write("Found player: "..name) |
69 | + | |
70 | - | printY = printY + 1 |
70 | + | |
71 | - | printCheck() |
71 | + | if printReadout == 1 then |
72 | printer.setCursorPos(1,printY) | |
73 | printer.write("Found player: "..name) | |
74 | printY = printY + 1 | |
75 | - | glass.addText(400,glassY,"Found entity: "..name, 0x000000) |
75 | + | printCheck() |
76 | end | |
77 | - | printer.setCursorPos(1,printY) |
77 | + | |
78 | - | printer.write("Found entity: "..name) |
78 | + | |
79 | - | printY = printY + 1 |
79 | + | |
80 | - | printCheck() |
80 | + | if printReadout == 1 then |
81 | printer.write("Found entity: "..name) | |
82 | printY = printY + 1 | |
83 | printCheck() | |
84 | end | |
85 | end | |
86 | - | glass.addText(400,glassY,"Health: "..moreDetails.Health, 0x000000) |
86 | + | |
87 | ||
88 | - | printer.setCursorPos(1,printY) |
88 | + | |
89 | - | printer.write("Health: "..moreDetails.Health) |
89 | + | |
90 | - | printY = printY + 1 |
90 | + | if printReadout == 1 then |
91 | - | printCheck() |
91 | + | printer.setCursorPos(1,printY) |
92 | printer.write("Health: "..moreDetails.Health) | |
93 | printY = printY + 1 | |
94 | - | glass.addText(400,glassY,"------", 0x000000) |
94 | + | printCheck() |
95 | end | |
96 | - | printer.setCursorPos(1,printY) |
96 | + | |
97 | - | printer.write("------") |
97 | + | |
98 | - | printY = printY + 1 |
98 | + | if printReadout == 1 then |
99 | - | printCheck() |
99 | + | printer.setCursorPos(1,printY) |
100 | printer.write("------") | |
101 | - | printer.endPage() |
101 | + | printY = printY + 1 |
102 | - | term.restore() |
102 | + | printCheck() |
103 | end | |
104 | end | |
105 | ||
106 | if printReadout == 1 then | |
107 | printer.endPage() | |
108 | end | |
109 | term.restore() | |
110 | ||
111 | function glassCheck() | |
112 | if glassY > 200 then | |
113 | sleep(5) | |
114 | glass.clear() | |
115 | glass.addBox(348,1,180,200,0xFFFFFF, 0.2) | |
116 | glass.addText(350,2,"Radar Readout:", 0xF2B233) | |
117 | glassY = 12 | |
118 | end | |
119 | end | |
120 | ||
121 | -- loop through targets from sensor | |
122 | for name, basicDetails in pairs(targets) do | |
123 | ||
124 | -- get more details about them | |
125 | local moreDetails = prox.getTargetDetails(name) | |
126 | -- Changes the text color to yellow if it lists a player. Otherwise, it's white | |
127 | if moreDetails.IsPlayer == nil then | |
128 | glass.addText(350,glassY,"Found ??????: "..name, 0xF2B233) | |
129 | glassY = glassY + 10 | |
130 | glassCheck() | |
131 | elseif moreDetails.IsPlayer == true then | |
132 | glass.addText(350,glassY,"Found player: "..name, 0xF2B233) | |
133 | glassY = glassY + 10 | |
134 | glassCheck() | |
135 | else | |
136 | glass.addText(350,glassY,"Found entity: "..name, 0x000000) | |
137 | glassY = glassY + 10 | |
138 | glassCheck() | |
139 | end | |
140 | ||
141 | -- print their health | |
142 | glass.addText(350,glassY,"Health: "..moreDetails.Health, 0x000000) | |
143 | glassY = glassY + 10 | |
144 | glassCheck() | |
145 | glass.addText(350,glassY,"------", 0x000000) | |
146 | glassY = glassY + 10 | |
147 | glassCheck() | |
148 | end | |
149 |