Advertisement
Guest User

draw

a guest
Oct 1st, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.52 KB | None | 0 0
  1.    
  2.  
  3.            
  4.      
  5.                
  6.          
  7.               os.loadAPI("button")
  8.                             m = peripheral.wrap("top")
  9.                             m.clear()
  10.                                             comp = {
  11.                                             "Ivan Zarkov", "Bob41599", "Blouwing14", "Dev Eagle", "PlentyOfKills", "N320S", "Kenpokid4", "DizzyAaron", "Jonathan", "Johnathon Chase",
  12.                                             "TPC", "Ivan Zarkov", "PlentyOfKills", "Artys", "Retschga", "N320S", "Kenpokid4", "Bob41599", "DizzyAaron", "Johnathon Chase",
  13.                                             "PlentyOfKills", "Ivan Zarkov", "N320S", "DizzyAaron", "Blouwing14", "Retschga", "Kenpokid4", "Johnathon Chase", "Lizy Girl",
  14.                                             "Kenpokid4", "TheNaeria", "Ivan Zarkov", "PlentyOfKills", "Retschga", "N320S", "DizzyAaron", "TPC", "Darko", "DrTacete", "Johnathon Chase",
  15.                                             "TPC", "Retschga", "N320S", "PlentyOfKills", "DizzyAaron", "Ivan Zarkov", "DrTacete", "PoOoPiez", "Kenpokid4", "Johnathon Chase",
  16.                                             "N320S", "PlentyOfKills", "ProRed", "Blouwing14", "DizzyAaron", "RealAlDay1", "Ivan Zarkov", "Retschga", "Ethan Rokosz", "H3ADPH0NEFREAK", "DrTacete", "Habood Hisham", "TPC", "Kenpokid4", "Johnathon Chase",
  17.                                             "Dan Zavada", "PlentyOfKills", "Ivan Zarkov", "Chris O", "DrTacete", "Nick Dubz", "N320S", "Daniel Stein", "Braiden Allen", "Dan Zavada", "TPC", "Johnathon Chase",
  18.                                             "Ivan Zarkov", "DrTacete", "Retschga", "PlentyOfKills", "N320S", "Chris O", "Dan Zavada", "DizzyAaron", "Daniel Stein", "MrPriZmaHD", "Kenni Krisensen", "UkrainianGaming", "purplemangaming", "KevinZePanda", "TPC", "LEGOKID", "Johnathon Chase", "Kenpokid4",
  19.                                             "Ivan Zarkov", "ProRed", "Waynee", "PlentyOfKills", "DrTacete", "Dan Zavada", "Retschga", "Daniel Stein", "TPC", "DizzyAaron", "alexmendiger", "Francisco", "Johnathon Chase", "Kenpokid4", "N320S", "Kenni Krisensen", "TiMBo Mc",
  20.                                             "Ivan Zarkov", "PlentyOfKills", "Plantago", "Arman Malekloo", "DrTacete", "Waynee", "UkrainianGaming", "Pigmack Gaming", "TheSadegh123", "TPC", "N320S", "Johnathon Chase", "Kenpokid4", "Retschga", "Kenni Krisensen",
  21.                                      
  22.                                              }                
  23.                             function countArray(t)
  24.                               local count = 0
  25.                               for _ in pairs(t) do count = count + 1 end
  26.                               return count
  27.                             end
  28.                             comments = countArray(comp)
  29.                              
  30.                             function spairs(t, order)
  31.                               local keys = {}
  32.                               for k in pairs(t) do keys[#keys+1] = k end
  33.                                 if order then
  34.                                   table.sort(keys, function(a,b) return order(t, a, b) end)
  35.                                
  36.                                 else
  37.                                   table.sort(keys)
  38.                                 end
  39.                                 local i = 0
  40.                                 return function()
  41.                                   i = i + 1
  42.                                   if keys[i] then
  43.                                     return keys[i], t[keys[i]]
  44.                                   end
  45.                               end
  46.                              
  47.                             end
  48.                              
  49.                             function fillTable()
  50.                                button.setTable("Draw Winner", drawWinner, 10,30, 23,25)
  51.                                button.screen()
  52.                             end
  53.                              
  54.                              
  55.                             function groupComp(t)
  56.                               local results = {}
  57.                               for k, v in pairs(t) do
  58.                                 if results[v] then
  59.                                   results[v] = results[v] + 1
  60.                                 else results[v] = 1
  61.                                 end
  62.                               end
  63.                               --table.sort(results)
  64.                               return results
  65.                             end
  66.                              
  67.                             function listCompetitors()
  68.                               x = 2
  69.                               y = 5
  70.                               compsorted = groupComp(comp)
  71.                               for k,v in spairs(compsorted, function(t,a,b) return t[b] < t[a] end) do
  72.                                 x = 2
  73.                                 m.setCursorPos(x,y)
  74.                                 m.setTextColor(colors.cyan)
  75.                                 m.write(k)
  76.                                 m.setTextColor(colors.yellow)
  77.                                 m.setCursorPos(25,y)
  78.                                 m.write(math.floor(v))
  79.                                 m.setTextColor(colors.white)
  80.                                 m.setCursorPos(32, y)
  81.                                 chance = (v / comments)*100
  82.                                 m.write(math.floor(chance) .. "%")
  83.                                 y = y + 1
  84.                                
  85.                                 if y > 18 then break end
  86.                               end
  87.                             end
  88.                              
  89.                             function centerMe(text, rowNum)
  90.                               w, h = m.getSize()
  91.                               --print("Center Me called, width is..")
  92.                               --print(w)
  93.                               m.setCursorPos((w-string.len(text))/2 + 1, rowNum)
  94.                             end
  95.                              
  96.                             function getClick()
  97.                                event,side,x,y = os.pullEvent("monitor_touch")
  98.                                button.checkxy(x,y)
  99.                             end
  100.                              
  101.                             function randomSelection(t)
  102.                               num = t[ math.random( #t ) ]
  103.                               return num
  104.                             end
  105.                             function drawWinner()
  106.                                button.flash("Draw Winner")
  107.                                result = randomSelection(comp)
  108.                                m.clear()
  109.                                headerLine()
  110.                                local i = 0
  111.                                spinmsg = "Spinning..."
  112.                                while i < 20 do
  113.                                  local num = math.random(1,5)
  114.                                  if num == 1 then
  115.                                    m.setTextColor(colors.lime)
  116.                                  elseif num == 2 then
  117.                                    m.setTextColor(colors.lightBlue)
  118.                                  elseif num == 3 then
  119.                                    m.setTextColor(colors.red)
  120.                                  elseif num == 4 then
  121.                                    m.setTextColor(colors.yellow)
  122.                                  elseif num == 5 then
  123.                                    m.setTextColor(colors.magenta)
  124.                                  end
  125.                                  centerMe(spinmsg, 10)
  126.                                  m.write(spinmsg)
  127.                                  sleep(0.5)
  128.                                  starpos = i + 16
  129.                                  m.setCursorPos(starpos, 11)
  130.                                  m.write("*")
  131.                                  m.setTextColor(colors.white)
  132.                                  i = i + 1
  133.                                end
  134.                                m.clear()
  135.                                headerLine()
  136.                                sleep(1)
  137.                                local x = 0
  138.                                while x < 5 do
  139.                                  sleep(0.4)
  140.                                  centerMe(result, 10)
  141.                                  m.setTextColor(colors.yellow)
  142.                                  m.write(result)
  143.                                  sleep(0.4)
  144.                                  centerMe(result, 10)
  145.                                  m.setTextColor(colors.white)
  146.                                  m.write(result)
  147.                                  sleep(0.4)
  148.                                  centerMe(result, 10)
  149.                                  m.setTextColor(colors.lime)
  150.                                  m.write(result)
  151.                                  
  152.                                  x = x+1
  153.                                  
  154.                                  
  155.                                  --button.screen()
  156.                                end
  157.                               m.setTextColor(colors.yellow)
  158.                               m.setCursorPos(16,12)
  159.                               m.write("Cong")
  160.                               m.setTextColor(colors.orange)
  161.                               m.setCursorPos(20,12)
  162.                               m.write("ratul")
  163.                               m.setTextColor(colors.red)
  164.                               m.setCursorPos(25,12)
  165.                               m.write("ations")
  166.                               m.setTextColor(colors.white)
  167.                               m.setCursorPos(31,12)
  168.                               m.write("!!!")
  169.                               button.screen()
  170.                             end
  171.                              
  172.                             fillTable()
  173.                             function headerLine()
  174.                               m.setTextColor(colors.white)
  175.                               m.setTextScale(1)
  176.                               button.heading("Iskalls GiveAway Machine")
  177.                               m.setCursorPos(1,3)
  178.                               m.setTextColor(colors.lime)
  179.                               m.write("***************************************************")
  180.                               m.setTextColor(colors.white)
  181.                             end
  182.                             headerLine()
  183.                             pCount = "Total Comments: " .. comments
  184.                             centerMe(pCount, 20)
  185.                             m.write(pCount)
  186.                             listCompetitors()
  187.                             groupComp(comp)
  188.                              
  189.                             --button.label(1,5,"Demo!")
  190.                              
  191.                             while true do
  192.                                getClick()
  193.                             end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement