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 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 GetBedDistance(bed, work)
- local bedY = bed["z"]
- local bedX = bed["x"]
- local workY = work["z"]
- local workX = work["x"]
- local distanceY = math.abs(workY-bedY)
- local distanceX = math.abs(workX-bedX)
- local distance = math.sqrt(distanceX^2 + distanceY^2)
- local mult = 10 -- # of decimal places
- distance = math.floor(distance * mult + 0.5) / mult
- m.setTextColor(colors.green)
- if (distance > 99) then
- m.setTextColor(colors.red)
- end
- if (distance > 75 and distance < 100) then
- m.setTextColor(colors.orange)
- end
- if (distance > 50 and distance < 76) then
- m.setTextColor(colors.yellow)
- end
- m.write(distance )
- 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"]
- local job = citizen["job"]
- if (job == "Knight" or job == "Druid" or job == "Archer" or job == "Archer Squire") then
- -- do Nothing
- else
- 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 + 25, row)
- GetBedDistance(citizen["home"]["location"], citizen["work"]["location"])
- row = row + 1
- end
- end
- end
- while true do
- ShowCitizens()
- sleep(5)
- end
Add Comment
Please, Sign In to add comment