balloonanimal

colony people list

Sep 1st, 2023 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. ---
  2. --- Made for the Advanced Peripherals documentation
  3. --- Created by Srendi - Created by Srendi - https://github.com/SirEndii
  4. --- DateTime: 25.04.2021 20:44
  5. --- Link: https://docs.srendi.de/peripherals/colony_integrator/
  6. ---
  7.  
  8.  
  9. colony = peripheral.find("colonyIntegrator")
  10. mon = peripheral.wrap("left")
  11.  
  12. function centerText(text, line, txtback, txtcolor, pos)
  13.     monX, monY = mon.getSize()
  14.     mon.setBackgroundColor(txtback)
  15.     mon.setTextColor(txtcolor)
  16.     length = string.len(text)
  17.     dif = math.floor(monX-length)
  18.     x = math.floor(dif/2)
  19.    
  20.     if pos == "head" then
  21.         mon.setCursorPos(x+1, line)
  22.         mon.write(text)
  23.     elseif pos == "left" then
  24.         mon.setCursorPos(2, line)
  25.         mon.write(text)
  26.     elseif pos == "right" then
  27.         mon.setCursorPos(monX-length, line)
  28.         mon.write(text)
  29.     end
  30. end
  31.  
  32. function prepareMonitor()
  33.     mon.clear()
  34.     mon.setTextScale(0.5)
  35.     centerText("Citizens", 1, colors.black, colors.white, "head")
  36. end
  37.  
  38. function printCitizens()
  39.     row = 3
  40.     useLeft = true
  41.     for k, v in ipairs(colony.getCitizens()) do
  42.         if row > 40 then
  43.             useLeft = false
  44.             row = 3
  45.         end
  46.        
  47.         gender = ""
  48.         if v.gender == "male" then
  49.             gender = "M"
  50.         else
  51.             gender = "F"
  52.         end
  53.        
  54.         if useLeft then
  55.             centerText(v.name.. " - ".. gender, row, colors.black, colors.white, "left")        
  56.         else
  57.             centerText(v.name.. " - ".. gender, row, colors.black, colors.white, "right")
  58.         end
  59.         row = row+1
  60.     end
  61. end
  62.  
  63. prepareMonitor()
  64.  
  65. while true do
  66.     printCitizens()
  67.     sleep(10)
  68. end
Add Comment
Please, Sign In to add comment