Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("top")
- local mon = peripheral.wrap("back")
- local datei = "ranks2"
- mon.clear()
- function startb()
- while true do
- ranktable()
- receive()
- end
- --out()
- end
- function addRank(pl,po)
- ranks = load(datei)
- if ranks[pl] < po then
- ranks[pl] = po
- end
- save(ranks,datei)
- print(textutils.serialize(ranks))
- ranktable()
- end
- function receive()
- pla = receivePlayer()
- poi = receivePoints()
- if pla ~= "" then
- addRank(pla,poi)
- end
- mon.write(pla..": "..poi)
- end
- function receivePlayer()
- modem.open(5,6)
- local event, a,b,c,d,e = os.pullEvent("modem_message")
- return (d)
- end
- function receivePoints()
- modem.open(6)
- local event, a,b,c,d,e = os.pullEvent("modem_message")
- return d
- end
- function save(table, datei)
- file = fs.open(datei, "w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function load(datei)
- file = fs.open(datei, "r")
- data = file.readAll()
- file.close()
- --return(data)
- return textutils.unserialize(data)
- end
- function ranktable()
- mon.setTextScale(0.5)
- t1 = load(datei)
- --table.sort(t1,v)
- --table.sort(t1, function(a,b) return a[2] > b[2] end)
- --table.sortReally(t1)
- --print(textutils.serialize(t1))
- li = 1
- for i, v in pairs(t1) do
- mon.setCursorPos(1,li)
- mon.write(i..": "..v.."Punkte")
- li= li+1
- mon.setCursorPos(1,li)
- mon.write("-------------")
- li=li+1
- end
- end
- function table.sortReally(table)
- return (bubbleSort(table) or table)
- end
- function bubbleSort(table)
- if (#table >1) then
- for i = 1, #table do
- for j = 2, #table do
- if(table[j] < table[j-1]) then
- temp = table[j-1]
- table[j-1] = table[j]
- table[j] = temp
- end
- end
- end
- end
- return table
- end
- --ranktable()
- --receive()
- --###############
- --##
- --###############
- function out()
- local CONTENT = {}
- CONTENT.Azula = 12
- CONTENT.Sakril3G = 12
- -- CONTENT[1] = {}
- -- CONTENT[1]["name"] ="Azula"
- -- CONTENT[1]["points"] = 23
- -- CONTENT[2] = {}
- -- CONTENT[2]["name"] = "Sakril3G"
- -- CONTENT[2]["points"]= 22
- --table.insert(CONTENT,22,"Azula")
- --table.insert(CONTENT,28,"Sakril3G")
- --table.insert(CONTENT,45,"Knoom")
- --CONTENT.22 = Azula85
- --CONTENT.28 = Sakril3G
- file = fs.open("ranks2", "w")
- file.write(textutils.serialize(CONTENT))
- file.close()
- print(textutils.serialize(CONTENT))
- end
- --out()
- --###########
- function out2()
- CONTENT = {}
- i = 1
- while readed == "yes" do
- line = h.readLine()
- if line ~= "" then
- table.insert(content[i] ,line)
- i = i+1
- sleep(0.1)
- else
- readed = "yes"
- end
- end
- --mon.write(content)
- for i=1,#CONTENT, 1 do
- mon.write(CONTENT[i])
- end
- end
- --#############
- startb()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement