southpole

Deathcounter

Jul 7th, 2013
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.90 KB | None | 0 0
  1. --Info Board by Southp0le
  2. --adjusted for 6x8 Advanced Monitor
  3. --Main Monitor Coordinates:
  4. ----x:=[1,55]
  5. ----y:=[1,27]
  6. --Touch Monitor Coordinates:
  7. ----x:=[1,80]
  8. ----y:=[1,5]
  9. --working, but a giant mess in the code.. => work =(
  10.  
  11.  
  12.  
  13. ---------------------
  14. -------Options-------
  15. ---------------------
  16.  
  17. os.loadAPI("buttonAPI")
  18. local serverAdmin = "Guracao"
  19. local boardAdmin = "Southp0le"
  20. local mon = peripheral.wrap("monitor_1")
  21. local mon2 = peripheral.wrap("top")
  22. local chat = peripheral.wrap("bottom")
  23. local mod = peripheral.wrap("back")
  24. local det = peripheral.wrap("playerDetector_1")
  25. local filled
  26. local page = 1
  27. local pages = 1
  28. local showed
  29. local listSorted = {}
  30. local numbersSorted = {}
  31. local deathReasonsSorted = {}
  32. local killNumbersSorted = {}
  33. local list = {}
  34. local numbers = {}
  35. local deathReasons = {}
  36. local killNumbers = {}
  37. mon.setTextColor(colors.black)
  38. mon.setBackgroundColor(colors.lightBlue)
  39. mon.setTextScale(1.5)
  40. mon2.setTextColor(colors.black)
  41. mon2.setBackgroundColor(colors.lightBlue)
  42. mon2.setTextScale(1)
  43.  
  44.  
  45. -----------------------
  46. -------Functions-------
  47. -----------------------
  48. function table.copy(t)
  49.   local t2 = {};
  50.   for k,v in pairs(t) do
  51.     if type(v) == "table" then
  52.         t2[k] = table.copy(v);
  53.     else
  54.         t2[k] = v;
  55.     end
  56.   end
  57.   return t2;
  58. end
  59. ----------------
  60. --file control--
  61. ----------------
  62.  
  63. --saves the file
  64. function saveFile(filename)
  65.   local file = fs.open(filename,"w")
  66.   if filename == "list1" then
  67.     listSorted = table.copy(list)
  68.     file.write(textutils.serialize(list))
  69.     file.close()
  70.     print("File '"..filename.."' saved.")
  71.     refresh()
  72.     return true
  73.   elseif filename == "numbers" then
  74.     file.write(textutils.serialize(numbers))
  75.     file.close()
  76.     print("File '"..filename.."' saved.")
  77.     refresh()
  78.     return true
  79.   elseif filename == "deathReasons" then
  80.     deathReasonsSorted = table.copy(deathReasons)
  81.     file.write(textutils.serialize(deathReasons))
  82.     file.close()
  83.     print("File '"..filename.."' saved.")
  84.     refresh()
  85.     return true
  86.   elseif filename == "killNumbers" then
  87.     file.write(textutils.serialize(killNumbers))
  88.     file.close()
  89.     print("File '"..filename.."' saved.")
  90.     refresh()
  91.     return true
  92.  elseif filename == "coords" then
  93.     file.write(textutils.serialize(coords))
  94.     file.close()
  95.     print("File '"..filename.."' saved.")
  96.     refresh()
  97.     return true
  98.   else
  99.     return false
  100.   end
  101. end
  102.  
  103. --loads the file and returns the file
  104. function loadFile(filename)
  105.   local file = fs.open(filename,"r")
  106.   local data = file.readAll()
  107.   file.close()
  108.   if string.len(data) > 0 and data ~= nil then
  109.     print("File '"..filename.."' loaded.")
  110.     return textutils.unserialize(data)
  111.   else
  112.     return {}
  113.   end
  114. end
  115.  
  116. --checks if there's a file, creates one if not
  117. function checkFile(file)
  118.   if fs.exists(file) == false then
  119.     if saveFile(file) then
  120.       print("Created a new file: " ..file..".")
  121.     end
  122.   else
  123.     print("Everything fine, file '" ..file.."' exists already.")
  124.   end
  125. end
  126.  
  127. ----------
  128. --Tables--
  129. ----------
  130.  
  131. --creates table "list" with all infomation (overloaded)
  132. function setTable(...)
  133.   local n = length(list)+1
  134.   local arguments = {select(1,...)}
  135.   local player = arguments[1]
  136.   numbers[n] = player
  137.   deathReasons[n] = {}
  138.   coords = {}
  139.   coords[n] ={}
  140.   if table.getn(arguments) == 1 then
  141.     list[n] = {}
  142.     list[n]["player"] = arguments[1]
  143.     list[n]["deaths"] = 0
  144.     list[n]["kills"] = 0
  145.     list[n]["ratio"] = "-"
  146.     list[n]["logins"] = 0
  147.     list[n]["messages"] = 0
  148.     list[n]["average"] = 0
  149.     print("Player '" ..player.. "' successfully created.")
  150.   elseif table.getn(arguments) == 7 then
  151.     list[n] = {}
  152.     list[n]["player"] = arguments[1]
  153.     list[n]["deaths"] = arguments[2]
  154.     list[n]["kills"] = arguments[3]
  155.     list[n]["ratio"] = arguments[4]
  156.     list[n]["logins"] = arguments[5]
  157.     list[n]["messages"] = arguments[6]
  158.     list[n]["average"] = arguments[7]
  159.     print("Player '" ..player.. "' successfully created.")
  160.   else
  161.     print("Error: setTable: Wrong parameter passed to function 'setTable'!")
  162.   end
  163. end
  164.  
  165. --returns lenght of list
  166. function length(table)
  167.   local n = 0
  168.     if table ~= nil then
  169.       n = #table
  170.     end
  171.   return n
  172. end
  173.  
  174. --returns related number from player   
  175. function getNumber(player)
  176.   if numbers == nil then
  177.     print("Error: getNumbers: nil list!")
  178.   elseif length(numbers) == 0 then
  179.     print("Error: getNumbers: empty list!")
  180.     return
  181.   else
  182.     for k in ipairs(list) do
  183.       if numbers[k] == player then
  184.         return k
  185.       end
  186.     end
  187.   end
  188. end
  189.  
  190. --checks if player exists
  191. function checkPlayer(player)
  192.   local x = 0
  193.   if numbers ~= nil then
  194.     for k in pairs(numbers) do
  195.       if numbers[k] == player then
  196.         return true
  197.       end
  198.     end
  199.   end
  200.   return false
  201. end
  202.  
  203. --removes table-entry
  204. function table.removePlayer(player)
  205.   local key = getNumber(player)
  206.   if checkPlayer(player) then
  207.     table.remove(list, key)
  208.     table.remove(numbers, key)
  209.     if deathReasons[key] ~= nil then
  210.       table.remove(deathReasons, key)
  211.     end
  212.     if killNumbers[key] ~= nil then
  213.       table.remove(killNumbers, key)
  214.     end
  215.     saveFile("list1")
  216.     saveFile("numbers")
  217.     saveFile("deathReasons")
  218.     saveFile("killNumbers")
  219.     print("Player " ..player.. " successfully removed.")
  220.   else
  221.     print("Error: removePlayer: Player '" ..player.. "' could not be removed. Is the name written correctly?")
  222.   end
  223. end
  224.  
  225. --creates a dummy-player for comparative
  226. --removes it if no longer needed
  227. function dummy()
  228.   local number = length(list)
  229.   --setTable("dummy")
  230.   print("Players:")
  231.   if number == 0 then
  232.     setTable("dummy")
  233.   end
  234.   if list ~= nil then
  235.     for k in ipairs(list) do
  236.       print(list[k]["player"])
  237.     end
  238.   else
  239.     print(" ")
  240.   end
  241.   if number>1 and checkPlayer("dummy") then
  242.     table.removePlayer("dummy")
  243.   end
  244.   print("There're " ..number.. " Players on the server.")
  245. end
  246.  
  247. --adds a new player to the list
  248. function addPlayer()
  249.   while true do
  250.     event,newcomer = os.pullEvent("player")
  251.     local x = 0
  252.     if checkPlayer(newcomer) then
  253.       chat.tell(newcomer,"Error: "..newcomer..", you're already listed in the database. Don't you remember, Idiot?")
  254.     elseif checkPlayer(newcomer) == false then
  255.       chat.tell(newcomer,"Congratulations! Welcome to this great server, now you're listed in the database. Have fun, "..newcomer..".")
  256.       setTable(newcomer)
  257.       saveFile("numbers")
  258.       saveFile("list1")
  259.       saveFile("deathReasons")
  260.       saveFile("killNumbers")
  261.     else
  262.       chat.say("Well this shouldn't happen, please report this error to "..serverAdmin.." or " ..infoboardAdmin..".")
  263.       chat.say("No joke!")
  264.     end
  265.   end  
  266. end
  267.  
  268. --calculates kill/death ratio
  269. function ratio(player)
  270.   if list[player]["deaths"] == 0 then
  271.     list[player]["ratio"] = "-"
  272.   else
  273.     list[player]["ratio"] = tonumber(list[player]["kills"])/tonumber(list[player]["deaths"])
  274.   end
  275. end
  276.  
  277. function randomMessage(player)
  278.   local case = math.random(1,29)
  279.   if case == 1 then
  280.     chat.tell(player,"So, how was dying?",20000)
  281.   elseif case ==2 then
  282.     chat.tell(player,"The South corporation would like to remind you that there is only one thing worse than respawning, and that is not respawning.",20000)
  283.   elseif case == 3 then
  284.     chat.tell(player,"South recommends swearing vengeance on the thing that killed you, unless it was an inanimate object such as a cliff.",20000)
  285.   elseif case == 4 then
  286.     chat.tell(player,"Byebye… Hello friend.",20000)
  287.   elseif case == 5 then
  288.     chat.tell(player,"Rise from your grave!",20000)
  289.   elseif case == 6 then
  290.     chat.tell(player,"The South corporation suggests: Live! LIIIIIIIIVVVVVVVVE!",20000)
  291.   elseif case == 7 then
  292.     chat.tell(player,"Aaaaaand RESPAWN!",20000)
  293.   elseif case == 8 then
  294.     chat.tell(player,"R-r-r-r-respawn!",20000)
  295.   elseif case == 9 then
  296.     chat.tell(player,"South recommends channeling your post-death frustration into pre-death vengeful anger!",20000)
  297.   elseif case == 10 then
  298.     chat.tell(player,"The South corporation would like to remind you that the afterlife is extremely boring, and not worth visiting.",20000)
  299.   elseif case == 11 then
  300.     chat.tell(player,"The South corporation is sure none of that was your fault.",20000)
  301.   elseif case == 12 then
  302.     chat.tell(player,"South recommends checking for any excess limbs before continuing your adventure.",20000)
  303.   elseif case == 13 then
  304.     chat.tell(player,"South says: back on your feet and show 'em what for!",20000)
  305.   elseif case == 14 then
  306.     chat.tell(player,"Anyone can live. Have the courage to die!",20000)
  307.   elseif case == 15 then
  308.     chat.tell(player,"So long as you believe in yourself, nothing can TRULY kill you! Except Creepers.",20000)
  309.   elseif case == 16 then
  310.     chat.tell(player,"Greetings, clone-of-the-recently-deceased! Good luck in your future endeavors!",20000)
  311.   elseif case == 17 then
  312.     chat.tell(player,"South suggests that you rejoice in your temporary death! A victory achieved without suffering is no victory at all!",20000)
  313.   elseif case == 18 then
  314.     chat.tell(player,"South hopes your death was a learning experience, but wouldn't mind if you made the same mistake just a few more times just to be sure.",20000)
  315.   elseif case == 19 then
  316.     chat.tell(player,"South says: afterlife, schmafterlife.",20000)
  317.   elseif case == 20 then
  318.     chat.tell(player,"The South corporation says: Welcome back.",20000)
  319.   elseif case == 21 then
  320.     chat.tell(player,"Dying is awesome! All of the cool kids are doing it!",20000)
  321.   elseif case == 22 then
  322.     chat.tell(player,"The South corporation welcomes you back from your visit to the undiscovered country.",20000)
  323.   elseif case == 23 then
  324.     chat.tell(player,"South asks: why die when you can respawn?",20000)
  325.   elseif case == 24 then
  326.     chat.tell(player,"Enjoy your new you!",20000)
  327.   elseif case == 25 then
  328.     chat.tell(player,"So, how are things?",20000)
  329.   elseif case == 26 then
  330.     chat.tell(player,"Oh, it's you again.",20000)
  331.   elseif case == 27 then
  332.     chat.tell(player,"So, how was hell?",20000)
  333.   elseif case == 28 then
  334.     chat.tell(player,"Death means nothing in this fantasy world!",20000)
  335.   elseif case == 29 then
  336.     chat.tell(player,"At least the game's not too easy, right?",20000)
  337.   end
  338. end
  339.  
  340.  
  341.  --calculates average messagelenght
  342. function average(player, message)
  343.   list[player]["average"] = (tonumber(list[player]["average"]))*(tonumber(list[player]["messages"])-1)
  344.   list[player]["average"] = (tonumber(list[player]["average"]) + string.len(message)) / (tonumber(list[player]["messages"]))
  345. end
  346.  
  347.  
  348.  
  349. -----------
  350. --sorting--
  351. -----------
  352. --damn many sort functions
  353. function sortByDeathsH(x, y)
  354.   return x.deaths > y.deaths
  355. end
  356.  
  357. function sortByKillsH(x, y)
  358.   return x.kills > y.kills
  359. end
  360.  
  361. function sortByLoginsH(x, y)
  362.   return x.logins > y.logins
  363. end
  364.  
  365. function sortByMessagesH(x, y)
  366.   return x.messages > y.messages
  367. end
  368.  
  369. function sortByAverageH(x, y)
  370.   return x.average > y.average
  371. end
  372.  
  373. function sortByRatioH(x,y)
  374.   return tostring(x.ratio) > tostring(y.ratio)
  375. end
  376.  
  377. function sortByDeathsL(x, y)
  378.   return x.deaths < y.deaths
  379. end
  380.  
  381. function sortByKillsL(x, y)
  382.   return x.kills < y.kills
  383. end
  384.  
  385. function sortByLoginsL(x, y)
  386.   return x.logins < y.logins
  387. end
  388.  
  389. function sortByMessagesL(x, y)
  390.   return x.messages < y.messages
  391. end
  392.  
  393. function sortByAverageL(x, y)
  394.   return x.average < y.average
  395. end
  396.  
  397. function sortByRatioL(x,y)
  398.     return tostring(x.ratio) < tostring(y.ratio)
  399. end
  400.  
  401. function sortByReasons(x, y)
  402.   return x > y
  403. end
  404.  
  405. function sortAll (state)
  406.   if state == "max1" then
  407.     table.sort(listSorted,sortByKillsH)
  408.     buttonAPI.toggleAll(" Max  ")
  409.   elseif state == "min1" then
  410.     table.sort(listSorted,sortByKillsL)
  411.     buttonAPI.toggleAll(" Min  ")
  412.   elseif state == "max2" then
  413.     table.sort(listSorted,sortByDeathsH)
  414.     buttonAPI.toggleAll("Max ")
  415.   elseif state == "min2" then
  416.     table.sort(listSorted,sortByDeathsL)
  417.     buttonAPI.toggleAll("Min ")
  418.   elseif state == "max3" then
  419.     table.sort(listSorted,sortByRatioH)
  420.     buttonAPI.toggleAll(" Max ")
  421.   elseif state == "min3" then
  422.     table.sort(listSorted,sortByRatioL)
  423.     buttonAPI.toggleAll(" Min ")
  424.   elseif state == "max4" then
  425.     table.sort(listSorted,sortByMessagesH)
  426.     buttonAPI.toggleAll("Max")
  427.   elseif state == "min4" then
  428.     table.sort(listSorted,sortByMessagesL)
  429.     buttonAPI.toggleAll("Min")
  430.  elseif state == "max5" then
  431.     table.sort(listSorted,sortByAverageH)
  432.     buttonAPI.toggleAll("Max ")
  433.   elseif state == "min5" then
  434.     table.sort(listSorted,sortByAverageL)
  435.     buttonAPI.toggleAll("Min ")
  436.   elseif state == "max6" then
  437.     table.sort(listSorted,sortByLoginsH)
  438.     buttonAPI.toggleAll("Max")
  439.   elseif state == "min6" then
  440.     table.sort(listSorted,sortByLoginsL)
  441.     buttonAPI.toggleAll("Min")
  442.   end
  443.   refresh()
  444. end
  445.  
  446.  
  447. -----------
  448. --Monitor--
  449. -----------
  450. --refreshes the monitorscreen
  451. function refresh()
  452.   mon.clear()
  453.   mon2.clear()
  454.   screen()
  455.   buttonAPI.screen()
  456. end
  457.  
  458. --creates labels
  459. function label(xpos,ypos, text)
  460.   mon.setCursorPos(xpos, ypos)
  461.   mon.write(text)
  462. end
  463.  
  464. --prints everything on the monitor
  465. function printAll()
  466.   mon2.clear()
  467.   local y = 4
  468.   if filled == "login" then
  469.     label(2,2,"Player:")
  470.     label(27,2, "Logins:")
  471.     for k in pairs(listSorted) do
  472.       mon.setCursorPos(3,y)
  473.       mon.write(listSorted[k]["player"])
  474.       mon.setCursorPos(29,y)
  475.       mon.write(tostring(listSorted[k]["logins"]))
  476.       y=y+1
  477.     end
  478.   elseif filled == "sortKill" then
  479.     label(2,2,"Player:")
  480.     label(19,2, "Kills:")
  481.     label(34,2, "Deaths:")
  482.     label(49,2, "Ratio:")
  483.     for k in pairs(listSorted) do
  484.       mon.setCursorPos(3,y)
  485.       mon.write(listSorted[k]["player"])
  486.       mon.setCursorPos(20,y)
  487.       mon.write(tostring(listSorted[k]["kills"]))
  488.       mon.setCursorPos(35,y)
  489.       mon.write(tostring(listSorted[k]["deaths"]))
  490.       mon.setCursorPos(50,y)
  491.       mon.write(tostring(listSorted[k]["ratio"]))
  492.       y=y+1
  493.     end
  494.   elseif filled == "sortMessage" then
  495.     label(2,2,"Player:")
  496.     label(22,2, "Messages:")
  497.     label(37,2, "average Length:")
  498.     for k in pairs(listSorted) do
  499.       mon.setCursorPos(3,y)
  500.       mon.write(listSorted[k]["player"])
  501.       mon.setCursorPos(23,y)
  502.       mon.write(tostring(listSorted[k]["messages"]))
  503.       mon.setCursorPos(38,y)
  504.       mon.write(tostring(listSorted[k]["average"]))
  505.       y=y+1
  506.     end
  507.   elseif filled == "sortReasons" then
  508.     local n = getNumber(showed)
  509.     local total = 0
  510.     label(2,2, tostring(showed))
  511.     label(20,4, "Reasons:")
  512.     label(45,4, "Deaths:")
  513.     y=y+2
  514.     if length(deathReasonsSorted[n]) ~= nil and length(deathReasonsSorted[n]) ~= 0 then
  515.       local written = {}
  516.       for k in pairs(deathReasonsSorted[n]) do
  517.         total = total + tonumber(deathReasonsSorted[n][k])
  518.         local i        
  519.         for i in pairs(deathReasons[n]) do
  520.           if deathReasons[n][i] == deathReasonsSorted[n][k] then
  521.             local j
  522.             local bool = true
  523.             for j in pairs(written) do
  524.               if killNumbers[n][i] == written[j] then
  525.                 bool = false
  526.               end
  527.             end
  528.             if bool then
  529.               mon.setCursorPos(21,y)
  530.               mon.write(tostring(killNumbers[n][i]))
  531.               table.insert(written, killNumbers[n][i])
  532.               break
  533.             end
  534.           end
  535.         end
  536.         mon.setCursorPos(44,y)
  537.         mon.write(tostring(deathReasonsSorted[n][k]))
  538.         y=y+1
  539.       end
  540.       if (listSorted[n]["deaths"]-total) ~= 0 then
  541.         mon.setCursorPos(21,y)
  542.         mon.write("Unknown Reasons")
  543.         mon.setCursorPos(44,y)
  544.         mon.write(tostring(listSorted[n]["deaths"]-total))
  545.       end    
  546.     end
  547.   end
  548. end
  549.  
  550. function screen()
  551.   if filled ~= "button" then
  552.     printAll()
  553.   end
  554. end
  555.  
  556. function toggleScreen(change)
  557.   buttonAPI.toggleAll(change)
  558.   refresh()
  559. end
  560.  
  561. function nextPage()
  562.    if page+1 <= pages then
  563.      page = page+1
  564.    end
  565.    fillReasons()
  566. end
  567.  
  568. function prevPage()
  569.    if page-1 >= 1 then
  570.      page = page-1
  571.    end
  572.    fillReasons()
  573. end
  574.  
  575. function nextPage2()
  576.    if page+1 <= pages then
  577.      page = page+1
  578.    end
  579.    fillCoords()
  580. end
  581.  
  582. function prevPage2()
  583.    if page-1 >= 1 then
  584.      page = page-1
  585.    end
  586.    fillCoords()
  587. end
  588.  
  589. function goBack()
  590.   fillReasons()
  591. end
  592.  
  593. --buttons in main-menu
  594. function fillButton()
  595.   buttonAPI.clearTable()
  596.   buttonAPI.setTable("Kill/Death", fillSortKill,"", 2, 15, 2, 4)
  597.   buttonAPI.setTable("Death Reasons", fillReasons,"", 18, 34, 2, 4)
  598.   buttonAPI.setTable("Messages", fillSortMessages,"", 37, 48, 2, 4)
  599.   buttonAPI.setTable("Coords",fillCoords,"", 51, 59,2,4)
  600.   filled = "button"
  601.   refresh()
  602. end
  603.  
  604. --button to choose player for deathreasons
  605. function fillReasons()
  606.   buttonAPI.clearTable()
  607.   mon.setTextScale(1.5)
  608.   players = length(list)
  609.   local npp = 3 --names per page
  610.   local currLength = 24
  611.   pages = math.ceil(players/npp)
  612.   local currName = 0
  613.   for k in pairs(numbers) do
  614.     currName = currName + 1
  615.     if currName > npp*(page-1) and currName < npp*page+1 then
  616.       buttonAPI.setTable(numbers[k], fillSortReasons, numbers[k], currLength, currLength + string.len(numbers[k])+4 ,2 ,4)
  617.       currLength = currLength + string.len(numbers[k])+8
  618.     end
  619.   end
  620.   buttonAPI.setTable("Home", fillButton, "", 2, 7, 2, 4)
  621.   buttonAPI.setTable("Next Page", nextPage, "", 10, 20, 1, 2)
  622.   buttonAPI.setTable("Prev Page", prevPage, "", 10, 20, 4, 5)
  623.   refresh()
  624.   buttonAPI.label(11,3, "Page: "..page.. "/"..pages)
  625.   filled = "reasons"
  626. end
  627.  
  628. --button to choose player for coord
  629. function fillCoords()
  630.   buttonAPI.clearTable()
  631.   mon.setTextScale(1.5)
  632.   players = length(list)
  633.   local npp = 3 --names per page
  634.   local currLength = 24
  635.   pages = math.ceil(players/npp)
  636.   local currName = 0
  637.   for k in pairs(numbers) do
  638.     currName = currName + 1
  639.     if currName > npp*(page-1) and currName < npp*page+1 then
  640.       buttonAPI.setTable(numbers[k], coordsOptions, numbers[k], currLength, currLength + string.len(numbers[k])+4 ,2 ,4)
  641.       currLength = currLength + string.len(numbers[k])+8
  642.     end
  643.   end
  644.   buttonAPI.setTable("Home", fillButton, "", 2, 7, 2, 4)
  645.   buttonAPI.setTable("Next Page", nextPage2, "", 10, 20, 1, 2)
  646.   buttonAPI.setTable("Prev Page", prevPage2, "", 10, 20, 4, 5)
  647.   refresh()
  648.   label(2,2,"Player:")
  649.   label(18,2,"Place:")
  650.   label(30,2,"Coordinates:")
  651.   local y = 4
  652.   for k in pairs(list) do
  653.     mon.setCursorPos(3,y)
  654.     mon.write(numbers[k])
  655.     if coords[k] == nil or #coords[k] then
  656.       y=y+1
  657.     end
  658.     for i in pairs(coords[k]) do
  659.       mon.setCursorPos(20,y)
  660.       mon.write(coords[k][i]["name"])
  661.       mon.setCursorPos(32,y)
  662.       mon.write(coords[k][i]["xCoord"])
  663.       mon.setCursorPos(38,y)
  664.       mon.write(coords[k][i]["yCoord"])
  665.       mon.setCursorPos(44,y)
  666.       mon.write(coords[k][i]["zCoord"])
  667.       y=y+1
  668.     end
  669.   end
  670.   buttonAPI.label(11,3, "Page: "..page.. "/"..pages)
  671.   filled = "coords"
  672. end
  673.  
  674. function goBack2()
  675.   fillCoords()
  676. end
  677.  
  678. function newCoords(player,name,x,y,z)
  679.   local n = getNumber(player)
  680.   local m = length(coords[n])+1
  681.   chat.say("Please write 'NameofthePlace x-coords y-coords z-coords' .")
  682.   chat.say("For example 'Base 12 85 943' .")
  683.   event, player, message =  os.pullEvent("chat")
  684.   local string = message
  685.   local x = 0
  686.   for word in string.gmatch(string, "%w+") do
  687.     if x == 0 then
  688.       name = word
  689.     elseif x == 1 then  
  690.       xCoord = word
  691.     elseif x == 2 then
  692.       yCoord= word
  693.     elseif x == 3 then
  694.       zCoord = word
  695.     end
  696.     x=x+1
  697.   end
  698.   coords[n][m] = {}
  699.   coords[n][m]["name"] = name
  700.   coords[n][m]["xCoord"] = xCoord
  701.   coords[n][m]["yCoord"] = yCoord
  702.   coords[n][m]["zCoord"] = zCoord
  703.   saveFile("coords")
  704. end
  705.  
  706.  
  707. function deleteCoords(player)
  708.   chat.say("Please write the number of the place you want to delete.")
  709.   event, player2, message =  os.pullEvent("chat")
  710.   local n = getNumber(player)
  711.   table.remove(coords[n], tonumber(message))
  712.   saveFile("coords")
  713. end
  714.  
  715. function coordsOptions(player)
  716.   buttonAPI.clearTable()
  717.   buttonAPI.setTable("Home", fillButton, player, 2, 7, 2, 4)
  718.   buttonAPI.setTable("Back", goBack2, "", 9, 14, 2, 4)
  719.   buttonAPI.setTable("New", newCoords,player,22,27,2,4)
  720.   buttonAPI.setTable("Delete", deleteCoords,player,30,37,2,4)
  721. refresh()
  722. end
  723.  
  724. --sorting buttons for kill-screen
  725. function fillSortKill()
  726.   buttonAPI.clearTable()
  727.   mon.setTextScale(1.5)
  728.   buttonAPI.setTable(" Min  ", sortAll, "min1", 22, 28, 4, 5)
  729.   buttonAPI.setTable(" Max  ", sortAll, "max1", 22, 28, 1, 2)
  730.   buttonAPI.setTable("Min ", sortAll, "min2", 44, 50, 4, 5)
  731.   buttonAPI.setTable("Max ", sortAll, "max2", 44, 50, 1, 2)
  732.   buttonAPI.setTable(" Min ", sortAll, "min3", 66, 72, 4, 5)
  733.   buttonAPI.setTable(" Max ", sortAll, "max3", 66, 72, 1, 2)
  734.   buttonAPI.setTable("Home", fillButton, "", 2, 7, 2, 4)
  735.   filled = "sortKill"
  736.   refresh()
  737. end
  738.  
  739. --sorting buttons for deathreason-screen
  740. function fillSortReasons(display)
  741.   buttonAPI.clearTable()
  742.   showed = display  
  743.   buttonAPI.setTable("Back", goBack, "", 9, 14, 2, 4)
  744.   buttonAPI.setTable("Home", fillButton, "", 2, 7, 2, 4)
  745.   filled = "sortReasons"
  746.   refresh()
  747. end
  748.  
  749. --sorting buttons for message-screen
  750. function fillSortMessages()
  751.   mon.setTextScale(1.5)
  752.   buttonAPI.clearTable()
  753.   buttonAPI.setTable("Min",sortAll, "min4", 35, 41, 4, 5)
  754.   buttonAPI.setTable("Max",sortAll, "max4", 35, 41, 1, 2)
  755.   buttonAPI.setTable("Min ",sortAll, "min5", 60, 66, 4, 5)
  756.   buttonAPI.setTable("Max ",sortAll, "max5", 60, 66, 1, 2)
  757.   buttonAPI.setTable("Home", fillButton, "", 2, 7, 2, 4)
  758.   filled = "sortMessage"
  759.   refresh()
  760. end
  761.  
  762. --sorting buttons for login-screen
  763. function fillSortLogins()
  764.   buttonAPI.clearTable()
  765.   buttonAPI.setTable("Min",sortAll, "min6", 26, 32, 4, 5)
  766.   buttonAPI.setTable("Max",sortAll, "max6", 26, 32, 1, 2)
  767.   buttonAPI.setTable("Home", fillButton, "", 2, 7, 2, 4)
  768.   filled = "sortLogins"
  769.   refresh()
  770. end
  771.  
  772.  
  773.  
  774.  
  775. ------------------------
  776. --while true functions--
  777. ------------------------
  778.  
  779. --counts deaths, kills and deathreasons
  780. function deathcount()
  781.   while true do
  782.     local event,dead,killer,cause = os.pullEvent("chat_death")
  783.     if checkPlayer(dead) == false then
  784.       setTable(dead)
  785.     end
  786.     local number1 = getNumber(dead)
  787.     list[number1]["deaths"] = tonumber(list[number1]["deaths"])+1
  788.     ratio(number1)
  789.     if killer~=nil then
  790.       for k in pairs(list) do
  791.         if killer == list[k]["player"] then
  792.           local number2 = getNumber(killer)
  793.           list[number2]["kills"] = tonumber(list[number2]["kills"])+1
  794.           ratio(number2)
  795.         end
  796.       end
  797.       local x = 0
  798.       if list[number1]["deaths"] == 1 then
  799.         killNumbers[number1] = {}
  800.         deathReasons[number1] = {}        
  801.       end
  802.       for i=1, length(killNumbers[number1]), 1 do
  803.         if tostring(killNumbers[number1][i]) == killer then
  804.           deathReasons[number1][i] = deathReasons[number1][i]+1
  805.           x = x+1          
  806.         end
  807.       end
  808.       if x == 0 then
  809.         local n = length(killNumbers[number1])+1
  810.         killNumbers[number1][n] = killer
  811.         deathReasons[number1][n] = 1
  812.      end
  813.     end
  814.     randomMessage(dead)
  815.     chat.tell(dead, "You died " ..list[number1]["deaths"].. " times.",20000)
  816.     saveFile("deathReasons")
  817.     saveFile("killNumbers")
  818.     saveFile("list1")
  819.     saveFile("numbers")
  820.     table.sort(deathReasonsSorted[number1], sortByReasons)
  821.   end
  822. end
  823.  
  824.  
  825. --counts numbers of messages
  826. --includes maintenance-options
  827. function messagecount()
  828.   while true do
  829.     local event, player, message = os.pullEvent("chat")
  830.     if checkPlayer(player) == false then --unregistered player would crash system
  831.       setTable(player)
  832.     end
  833.     local number = getNumber(player)
  834.     list[number]["messages"] = tonumber(list[number]["messages"])+1
  835.     average(number,tostring(message))
  836.     if player == boardAdmin and message == "createPlayer" then
  837.       chat.tell(boardAdmin,"Waiting for information to create player: Name, Kills, Deaths, Ratio, Logins, Messages, Average")
  838.       print("Waiting for information to create player: Name, Kills, Deaths, Ratio, Logins, Messages, Average")
  839.       local event, player, message = os.pullEvent("chat")
  840.       local string = message
  841.       local x = 0
  842.       for word in string.gmatch(string, "%w+") do
  843.         if x == 0 then
  844.           name = word
  845.           print("Player: " ..word)
  846.         elseif x == 1 then  
  847.           kills = tonumber(word)
  848.           print("Kills: " ..word)
  849.         elseif x == 2 then
  850.           deaths = tonumber(word)
  851.           print("Deaths: " ..word)
  852.         elseif x == 3 then
  853.           ratio = tonumber(word)
  854.           print("Ratio: "..word)
  855.         elseif x == 4 then
  856.           logins = tonumber(word)
  857.           print("Logins: " ..word)
  858.         elseif x == 5 then
  859.           messages = tonumber(word)
  860.           print("Messages: " ..word)
  861.         elseif x == 6 then
  862.           average = tonumber(word)
  863.           print("Average Lenght: " ..word)
  864.         else
  865.           print("Error: messagecount: createPlayer: String-message not matching")
  866.         end
  867.         x=x+1
  868.       end
  869.       setTable(name,deaths,kills,ratio,logins,messages,average)
  870.     elseif player == boardAdmin and message == "deletePlayer"then
  871.       chat.tell(boardAdmin,"Waiting for information to delete player: Name")
  872.       print("Waiting for information to delete player: Name")
  873.       event, player, message = os.pullEvent("chat")
  874.       table.removePlayer(tostring(message))
  875.     end
  876.     saveFile("list1")
  877.     saveFile("numbers")
  878.     saveFile("deathReasons")
  879.     saveFile("killNumbers")  
  880.   end
  881. end
  882.  
  883. --checks for monitortouch
  884. function getClick()
  885.   while true do
  886.     local event,side,x,y = os.pullEvent("monitor_touch")
  887.     if side == "top" then
  888.       buttonAPI.checkxy(x,y)
  889.     end
  890.   end
  891. end
  892.  
  893. function time()
  894.   while true do
  895.     local day = os.day()
  896.     if filled == "button" then
  897.       local time = textutils.formatTime(os.time(), true)
  898.       mon.clear()
  899.       mon.setTextScale(5)
  900.       mon.setCursorPos(3,3)
  901.       mon.write("Day: " ..day)
  902.       mon.setCursorPos(3,4)
  903.       mon.write("Time: " ..time)
  904.     end
  905.     sleep(5)
  906.     if day%100 == 0 then
  907.       chat.say("The South corporation enjoys to say that it's time to celebrate the " ..day.. ". jubilee of the World a27Dci85sg-3. Have a nice day!",20000)
  908.     end
  909.   end
  910. end
  911.  
  912.  
  913. --function with all pullEvents
  914. function mainProcess()
  915.     parallel.waitForAny(deathcount, messagecount, addPlayer, getClick, time)
  916. end
  917.  
  918.  
  919. -----------
  920. --Process--
  921. -----------
  922. --lifeControl()
  923. checkFile("list1")
  924. checkFile("numbers")
  925. checkFile("deathReasons")
  926. checkFile("killNumbers")
  927. list = loadFile("list1")
  928. numbers = loadFile("numbers")
  929. deathReasons = loadFile("deathReasons")
  930. killNumbers = loadFile("killNumbers")
  931. listSorted = table.copy(list)
  932. numbersSorted = table.copy(numbers)
  933. deathReasonsSorted = table.copy(deathReasons)
  934. killNumbersSorted = table.copy(killNumbers)
  935. coords = loadFile("coords")
  936. fillButton()
  937. dummy()
  938. refresh()
  939. mainProcess()
Advertisement
Add Comment
Please, Sign In to add comment