SHOW:
|
|
- or go back to the newest paste.
| 1 | --different possible groupings and their | |
| 2 | --corresponding greetings | |
| 3 | - | local groupings = {
|
| 3 | + | |
| 4 | - | {"kaibochan"},
|
| 4 | + | |
| 5 | - | {"kaibochan", "sethrl"},
|
| 5 | + | local defaultText = "Welcome to Biopunk" |
| 6 | - | {"sethrl"},
|
| 6 | + | |
| 7 | - | {"N0LIF3RRE3"},
|
| 7 | + | |
| 8 | - | {"kaibochan", "N0LIF3RRE3"},
|
| 8 | + | ["scale"] = 1.5, |
| 9 | - | {"N0LIF3RRE3", "sethrl"},
|
| 9 | + | ["textColor"] = "lime", |
| 10 | - | {"kaibochan", "N0LIF3RRE3", "sethrl"},
|
| 10 | + | ["bgColor"] = "black", |
| 11 | } | |
| 12 | ||
| 13 | - | local greetings = {
|
| 13 | + | function findGroup(players, groupings) |
| 14 | - | "Welcome back, Kai", |
| 14 | + | local foundGroup |
| 15 | - | "Welcome, disciples", |
| 15 | + | |
| 16 | - | "Hey cutie ;-)", |
| 16 | + | --iterate through all different groups |
| 17 | - | "ICEJJPICK!?", |
| 17 | + | |
| 18 | - | "ADHD squad B-)", |
| 18 | + | foundGroup = true |
| 19 | - | "TWO CUTIES!?\nAT MY BASE!?", |
| 19 | + | |
| 20 | - | "What's up CS squad", |
| 20 | + | --iterate through names within the |
| 21 | --current group, checking for a | |
| 22 | --match, then printing the | |
| 23 | - | local settings = {
|
| 23 | + | --corresponding greeting |
| 24 | - | {
|
| 24 | + | if #players == #group then |
| 25 | - | ["scale"] = 1, |
| 25 | + | for j, name in ipairs(group) do |
| 26 | - | ["textColor"] = colors.lime, |
| 26 | + | if players[j] ~= name then |
| 27 | - | ["bgColor"] = colors.black, |
| 27 | + | |
| 28 | - | }, |
| 28 | + | |
| 29 | - | {
|
| 29 | + | |
| 30 | - | ["scale"] = 1, |
| 30 | + | |
| 31 | - | ["textColor"] = colors.yellow, |
| 31 | + | |
| 32 | - | ["bgColor"] = colors.black, |
| 32 | + | foundGroup = false |
| 33 | - | }, |
| 33 | + | |
| 34 | - | {
|
| 34 | + | |
| 35 | - | ["scale"] = 2, |
| 35 | + | if foundGroup then |
| 36 | - | ["textColor"] = colors.pink, |
| 36 | + | return i |
| 37 | - | ["bgColor"] = colors.black, |
| 37 | + | |
| 38 | - | }, |
| 38 | + | |
| 39 | - | {
|
| 39 | + | |
| 40 | - | ["scale"] = 2, |
| 40 | + | |
| 41 | - | ["textColor"] = colors.black, |
| 41 | + | function loadGreetingFiles() |
| 42 | - | ["bgColor"] = colors.white, |
| 42 | + | --load greeting data from files |
| 43 | - | }, |
| 43 | + | local fileGroupings = fs.open("groupings.txt", "r")
|
| 44 | - | {
|
| 44 | + | local groupings = textutils.unserialise(fileGroupings.readAll()) |
| 45 | - | ["scale"] = 2, |
| 45 | + | fileGroupings.close() |
| 46 | - | ["textColor"] = colors.red, |
| 46 | + | |
| 47 | - | ["bgColor"] = colors.black, |
| 47 | + | local fileGreetings = fs.open("greetings.txt", "r")
|
| 48 | - | }, |
| 48 | + | local greetings = textutils.unserialise(fileGreetings.readAll()) |
| 49 | - | {
|
| 49 | + | fileGreetings.close() |
| 50 | - | ["scale"] = 1, |
| 50 | + | |
| 51 | - | ["textColor"] = colors.red, |
| 51 | + | local fileGreetFormat = fs.open("greetFormat.txt", "r")
|
| 52 | - | ["bgColor"] = colors.white, |
| 52 | + | local settings = textutils.unserialise(fileGreetFormat.readAll()) |
| 53 | - | }, |
| 53 | + | fileGreetFormat.close() |
| 54 | - | {
|
| 54 | + | |
| 55 | - | ["scale"] = 1, |
| 55 | + | return groupings, greetings, settings |
| 56 | - | ["textColor"] = colors.lightBlue, |
| 56 | + | |
| 57 | - | ["bgColor"] = colors.black, |
| 57 | + | |
| 58 | - | }, |
| 58 | + | |
| 59 | local groupings, greetings, settings = loadGreetingFiles() | |
| 60 | ||
| 61 | --sort each grouping for easy comparison | |
| 62 | - | local defaultText = "Biopunk" |
| 62 | + | |
| 63 | table.sort(group) | |
| 64 | end | |
| 65 | - | ["scale"] = 2, |
| 65 | + | |
| 66 | - | ["textColor"] = colors.lime, |
| 66 | + | |
| 67 | - | ["bgColor"] = colors.black, |
| 67 | + | |
| 68 | playerDetector = peripheral.find("playerDetector")
| |
| 69 | ||
| 70 | while true do | |
| 71 | --only activate once every 1/8 of a second | |
| 72 | sleep(1/8) | |
| 73 | ||
| 74 | monitor.setCursorPos(1, 1) | |
| 75 | ||
| 76 | --get a sorted list of nearby players | |
| 77 | local players = playerDetector.getPlayersInCubic(3, 3, 3) | |
| 78 | table.sort(players) | |
| 79 | ||
| 80 | local group = findGroup(players, groupings) | |
| 81 | if group then | |
| 82 | monitor.setTextScale(settings[group].scale) | |
| 83 | monitor.setTextColor(colors[settings[group].textColor]) | |
| 84 | - | monitor.clear() |
| 84 | + | monitor.setBackgroundColor(colors[settings[group].bgColor]) |
| 85 | monitor.clear() | |
| 86 | ||
| 87 | monitor.write(greetings[group]) | |
| 88 | - | local players = playerDetector.getPlayersInCubic(2, 2, 2) |
| 88 | + | |
| 89 | --if no players nearby or no matching group found | |
| 90 | --display default text | |
| 91 | - | --if no players nearby, display default |
| 91 | + | |
| 92 | - | --text |
| 92 | + | |
| 93 | - | if #players == 0 then |
| 93 | + | monitor.setTextColor(colors[defaultSettings.textColor]) |
| 94 | monitor.setBackgroundColor(colors[defaultSettings.bgColor]) | |
| 95 | - | monitor.setTextColor(defaultSettings.textColor) |
| 95 | + | monitor.clear() |
| 96 | - | monitor.setBackgroundColor(defaultSettings.bgColor) |
| 96 | + | |
| 97 | monitor.write(defaultText) | |
| 98 | end | |
| 99 | - | local foundGroup |
| 99 | + | |
| 100 | end | |
| 101 | - | --iterate through all different groups |
| 101 | + | |
| 102 | - | for i, group in ipairs(groupings) do |
| 102 | + |