Advertisement
TheDieselPunk

Untitled

Sep 3rd, 2024 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. colony = peripheral.find("colonyIntegrator")
  2. mon = peripheral.wrap("left")
  3.  
  4. function centerText(text, line, txtback, txtcolor, pos)
  5.     monX, monY = mon.getSize()
  6.     mon.setBackgroundColor(txtback)
  7.     mon.setTextColor(txtcolor)
  8.     length = string.len(text)
  9.     dif = math.floor(monX-length)
  10.     x = math.floor(dif/2)
  11.  
  12.     if pos == "head" then
  13.         mon.setCursorPos(x+1, line)
  14.         mon.write(text)
  15.     elseif pos == "left" then
  16.         mon.setCursorPos(2, line)
  17.         mon.write(text)
  18.     elseif pos == "right" then
  19.         mon.setCursorPos(monX-length, line)
  20.         mon.write(text)
  21.     end
  22. end
  23.  
  24. function prepareMonitor()
  25.     mon.clear()
  26.     mon.setTextScale(0.5)
  27.     centerText("Citizens", 1, colors.black, colors.white, "head")
  28. end
  29.  
  30. -- Function to capitalize the first letter of a string
  31. function capitalizeFirstLetter(str)
  32.     return str:sub(1,1):upper() .. str:sub(2)
  33. end
  34.  
  35. -- Function to remove the "com.minecolonies.building." prefix and capitalize the job name
  36. function formatJobName(job)
  37.     local prefix = "com.minecolonies.building."
  38.     if job:find(prefix) then
  39.         job = job:sub(#prefix + 1)  -- Remove the prefix
  40.         job = capitalizeFirstLetter(job)  -- Capitalize the first letter of the job name
  41.     end
  42.     return job
  43. end
  44.  
  45. function printCitizens()
  46.     row = 3
  47.     useLeft = true
  48.     for k, v in ipairs(colony.getCitizens()) do
  49.         if row > 40 then
  50.             useLeft = false
  51.             row = 3
  52.         end
  53.  
  54.         -- Ensure state is a string
  55.         state = type(v.state) == "string" and v.state or "Unknown"
  56.  
  57.         -- Access job name from the 'work' table and format it
  58.         job = v.work and v.work.name or "Unemployed"
  59.         job = formatJobName(job)  -- Remove the prefix and capitalize the job name
  60.  
  61.         -- Format location as "x, y, z" if location is a table
  62.         if type(v.location) == "table" then
  63.             location = string.format("x:%d y:%d z:%d", v.location.x or 0, v.location.y or 0, v.location.z or 0)
  64.         else
  65.             location = "Unknown"
  66.         end
  67.  
  68.         -- Construct the full line based on the state
  69.         if state == "Sick" then
  70.             if useLeft then
  71.                 mon.setTextColor(colors.white)
  72.                 mon.setCursorPos(2, row)
  73.                 mon.write(v.name .. " - ")
  74.                 mon.setTextColor(colors.red)
  75.                 mon.write("Sick")
  76.                 mon.setTextColor(colors.white)
  77.                 mon.write(" - " .. job .. " - " .. location)
  78.             else
  79.                 mon.setTextColor(colors.white)
  80.                 mon.setCursorPos(mon.getSize() - string.len(v.name .. " - ") - 1, row)
  81.                 mon.write(v.name .. " - ")
  82.                 mon.setTextColor(colors.red)
  83.                 mon.write("Sick")
  84.                 mon.setTextColor(colors.white)
  85.                 mon.setCursorPos(mon.getSize() - string.len("Sick" .. " - " .. job .. " - " .. location) - 1, row)
  86.                 mon.write(" - " .. job .. " - " .. location)
  87.             end
  88.         else
  89.             if useLeft then
  90.                 centerText(v.name .. " - " .. state .. " - " .. job .. " - " .. location, row, colors.black, colors.white, "left")
  91.             else
  92.                 centerText(v.name .. " - " .. state .. " - " .. job .. " - " .. location, row, colors.black, colors.white, "right")
  93.             end
  94.         end
  95.         row = row+1
  96.     end
  97. end
  98.  
  99. prepareMonitor()
  100.  
  101. while true do
  102.     printCitizens()
  103.     sleep(10)
  104. end
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement