Advertisement
Guest User

test

a guest
Feb 21st, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. local modem = peripheral.wrap("top")
  2. local mon = peripheral.wrap("back")
  3. local datei = "ranks2"
  4.  
  5. mon.clear()
  6. function startb()
  7.   while true do
  8.     ranktable()
  9.     receive()
  10.   end
  11.   --out()
  12. end
  13. function addRank(pl,po)
  14.   ranks = load(datei)
  15.   if ranks[pl] < po then
  16.     ranks[pl] = po
  17.   end
  18.   save(ranks,datei)
  19.   print(textutils.serialize(ranks))
  20.   ranktable()
  21. end
  22.  
  23. function receive()
  24.   pla = receivePlayer()
  25.   poi = receivePoints()
  26.   if pla ~= "" then
  27.     addRank(pla,poi)
  28.   end
  29.   mon.write(pla..": "..poi)
  30. end
  31. function receivePlayer()
  32.   modem.open(5,6)
  33.     local event, a,b,c,d,e = os.pullEvent("modem_message")
  34.     return (d)
  35. end
  36. function receivePoints()
  37.   modem.open(6)
  38.     local event, a,b,c,d,e = os.pullEvent("modem_message")
  39.     return d
  40. end
  41.  
  42. function save(table, datei)
  43.   file = fs.open(datei, "w")
  44.   file.write(textutils.serialize(table))
  45.   file.close()
  46. end
  47. function load(datei)
  48.   file = fs.open(datei, "r")
  49.   data = file.readAll()
  50.   file.close()
  51.   --return(data)
  52.   return textutils.unserialize(data)
  53. end
  54.  
  55. function ranktable()
  56.   mon.setTextScale(0.5)
  57.   t1 = load(datei)
  58.   --table.sort(t1,v)
  59.   --table.sort(t1, function(a,b) return a[2] > b[2] end)
  60.   --table.sortReally(t1)
  61.   --print(textutils.serialize(t1))
  62.   li = 1
  63.   for i, v in pairs(t1) do
  64.    mon.setCursorPos(1,li)
  65.    mon.write(i..": "..v.."Punkte")
  66.    li= li+1
  67.    mon.setCursorPos(1,li)
  68.    mon.write("-------------")
  69.    li=li+1
  70.    
  71.  
  72.   end
  73. end
  74.  
  75.  
  76.  
  77.  
  78. function table.sortReally(table)
  79.   return (bubbleSort(table) or table)
  80. end
  81. function bubbleSort(table)
  82.   if (#table >1) then
  83.     for i = 1, #table do
  84.       for j = 2, #table do
  85.         if(table[j] < table[j-1]) then
  86.           temp = table[j-1]
  87.           table[j-1] = table[j]
  88.           table[j] = temp
  89.         end
  90.       end
  91.     end
  92.   end
  93.   return table
  94. end
  95. --ranktable()
  96. --receive()
  97.  
  98. --###############
  99. --##
  100. --###############
  101. function out()
  102. local CONTENT = {}
  103. CONTENT.Azula = 12
  104. CONTENT.Sakril3G = 12
  105. --  CONTENT[1] = {}
  106. --  CONTENT[1]["name"] ="Azula"
  107. --  CONTENT[1]["points"] = 23
  108. --  CONTENT[2] = {}
  109. --  CONTENT[2]["name"] = "Sakril3G"
  110. --  CONTENT[2]["points"]= 22
  111. --table.insert(CONTENT,22,"Azula")
  112. --table.insert(CONTENT,28,"Sakril3G")
  113. --table.insert(CONTENT,45,"Knoom")
  114. --CONTENT.22 = Azula85
  115. --CONTENT.28 = Sakril3G
  116. file = fs.open("ranks2", "w")
  117. file.write(textutils.serialize(CONTENT))
  118. file.close()
  119.  
  120. print(textutils.serialize(CONTENT))
  121.  
  122. end
  123. --out()
  124. --###########
  125. function out2()
  126. CONTENT = {}
  127. i = 1
  128. while readed == "yes" do
  129.  line = h.readLine()
  130.  if line ~= "" then
  131.    table.insert(content[i] ,line)
  132.    i = i+1
  133.    sleep(0.1)
  134.  else
  135.    readed = "yes"
  136.  end
  137.  
  138. end
  139.  
  140. --mon.write(content)
  141.  
  142. for i=1,#CONTENT, 1 do
  143.   mon.write(CONTENT[i])
  144. end
  145. end
  146. --#############
  147.  
  148. startb()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement