Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monitor = peripheral.wrap("top");
- file = fs.open("d.json","r");
- d = textutils.unserialize(file.readLine());
- file.close();
- function adddeath(deadmeat)
- local playerindex = nil;
- for i,plyr in pairs(d) do
- if plyr.p == deadmeat then
- playerindex = i;
- end
- end
- if not playerindex then
- playerindex = #d+1;
- d[playerindex] = { };
- d[playerindex].p = deadmeat;
- d[playerindex].d = 0;
- end
- d[playerindex].d = d[playerindex].d + 1;
- file = fs.open("d.json","w");
- file.writeLine(textutils.serialize(d));
- file.close();
- end
- function sortfn(a,b)
- return a.d > b.d;
- end
- function printlist()
- local ds = table.sort(d,sortfn);
- monitor.clear();
- monitor.setCursorPos(1,1);
- local i;
- monitor.write("Death Counter 3000");
- i = 2;
- for _,p in pairs(d) do
- monitor.setCursorPos(1,i);
- monitor.write(p.p);
- monitor.setCursorPos(17,i);
- monitor.write("|" .. p.d);
- i = i + 1;
- end
- end
- repeat
- printlist();
- _,p = os.pullEvent("chat_death");
- adddeath(p);
- until false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement