Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Startup Stuff
- m = peripheral.wrap("top")
- m.setTextScale(1.0 )
- -- End Startup Stuff
- function SortJob(a, b)
- return a["job"] < b["job"]
- end
- function FirstName(name)
- returnStr = ""
- for i=1, #name do
- local char = string.sub(name, i, i)
- if (char == " " or i == 9) then
- return returnStr
- end
- returnStr = returnStr .. char
- end
- return returnStr
- end
- function GetHappiness(happiness)
- local mult = 10 -- # of places
- happiness = math.floor(happiness * mult + 0.5) / mult
- if (happiness == 10.0) then
- m.setTextColor(colors.green)
- else
- m.setTextColor(colors.pink)
- end
- m.write(happiness)
- end
- function GetJobStatus(status)
- local statusText = {
- ["Working"] = "Working",
- ["Farming"] = "Working",
- ["Delivering"] = "Working",
- ["Mining"] = "Working",
- ["Composting"] = "Working",
- ["Searching for trees"] = "Working"
- }
- if (statusText[status] == nil) then
- m.setTextColor(colors.red)
- m.write(status)
- else
- m.setTextColor(colors.green)
- m.write(statusText[status])
- end
- end
- function SetJobColor(job)
- local jobColors = {
- ["Knight"] = colors.magenta,
- ["Courier"] = colors.yellow,
- ["Archer"] = colors.pink,
- ["Builder"] = colors.brown,
- ["Druid"] = colors.lime,
- ["Enchanter"] = colors.purple,
- ["Farmer"] = colors.cyan,
- ["Student"] = colors.orange,
- ["Researcher"] = colors.lightBlue
- }
- if (jobColors[job] == nil) then
- m.setTextColor(colors.blue)
- else
- m.setTextColor(jobColors[job])
- end
- end
- function ShowCitizens()
- m.clear()
- local counter = 1
- local row = 1
- local column = 1
- local citizens = colony.getCitizens()
- table.sort(citizens, SortJob)
- for _, citizen in ipairs(citizens) do
- local status = citizen["status"]
- if (row > 40) then
- row = 1
- column = 42
- end
- m.setCursorPos(column, row)
- m.setTextColor(colors.blue)
- m. write(FirstName(citizen["name"]))
- m.setCursorPos(column + 10, row)
- SetJobColor(citizen["job"])
- m.write(citizen["job"])
- m.setCursorPos(column + 30 , row)
- GetJobStatus(status)
- m.setCursorPos(column + 25, row)
- GetHappiness(citizen["happiness"])
- row = row + 1
- end
- end
- while true do
- ShowCitizens()
- sleep(5)
- end
Add Comment
Please, Sign In to add comment