Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = peripheral.wrap("top")
- chat = peripheral.wrap("right")
- w,h = m.getSize()
- w = w+1
- h = h+1
- col = { ["white"]=1, ["orange"]=2, ["magenta"]=4, ["lightblue"]=8, ["yellow"]=16, ["lime"]=32, ["pink"]=64, ["gray"]=128, ["lightgray"]=256, ["cyan"]=512, ["purple"]=1024, ["blue"]=2048, ["brown"]=4096, ["green"]=8192, ["red"]=16384, ["black"]=32768 }
- popular = ""
- function printData()
- local path = shell.resolve("data")
- data = { [1] = textutils.serialize(names), [2] = textutils.serialize(deaths) }
- if fs.exists("data") then
- fs.delete("data")
- end
- local file = fs.open(path,"w")
- file.write(textutils.serialize(data))
- file.close()
- end
- function getData()
- local path = shell.resolve("data")
- if fs.exists("data") then
- local file = fs.open(path,"r")
- data = textutils.unserialize(file.readAll())
- names = textutils.unserialize(data[1])
- deaths = textutils.unserialize(data[2])
- return true
- else
- names = { [1] = "Fair" }
- deaths = { ["Fair"] = 0 }
- return false
- end
- end
- function swrite(str,x,y,color)
- m.setCursorPos(x,y)
- m.setTextColor(col[color])
- m.write(str)
- end
- function drawbox(str,x1,x2,y1,y2,strcol,color)
- m.setCursorPos(x1,y1)
- m.setBackgroundColor(col[color])
- m.setTextColor(col[strcol])
- local bw = x2-x1
- local bh = y2-y1
- local bstr = " "
- while #bstr < bw do
- bstr = bstr.." "
- end
- for i=1,bh do
- m.setCursorPos(x1,y1+i-1)
- m.write(bstr)
- end
- m.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
- m.write(str)
- m.setBackgroundColor(col["black"])
- return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
- end
- function drawbackground(str,strcol,color)
- drawbox("",1,w,1,h,strcol,color)
- drawbox("",2,w-1,2,h-1,"black","black")
- drawbox(str,1,w,1,2,strcol,color)
- end
- function printDeaths()
- m.clear()
- drawbackground("Death counter","black","white")
- for i=1,#names do
- swrite(names[i],3,2+i,"white")
- swrite(tostring(deaths[names[i]]),w-2-#tostring(deaths[i]),2+i,"white")
- end
- end
- getData()
- printDeaths()
- while true do
- event,pr1,pr2,pr3 = os.pullEvent()
- getData()
- print(tostring(event))
- print(tostring(pr1))
- if event == "chat_death" then
- print("Detected death.")
- for i=1,#names do
- if names[i] == pr1 then
- deaths[names[i]] = deaths[names[i]] + 1
- print("Found old name.")
- else
- table.insert(names,pr1)
- deaths[names[i]] = 1
- print("Added new name.")
- end
- end
- end
- printData()
- printDeaths()
- end
Advertisement
Add Comment
Please, Sign In to add comment