Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- colony = peripheral.find("colonyIntegrator")
- mon = peripheral.wrap("left")
- function centerText(text, line, txtback, txtcolor, pos)
- monX, monY = mon.getSize()
- mon.setBackgroundColor(txtback)
- mon.setTextColor(txtcolor)
- length = string.len(text)
- dif = math.floor(monX-length)
- x = math.floor(dif/2)
- if pos == "head" then
- mon.setCursorPos(x+1, line)
- mon.write(text)
- elseif pos == "left" then
- mon.setCursorPos(2, line)
- mon.write(text)
- elseif pos == "right" then
- mon.setCursorPos(monX-length, line)
- mon.write(text)
- end
- end
- function prepareMonitor()
- mon.clear()
- mon.setTextScale(0.5)
- centerText("Citizens", 1, colors.black, colors.white, "head")
- end
- -- Function to capitalize the first letter of a string
- function capitalizeFirstLetter(str)
- return str:sub(1,1):upper() .. str:sub(2)
- end
- -- Function to remove the "com.minecolonies.building." prefix and capitalize the job name
- function formatJobName(job)
- local prefix = "com.minecolonies.building."
- if job:find(prefix) then
- job = job:sub(#prefix + 1) -- Remove the prefix
- job = capitalizeFirstLetter(job) -- Capitalize the first letter of the job name
- end
- return job
- end
- function printCitizens()
- row = 3
- useLeft = true
- for k, v in ipairs(colony.getCitizens()) do
- if row > 40 then
- useLeft = false
- row = 3
- end
- -- Ensure state is a string
- state = type(v.state) == "string" and v.state or "Unknown"
- -- Access job name from the 'work' table and format it
- job = v.work and v.work.name or "Unemployed"
- job = formatJobName(job) -- Remove the prefix and capitalize the job name
- -- Format location as "x, y, z" if location is a table
- if type(v.location) == "table" then
- location = string.format("x:%d y:%d z:%d", v.location.x or 0, v.location.y or 0, v.location.z or 0)
- else
- location = "Unknown"
- end
- -- Construct the full line based on the state
- if state == "Sick" then
- if useLeft then
- mon.setTextColor(colors.white)
- mon.setCursorPos(2, row)
- mon.write(v.name .. " - ")
- mon.setTextColor(colors.red)
- mon.write("Sick")
- mon.setTextColor(colors.white)
- mon.write(" - " .. job .. " - " .. location)
- else
- mon.setTextColor(colors.white)
- mon.setCursorPos(mon.getSize() - string.len(v.name .. " - ") - 1, row)
- mon.write(v.name .. " - ")
- mon.setTextColor(colors.red)
- mon.write("Sick")
- mon.setTextColor(colors.white)
- mon.setCursorPos(mon.getSize() - string.len("Sick" .. " - " .. job .. " - " .. location) - 1, row)
- mon.write(" - " .. job .. " - " .. location)
- end
- else
- if useLeft then
- centerText(v.name .. " - " .. state .. " - " .. job .. " - " .. location, row, colors.black, colors.white, "left")
- else
- centerText(v.name .. " - " .. state .. " - " .. job .. " - " .. location, row, colors.black, colors.white, "right")
- end
- end
- row = row+1
- end
- end
- prepareMonitor()
- while true do
- printCitizens()
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement