Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2016
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 39.42 KB | None | 0 0
  1. -- COUNTDOWN GAME - Made by Iceoccultism, yes the code isn't great, feel free to update it but don't remove accreditations.
  2. -- Credits to Makinit's CAH which I got some utility functions from and some boilerplate from.
  3. -- TODO
  4. -- Maybe show them all one by one.
  5. -- Parser in UI ... needs far more work, and some sort of backstack + back button. :/
  6. -- Guard join on UI clicks
  7.  
  8. system.disableChatCommandDisplay("", true)
  9.  
  10. -- Function needs to be preloaded
  11. function table.copy(t)
  12.     local t, r = t, {}
  13.     local n = #t
  14.     for i = 1, n do
  15.         r[i] = t[i]
  16.     end
  17.     return r
  18. end
  19.  
  20.  
  21. local settings = {
  22.     maxplayers = 8,
  23.     timerCounter = 35,
  24.     timerCounterNum = 45,
  25.     letters = 9,
  26.     no = 6,
  27.     -- Yes the frequency is somewhat proportionate to what you see on actual English
  28.     vowels = {"A","O", "A", "I", "A","A","I","O","O", "E","E","E","E","E","E", "U", "U", "A","A", "I","I","I","I", "E", "O","E","E","E", "O", "U"},
  29.     consonants = {"B","B", "B", "C","C","C","C", "D","D","D", "D", "D","D","D", "F","F", "G","G","G","G","G","G", "H","H", "J", "K","K","K", "L", "L", "L", "L","L","L","L","L", "M","M","M","M","M", "N","N","N","N","N","N", "N", "P","P","P","P", "Q", "R","R","R","R","R","R","R", "S","S","S","S","S","S","S","S","S","S", "T","T","T","T","T","T","T", "V","V", "W", "W", "X", "Y","Y","Y", "Z"},
  30.     numbers = {1,1,1,2,2,2,2,3,3,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,10,10},
  31.     numbersBig = {100, 75, 25, 50},
  32.     admins = {"Iceoccultism", "Luminousity", "Willowshine", "Sassybaskets"},
  33.     keys = {"remindertoremovethis"},
  34.     -- You can change this around, however, the C [Conundrum] must always be last for now.
  35.     roundOrdering = {"N", "L", "L", "N", "L", "L", "N", "L", "L", "L", "L", "N", "C"},
  36.     highlights = {"#F7CA18","#F89406","#26A65B", "#BB8EDE", "#4ECDC4","#011a40","#d6a273","#cccccc", "#f2d378", "#CF000F"},
  37.     conundrum = {"VERITABLE", "FARMHOUSE", "TERRAFORM", "DISESTEEM", "MUSTACHIO", "ROBOTLIKE", "FORNICATE", "GERMINATE", "SPITELESS", "COURTESAN", "REPERTORY", "ANECTODES", "PROTOTYPE", "CORRALLED", "OLIGARCHY", "FIREARMED", "KISSINGLY", "SEMBLANCE", "UNGRASPED", "REMODELER", "TRACTABLE", "UNPLEDGED", "PARLEYING", "SLOPPIEST", "WINDMILLS", "CABDRIVER", "BLACKMAIL", "DISTURBED", "PREACCEPT", "GASOMETER", "PLUMMIEST", "REWARDING", "STREAMING", "GROUNDNUT", "PREFLAVOR", "SUSPICION", "ENCRIMSON", "ALIBILITY", "ANTIPODES", "UNGENERIC", "GROVELLER", "RESALABLE", "REPATTERN", "IMPLODING", "PARAMOUNT", "BIRTHROOT", "THORNIEST", "CURBSTONE", "UNCONCERN", "ICONOLOGY", "FRUITIEST", "EXTENSIVE", "WHINNYING", "JUICELESS", "INTERMEAN", "FAULTLESS", "ANTARCTIC", "DRIVEABLE", "BARBARIAN", "SOAKINGLY", "REBELLION", "EVAPORATE", "THROBBING", "ABUSIVELY", "PARALYSER", "UNSTAYING", "IMPULSION", "JOBCENTRE", "CLEANABLE", "SUNLESSLY", "SQUIRMIER", "ESTIMATED", "ANNECTANT", "CHAINSAWS", "SORCEROUS", "TRANSITION", "EXCEPTION", "BRICKIEST", "STAVEABLE", "DEALATION", "VISIONARY", "RIVETLESS", "CASTRATES", "MANDATING", "MANDATORY", "WOODLANDS", "SERRATING", "EXCAVATED", "PENUMBRAS", "ERECTIONS", "EJACULATE", "ARGUMENTS", "DEMANDING", "SEPULCHRE", "BARRICADE", "INGENIOUS", "HAPPINESS", "CARESSING", "ELEVATION", "WARDROBES", "TENEBROUS", "TURNSTILE", "IMPORTANT", "MAMMARIES", "CONUNDRUM", "CASCADING", "GARDENING", "IMBECILES", "ANTHROPOD", "ANTEATERS", "ALTERNATE", "PLENILUNE", "ANCHOVIES",
  38.      "MISERABLE", "OCCULTISM", "NEPTUNIUM", "BLUNDERED", "SPAGHETTI", "ATTACKING", "MERIDIAN", "SPOKESMAN", "ARMENIANS", "GALAVANTS", "VALIDATES"   }
  39. }
  40.  
  41. local status = {
  42.     playing = {},
  43.     timer = settings.timerCounter,
  44.     started = false,
  45.     claims = {},
  46.     numberMarkableClaims = {},
  47.     round = 0,
  48.     roundCtr = table.copy(settings.roundOrdering),
  49.     letters = "",
  50.     numbers = {},
  51.     targ = 0,
  52.     ingame = false,
  53.     conundrum = "",
  54.     conundrumGuesser = nil,
  55.     playerOperandOne = {},
  56.     playerOperandTwo = {},
  57.     playerOp = {},
  58.     playerNums = {}
  59. }
  60.  
  61. local ids = {
  62.     topLeft = 1444,
  63.     topRight = 1445,
  64.     topCenter = 9996,
  65.     main = 1221,
  66.     cardSummary = 8888,
  67.     commands = 9999,
  68.     helpn = 9990,
  69.     helpl = 9991,
  70.     helpc = 9992,
  71.     timer = 6666,
  72.     conundrum = 123,
  73.     numbers = 7777,
  74.     plus = 344,
  75.     minus = 345,
  76.     times = 346,
  77.     div = 347,
  78.     clear = 348
  79. }
  80.  
  81. function eventLoop(t, r)
  82.     if status.started == true then
  83.         if(status.timer <= 0) then
  84.             if #status.roundCtr == 1 then
  85.                 -- If no one guessed the conundrum
  86.                 endFullGame()
  87.                 return
  88.             end
  89.             endGame()
  90.             return
  91.         end
  92.         status.timer = status.timer - 0.50
  93.         renderTimer(status.timer)
  94.     end
  95.     table.print(status.roundCtr)
  96. end
  97.  
  98. function endGame()
  99.     status.started = false
  100.     status.playerOperandOne = {}
  101.     status.playerNums = {}
  102.     status.playerOperandTwo = {}
  103.     status.playerOp = {}    settings.numbersBig = {100, 75, 25, 50}
  104.     status.timer = settings.timerCounter
  105.     ui.addTextArea(ids.topLeft, "ROUND ENDED ADMIN WILL ADJUDICATE POINTS ", nil, 20, 30, 300, 50, nil, nil, 1, true)
  106.     -- Remove card UI and show guesses
  107.     ui.removeTextArea(ids.main, nil)
  108.     -- Magic numbers relate to fixed ids in card gen.
  109.     for i=1, 10, 1 do
  110.         ui.removeTextArea(i, nil)
  111.     end
  112.     -- Magic numbers relate to new numsids in card gen.
  113.     for i=554, 560, 1 do
  114.         ui.removeTextArea(i, nil)
  115.     end
  116.     -- Timer UI
  117.     timerIn = nil
  118.     ui.removeTextArea(ids.timer, nil)
  119.    
  120.     -- Numbers UI
  121.     ui.removeTextArea(ids.numbers, nil)
  122.    
  123.     -- Numbers calc UI
  124.     ui.removeTextArea(ids.plus, nil)
  125.     ui.removeTextArea(ids.minus, nil)
  126.     ui.removeTextArea(ids.times, nil)
  127.     ui.removeTextArea(ids.div, nil)
  128.     ui.removeTextArea(ids.clear, nil)
  129.    
  130.     -- Conundrum for testing
  131.     ui.removeTextArea(ids.conundrum, nil)
  132.    
  133.     local frmt = "<br />"
  134.     if next(status.claims) == nil then
  135.         frmt = "<p align='center'><font size='20px' color='white'><b> No valid guesses... type !next for next round. </b></p>"
  136.     end
  137.    
  138.     local hgh = 10
  139.    
  140.     -- Seperate for numbers / letters due to ordering
  141.     if status.roundCtr[1] == "L" then
  142.         -- hacky columns because html seems rejected?
  143.         local col = 1
  144.         for key,value in spairs(status.claims, function(t,a,b) return string.len(t[b]) < string.len(t[a]) end) do
  145.             hgh = string.len(value)
  146.             if hgh == nil then hgh = 10 end
  147.             if col % 2 == 1 then
  148.                 frmt = frmt .. "<p align='left'><font size='20px' color='" .. settings.highlights[hgh] .. "'><b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='event:win=" ..key .. "'>" .. key .. " &lt;-&gt; " .. value .. "</a></font></b>"
  149.             else
  150.                 frmt = frmt .. "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='20px' color='" .. settings.highlights[hgh] .. "'><b><a href='event:win=" .. key .. "'>" .. key .. " &lt;-&gt; " .. value  .. "  </a></b></font></p>"
  151.             end
  152.             col = col + 1
  153.         end
  154.     elseif status.roundCtr[1] == "N" then
  155.         -- hacky columns because html seems rejected?
  156.         local col = 1
  157.         for key,value in spairs(status.claims, function(t,a,b) return math.abs(status.targ - t[b]) > math.abs(status.targ - t[a]) end) do
  158.             local ul = ""
  159.             table.print(status.numberMarkableClaims)
  160.             if contains(table.keys(status.numberMarkableClaims), key) then ul = "<u>" end
  161.             hgh = 9 - math.abs(status.targ - value)
  162.             if hgh > 9 or hgh < 0 then hgh = 10 end
  163.             if hgh == 0 then hgh = 1 end
  164.             if col % 2 == 1 then
  165.                 frmt = frmt .. "<p align='left'><font size='20px' color='" .. settings.highlights[hgh] .. "'><b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='event:win=" ..key .. "'>" .. ul .. key .. " &lt;-&gt; " .. value .. "</a></font></b></u>"
  166.             else
  167.                 frmt = frmt .. "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font size='20px' color='" .. settings.highlights[hgh] .. "'><b><a href='event:win=" ..key .. "'>" .. ul ..  key .. " &lt;-&gt; " .. value  .. " </a></b></u></font></p>"
  168.             end
  169.             col = col + 1
  170.         end
  171.     end
  172.    
  173.        
  174.     -- Now let's add in the other UI showing the guesses
  175.     ui.addTextArea(ids.main, frmt, nil, 30, 100, 765, 250, nil, nil, 0.8, true)
  176.    
  177.     if status.roundCtr[1] == "L" then
  178.         -- And a UI summarising the letters or numbers
  179.         ui.addTextArea(ids.cardSummary, "<p align='center'><font size='25px' color='white'><b> " .. status.letters .. " </b></p>", nil, 30, 330, 765, 40, nil, nil, 0.9, true)
  180.     elseif status.roundCtr[1] == "N" then
  181.         local nos = ""
  182.         for key,value in pairs(status.numbers) do
  183.             nos = nos .. value .. ", "
  184.         end
  185.         -- And a UI summarising the numbers + target
  186.         ui.addTextArea(ids.cardSummary, "<p align='center'><font size='25px' color='white'><b> Target: " .. status.targ .. " Numbers: " .. nos .. "</b></p>", nil, 30, 330, 765, 40, nil, nil, 0.9, true)
  187.     end
  188.    
  189.     status.letters = ""
  190.     status.numbers = {}
  191.    
  192. end
  193.  
  194. function endFullGame()
  195.     status.started = false
  196.     status.playerOperandOne = {}
  197.     status.playerNums = {}
  198.     status.playerOperandTwo = {}
  199.     status.playerOp = {}
  200.     ui.addTextArea(ids.topLeft, "<p align='center'><font size='15px' color='white'><b>The game has ended, type !join to play again.</b></font></p>", nil, 20, 30, 300, 50, nil, nil, 1, true)
  201.     -- Remove card UI and show guesses
  202.     ui.removeTextArea(ids.main, nil)
  203.     -- Magic numbers relate to fixed ids in card gen.
  204.     for i=1, 10, 1 do
  205.         ui.removeTextArea(i, nil)
  206.     end
  207.     -- Magic numbers relate to new numsids in card gen.
  208.     for i=554, 560, 1 do
  209.         ui.removeTextArea(i, nil)
  210.     end
  211.     -- Timer UI
  212.     timerIn = nil
  213.     ui.removeTextArea(ids.timer, nil)
  214.    
  215.     -- Numbers calc UI
  216.     ui.removeTextArea(ids.plus, nil)
  217.     ui.removeTextArea(ids.minus, nil)
  218.     ui.removeTextArea(ids.times, nil)
  219.     ui.removeTextArea(ids.div, nil)
  220.     ui.removeTextArea(ids.clear, nil)
  221.  
  222.    
  223.     -- Conundrum UI
  224.     ui.removeTextArea(ids.conundrum, nil)
  225.    
  226.    
  227.     local frmt
  228.     if status.conundrumGuesser == nil then
  229.        frmt = "<p align='center'><font size='20px' color='white'><b>The conundrum answer was: " .. status.conundrum .. "</b></font></p><br />"
  230.     else
  231.        frmt = "<p align='center'><font size='20px' color='white'><b>The conundrum answer was: " .. status.conundrum .. " and was answered by " .. status.conundrumGuesser .. "</b></font></p><br />"
  232.     end
  233.     local col = 1
  234.     for key,value in spairs(status.playing, function(t,a,b) return tonumber(t[b]) < tonumber(t[a]) end) do
  235.         if col % 2 == 1 then
  236.             frmt = frmt .. "<p align='left'><font size='20px' color='white'><b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#".. col .. ": " .. key .. " &lt;-&gt; " .. value
  237.         else
  238.             frmt = frmt .. "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#".. col .. ": " .. key .. " &lt;-&gt; " .. value  .. " </b></p>"
  239.         end
  240.         col = col + 1
  241.     end
  242.        
  243.     -- Now let's add in the other UI showing the guesses
  244.     ui.addTextArea(ids.main, frmt, nil, 30, 100, 765, 250, nil, nil, 0.8, true)
  245.    
  246.     status.timer = settings.timerCounter
  247.     status.ingame = false
  248.     status.conundrum = ""
  249.     status.conundrumGuesser = nil
  250.     status.playing = {}
  251.     status.round = 0
  252.     status.roundCtr = table.copy(settings.roundOrdering)
  253. end
  254.  
  255.  
  256. function renderPlayers()
  257.     local v = "Playing: "
  258.     for key,value in spairs(status.playing, function(t,a,b) return tonumber(t[b]) < tonumber(t[a]) end) do
  259.         v = v .. key .. " : " .. value .. ", "
  260.     end
  261.     ui.addTextArea(ids.topRight, v, nil, 540, 30, 250, 50, nil, nil, 1, true)
  262. end
  263.  
  264. function renderRecent(p, v)
  265.     ui.addTextArea(ids.topCenter, "<p align='center'><font size='20px' color='white'><b>" .. v .. "</b></font></p>", p, 340, 30, 170, 50, nil, nil, 1, true)
  266. end
  267.  
  268.  
  269. function main()
  270.     tfm.exec.disableAutoNewGame(true)
  271.     tfm.exec.disableAutoShaman(true)
  272.     tfm.exec.disableAutoScore(true)
  273.     tfm.exec.disableAutoTimeLeft(true)
  274.     ui.addTextArea(ids.topLeft, "<p align='center'><font size='15px' color='white'><b>Type !join to play and !commands for help.</b></font></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  275. end
  276.  
  277. -- Available command
  278. function eventChatCommand(p, cmd)
  279.  
  280.     if contains(settings.admins, p) then
  281.         if cmd == "start" and table.length(status.playing) > 1 and status.ingame == false then
  282.             status.ingame = true
  283.             ui.addTextArea(ids.topLeft, "<p align='center'><font size='15px' color='white'><b>STARTING GAME ... </b></font></p>", nil, 20, 30, 300, 50, nil, nil, 1, true)
  284.             initLayout()
  285.             renderCardsForNumbers()
  286.             status.started = true
  287.             status.round = status.round + 1
  288.             return
  289.         end
  290.         if cmd == "next" and table.length(status.playing) > 1 and status.ingame == true then
  291.             -- Lua caps to two operands???
  292.             if status.started == false then
  293.                 table.remove(status.roundCtr, 1)
  294.                 -- Remove summary
  295.                 ui.removeTextArea(ids.cardSummary, nil)
  296.                 -- Add new round
  297.                 initLayout()
  298.                 if status.roundCtr[1] == "L" then
  299.                     ui.addTextArea(ids.topLeft, "<p align='center'><font size='25px' color='white'><b>LETTERS</b></font></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  300.                     renderCardsForLetters()
  301.                 elseif status.roundCtr[1] == "N" then
  302.                     ui.addTextArea(ids.topLeft, "<p align='center'><font size='25px' color='white'><b>NUMBERS</b></font></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  303.                     renderCardsForNumbers()
  304.                 elseif status.roundCtr[1] == "C" then
  305.                     ui.addTextArea(ids.topLeft, "<p align='center'><font size='25px' color='white'><b>CONUNDRUM</b></font></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  306.                     renderCardsForConundrum()
  307.                 end                    
  308.                 status.started = true
  309.                 status.claims = {}
  310.                 status.round = status.round + 1
  311.                 return
  312.             end
  313.         end
  314.        
  315.         if cmd == "winall" then
  316.             if status.started == false then
  317.                 if status.roundCtr[1] == "L" then
  318.                     for k,v in pairs(status.claims) do
  319.                         status.playing[k] = status.playing[k] + string.len(status.claims[k])
  320.                     end
  321.                 elseif status.roundCtr[1] == "N" then
  322.                        for k,v in pairs(status.claims) do
  323.                             if math.abs(status.targ - status.claims[k]) <= 10 and isint(math.abs(status.targ - status.claims[k])) then
  324.                                 status.playing[k] = status.playing[k] + 10 - math.abs(status.targ - status.claims[k])
  325.                             end
  326.                        end
  327.                    
  328.                 elseif status.roundCtr[1] == "C" then
  329.                     for k,v in pairs(status.claims) do
  330.                         -- 10 Points given to conundrum
  331.                        status.playing[k] = status.playing[k] + 10
  332.                     end
  333.                 end
  334.                 ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>All valid scores updated. </b></p>", nil)
  335.                 renderPlayers()
  336.             end
  337.         end
  338.        
  339.         if table.length(string.split(cmd, " ")) == 2 and string.split(cmd, " ")[1] == "win" and contains(table.keys(status.playing), firstUpper(string.split(cmd, " ")[2])) then
  340.             local targ = firstUpper(string.split(cmd, " ")[2])
  341.             if contains(table.keys(status.claims), targ) == false then
  342.                 return
  343.             end
  344.             if status.started == false then
  345.                 if status.roundCtr[1] == "L" then
  346.                    status.playing[targ] = status.playing[targ] + string.len(status.claims[targ])
  347.                    ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
  348.                        " score updated by " .. string.len(status.claims[targ]) .. "</b></p>", nil)
  349.                 elseif status.roundCtr[1] == "N" then
  350.                    if math.abs(status.targ - status.claims[targ]) <= 10 and isint(math.abs(status.targ - status.claims[targ])) then
  351.                        status.playing[targ] = status.playing[targ] + 10 - math.abs(status.targ - status.claims[targ])
  352.                        ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
  353.                        " score updated by " .. 10 - math.abs(status.targ - status.claims[targ]) .. "</b></p>", nil)
  354.                    end
  355.                 elseif status.roundCtr[1] == "C" then
  356.                     -- 10 Points given to conundrum in reality this could should never be called as its auto.
  357.                    status.playing[targ] = status.playing[targ] + 10
  358.                 end
  359.                 renderPlayers()
  360.             end
  361.         end
  362.        
  363.         if table.length(string.split(cmd, " ")) == 3 and string.split(cmd, " ")[1] == "adjust" and contains(table.keys(status.playing), firstUpper(string.split(cmd, " ")[2]))
  364.             and tonumber(string.split(cmd, " ")[3]) ~= nil then
  365.            
  366.             if status.started == false then
  367.                 ui.addTextArea(ids.topLeft, "<p align='center'><font size='15px' color='white'><b>" .. string.split(cmd, " ")[2] .. "'s score was changed to: " .. string.split(cmd, " ")[3] .. ".</b></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  368.                 status.playing[firstUpper(string.split(cmd, " ")[2])] = string.split(cmd, " ")[3]
  369.                 renderPlayers()
  370.             end
  371.         end
  372.        
  373.         if table.length(string.split(cmd, " ")) == 3 and string.split(cmd, " ")[1] == "sub" and contains(table.keys(status.playing), firstUpper(string.split(cmd, " ")[2]))
  374.             and tonumber(string.split(cmd, " ")[3]) ~= nil then
  375.            
  376.             if status.started == false then
  377.                 ui.addTextArea(ids.topLeft, "<p align='center'><font size='15px' color='white'><b>" .. string.split(cmd, " ")[3] .. " was taken from " .. string.split(cmd, " ")[2] .."'s score.</b></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  378.                 status.playing[firstUpper(string.split(cmd, " ")[2])] = status.playing[firstUpper(string.split(cmd, " ")[2])] - string.split(cmd, " ")[3]
  379.                 renderPlayers()
  380.             end
  381.         end
  382.        
  383.         if table.length(string.split(cmd, " ")) == 3 and string.split(cmd, " ")[1] == "add" and contains(table.keys(status.playing), firstUpper(string.split(cmd, " ")[2]))
  384.             and tonumber(string.split(cmd, " ")[3]) ~= nil then
  385.            
  386.             if status.started == false then
  387.                 ui.addTextArea(ids.topLeft, "<p align='center'><font size='15px' color='white'><b>" .. string.split(cmd, " ")[3] .. " was added to " .. string.split(cmd, " ")[2] .."'s score.</b></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  388.                 status.playing[firstUpper(string.split(cmd, " ")[2])] = status.playing[firstUpper(string.split(cmd, " ")[2])] + string.split(cmd, " ")[3]
  389.                 renderPlayers()
  390.             end
  391.         end
  392.        
  393.        
  394.     end
  395.    
  396.     if cmd == "join" and contains(table.keys(status.playing), p) == false then
  397.         ui.addTextArea(ids.topLeft, "<p align='center'><font size='15px' color='white'><b>" .. p .. " has joined.</b></p>", nil, 20, 30, 200, 50, nil, nil, 1, true)
  398.         status.playing[p] = 0
  399.         renderPlayers()
  400.     end
  401.    
  402.     if cmd == "commands" then
  403.         local popup = "<p align='center'><font size='30px' color='white'><b>Commands Menu - Read Carefully</b></font></p>" ..
  404.                       "<br /><p><font size='20px' color='white'><b>Admin Commands</b></font></p><br />" ..
  405.                       "<p><font size='12px' color='white'>!start - To start the game.</font></p>" ..
  406.                       "<p><font size='12px' color='white'>!next -  To start the next round after points have been set.</font></p>" ..
  407.                       "<p><font size='12px' color='white'>!win Username -  To mark a victory for the player. Points scoring is automatic. You may now also click on a player's name to award points instead.</font></p>" ..
  408.                       "<p><font size='12px' color='white'>!winall -  Everyone who guessed on that round is automatically given points.</font></p>" ..
  409.                       "<p><font size='12px' color='white'>!adjust Username actualpoints -  In case of a mistake, you can set points manually such as !adjust Kenill 2.</font></p>" ..
  410.                       "<p><font size='12px' color='white'>!sub Username pointstosubtract -  Subtract points from the players score !sub Kenill 69.</font></p>" ..
  411.                       "<p><font size='12px' color='white'>!add Username actualpoints -  Add points from the players score !add Iceoccultism 111.</font></p>" ..
  412.                       "<br /><p><font size='20px' color='white'><b>Everyone's Commands</b></font></p><br />" ..
  413.                       "<p><font size='12px' color='white'>!join - To join the game.</font></p>" ..
  414.                       "<p><font size='12px' color='white'>! yourguess -  To set your guess WITH THE SPACE so that no one can see it. Only most recent guess is valid.</font></p>" ..
  415.                       "<p><font size='12px' color='white'>!helpn !helpl !helpc  -  To view help on the numbers, letters and conundrum game respectively</font></p>"
  416.                    
  417.         ui.addPopup(ids.commands, 0, popup , p, 70, 30, 600, true)
  418.     end
  419.    
  420.     if cmd == "helpn" then
  421.         local popup = "<p align='center'><font size='30px' color='white'><b>Help Menu - Read Carefully</b></font></p>" ..
  422.                       "<br /><p><font size='15px' color='white'><b>Number Game Rules</b></font></p><br />" ..
  423.                       "<p><font size='12px' color='#D24D57'>**WHEN MARKING THE NUMBERS GAMES, UNDERLINED ANSWERS NEED MANUAL VERIFICATION**</font></p>" ..
  424.                       "<p><font size='15px' color='white'>Using each number only once, and using only the operations +, -, *, /, attempt " ..
  425.                       "to reach the target number. You don't have to use all the numbers if you don't want to. To set your answer use the clickable" ..
  426.                       " interface clicking the numbers to arrive to your totals, on the bottom left in progress calculations are shown. Use those" ..
  427.                       " numbers within your calculation. Clear your method and start anew with 'C'. On the other manually submit the number you got " ..
  428.                       "by typing ! 555 where 555 would be number you got, then explain your method to the admin in chat. This UI is still under construction/discussion.</font></p>" ..
  429.                       "<br /><p><font size='20px' color='white'><b>If you're noob and still confused /c Iceoccultism halp</b></font></p><br />"
  430.  
  431.                    
  432.         ui.addPopup(ids.helpn, 0, popup , p, 70, 30, 600, true)
  433.     end
  434.    
  435.     if cmd == "helpl" then
  436.         local popup = "<p align='center'><font size='30px' color='white'><b>Help Menu - Read Carefully</b></font></p>" ..
  437.                      
  438.                       "<br /><p><font size='20px' color='white'><b>Letters Game Rules</b></font></p><br />" ..
  439.                       "<p><font size='15px' color='white'>Using each letter only once, try to get the biggest valid English word from the letters available" ..
  440.                       " on screen. For example if the letters are ABCDEFGHI and you find the word 'BAD' in there do ! bad for that to be submitted as your"
  441.                       .. " latest guess. You don't have to use all your letters of course and you can't use a letter more than once.</font></p>" ..
  442.                       "<br /><p><font size='20px' color='white'><b>If you're noob and still confused /c Iceoccultism halp</b></font></p><br />"
  443.  
  444.                    
  445.         ui.addPopup(ids.helpl, 0, popup , p, 70, 30, 600, true)
  446.     end
  447.    
  448.     if cmd == "helpc" then
  449.         local popup = "<p align='center'><font size='30px' color='white'><b>Help Menu - Read Carefully</b></font></p>" ..
  450.                       "<br /><p><font size='20px' color='white'><b>Conundrum Rules</b></font></p><br />" ..
  451.                       "<p><font size='15px' color='white'>You will be presented a 9 letter scrambled word. Your job is to unscramble it and guess it. For example if the conundrum is 'bedsdeath' then the unscrambled version is ! deathbed so guess that. The conundrum is always the last round. </font></p>" ..
  452.                       "<br /><p><font size='20px' color='white'><b>If you're noob and still confused /c Iceoccultism halp</b></font></p><br />"
  453.  
  454.                    
  455.         ui.addPopup(ids.helpc, 0, popup , p, 70, 30, 600, true)
  456.     end
  457.        
  458.     if status.started == true and contains(settings.keys, cmd) == false then
  459.         local sguess = string.gsub(cmd, "[^A-Za-z0-9]+", "")
  460.         sguess = string.upper(sguess)
  461.  
  462.         -- Stops autopad cheating and guessings words not there
  463.         if status.roundCtr[1] == "L" then
  464.             if isMakeableFromLetters(status.letters, sguess) == true and contains(table.keys(status.playing), p) == true
  465.             and string.len(sguess) <= 9 then
  466.                 renderRecent(p, sguess)
  467.                 status.claims[p] = sguess
  468.             else
  469.                 renderRecent(p, "Invalid")
  470.             end
  471.         end
  472.        
  473.         print (string.len(sguess))
  474.         print (status.roundCtr[1])
  475.         print (tonumber(sguess))
  476.         -- Correct format + Number round // MUST BE MARKED MANUALLY BY ADMIN BY VERIFYING METHOD
  477.         if status.roundCtr[1] == "N" and tonumber(sguess) ~= nil and string.len(sguess) <= 4 then
  478.           status.claims[p] = sguess
  479.           renderRecent(p, sguess)
  480.           status.numberMarkableClaims[p] = sguess
  481.         elseif status.roundCtr[1] == "N" and tonumber(sguess) == nil then
  482.           renderRecent(p, "Invalid")
  483.         end
  484.        
  485.         -- Simply check if its the conundrum
  486.  
  487.         if status.roundCtr[1] == "C" and sguess == status.conundrum then
  488.             -- Auto ends the game and gives points.
  489.             status.playing[p] = status.playing[p] + 10
  490.              ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. p .. "'s" ..
  491.                        " score updated by 10</b></p>", nil)
  492.             status.conundrumGuesser = p
  493.             renderRecent(p, sguess)
  494.             endFullGame()
  495.         elseif status.roundCtr[1] == "C" and sguess ~= status.conundrum then
  496.             renderRecent(p, "Incorrect")
  497.         end
  498.        
  499.     end
  500. end
  501.  
  502.  
  503. -- Where layout displayed
  504. function initLayout()
  505.     ui.addTextArea(ids.main, "", nil, 30, 100, 765, 250, nil, nil, 0.8, true)
  506. end
  507.  
  508. function renderModifiers()
  509.     ui.addTextArea(ids.plus, "<p align='center'><a href='event:plus'><br /><font size='15px' color='#ffffff'><b>+</b></a></p>", nil, 470, 360, 50, 40, nil, nil, 1, true)
  510.     ui.addTextArea(ids.minus, "<p align='center'><a href='event:minus'><br /><font size='15px' color='#ffffff'><b>-</b></a></p>", nil, 530, 360, 50, 40, nil, nil, 1, true)
  511.     ui.addTextArea(ids.times, "<p align='center'><a href='event:times'><br /><font size='15px' color='#ffffff'><b>*</b></a></p>", nil, 590, 360, 50, 40, nil, nil, 1, true)
  512.     ui.addTextArea(ids.div, "<p align='center'><a href='event:div'><br /><font size='15px' color='#ffffff'><b>/</b></a></p>", nil, 650, 360, 50, 40, nil, nil, 1, true)
  513.     ui.addTextArea(ids.clear, "<p align='center'><a href='event:clear'><br /><font size='15px' color='#ffffff'><b>C</b></a></p>", nil, 710, 360, 50, 40, nil, nil, 1, true)
  514.  
  515. end
  516.  
  517. function reRenderNumbers(name)
  518.  
  519.     status.playerOperandOne[name] = nil
  520.     status.playerOperandTwo[name] = nil
  521.     status.playerOp[name] = nil
  522.     status.playerNums[name] = nil
  523.  
  524.     for i = 1, table.length(status.numbers), 1 do
  525.         ui.updateTextArea(i, "<p align='center'><br /><a href='event:clicked=".. status.numbers[i] .."'><font size='30px' color='#22313F'><b> " .. status.numbers[i] .. " </b></p>" ,name)
  526.     end
  527.    
  528.     -- Ew, magic numbers. :[
  529.     for i = 554, 560, 1 do
  530.         ui.removeTextArea(i, name)
  531.     end
  532.    
  533. end
  534.  
  535. function renderCardsForNumbers()
  536.     -- Increase the time.
  537.     status.timer = settings.timerCounterNum
  538.     renderModifiers()
  539.    
  540.     local big = math.random(1, 3)
  541.     local off = 0
  542.     local j = 1
  543.    
  544.     -- Pick big amount of big numbers
  545.      for i=1, big, 1 do
  546.         local bg = table.shuffle(settings.numbersBig)[1]
  547.         table.insert(status.numbers, bg)
  548.          -- Limited selection for big.
  549.         table.remove(settings.numbersBig, 1)
  550.         ui.addTextArea(i, "<p align='center'><br /><a href='event:clicked=".. bg .."'><font size='30px' color='#22313F'><b> " .. bg .. " </b></p>", nil, 5 + i*110, 130, 95, 80, 0xffffff, 0x000000, 1, true)
  551.         off = 5 + i*110
  552.         j = i
  553.      end
  554.      -- Pick Small Nos now.
  555.      for i=1, settings.no - big, 1 do
  556.         local sm = table.shuffle(settings.numbers)[1]
  557.         table.insert(status.numbers, sm)
  558.         ui.addTextArea(j+i, "<p align='center'><br /><a href='event:clicked=".. sm .."'><font size='30px' color='#22313F'><b> " .. sm .. " </b></p>", nil, off + i*110, 130, 95, 80, 0xffffff, 0x000000, 1, true)
  559.      end
  560.      
  561.     local targ = math.random(101, 999)
  562.     status.targ = targ
  563.     ui.addTextArea(ids.numbers, "<p align='center'><br /><font size='30px' color='#22313F'><b>Target: " .. targ .. " </b></p>", nil, 55, 260, 285, 80, 0xffffff, 0x000000, 1, true)
  564.  
  565.      
  566. end
  567.  
  568. function renderCardsForLetters()
  569.     -- Countdown always nine letters, randomly generate between 2-5 vowels, rest consonants
  570.    
  571.     -- make 2 vowels really rare.
  572.     local twoVowels = math.random(1, 8)
  573.     local vowels
  574.    
  575.     if twoVowels == 7 then
  576.         vowels = 2
  577.     else
  578.         vowels = math.random(3, 5)
  579.     end
  580.    
  581.     local lt = {}
  582.    
  583.     -- Pick vowels amount of vowels
  584.      for i=1, vowels, 1 do
  585.         local vow = table.shuffle(settings.vowels)[1]
  586.         table.insert(lt, vow)
  587.      end
  588.  
  589.      for i=1, settings.letters - vowels, 1 do
  590.         local cns = table.shuffle(settings.consonants)[1]
  591.         table.insert(lt, cns)
  592.      end
  593.      
  594.      table.shuffle(lt)
  595.      
  596.      for i=1, settings.letters, 1 do
  597.         status.letters = status.letters .. lt[i]
  598.      end
  599.      
  600.      -- Render randomly.
  601.      for i=1, settings.letters, 1 do
  602.         ui.addTextArea(i, "<p align='center'><br /><font size='30px' color='#22313F'><b> " .. lt[i] .. " </b></p>", nil, 33 + i*70, 130, 55, 80, 0xffffff, 0x000000, 1, true)
  603.      end
  604.      
  605. end
  606.  
  607. function renderCardsForConundrum()
  608.     -- Countdown always nine letters, from a set list.
  609.     -- Pick random word
  610.     local cndrm = table.shuffle(settings.conundrum)[1]
  611.     local tb = {}
  612.     status.conundrum = cndrm
  613.    
  614.     for i = 1, #cndrm do
  615.         table.insert(tb, string.sub(cndrm,i,i))
  616.     end
  617.    
  618.     local shuffledCndrm = table.shuffle(tb)
  619.    
  620.     ui.addTextArea(ids.conundrum, "<p align='center'><br /><font size='25px' color='#22313F'><b>CONUNDRUM</b></p>", nil, 55, 260, 285, 80, 0x95A5A6, 0xffffff, 1, true)
  621.    
  622.     for i=1, string.len(cndrm), 1 do
  623.         ui.addTextArea(i, "<p align='center'><br /><font size='30px' color='#22313F'><b> " .. shuffledCndrm[i] .. " </b></p>", nil, i*70, 130, 55, 80, 0xffffff, 0x000000, 1, true)
  624.     end
  625.      
  626. end
  627.  
  628. timerIn = nil
  629.  
  630. -- Updated by a timer periodically, this is the UI
  631. function renderTimer(rem)
  632.     if timerIn == nil then
  633.         ui.addTextArea(ids.timer, "<p align='center'><br /><font size='50px' color='#ffffff'><b>Timer: " .. rem .. " </b></p>", nil, 400, 233, 300, 90, 0x000000, 0x000000, 1, true)
  634.     else
  635.         ui.updateTextArea(ids.timer, "<p align='center'><br /><font size='50px' color='#ffffff'><b>Timer: " .. rem .. " </b></p>", nil)
  636.     end
  637. end
  638.  
  639. -- Utilities.
  640.  
  641. function table.shuffle(t)
  642.     local t = t
  643.     local n = #t
  644.     local j
  645.     local random = math.random
  646.     for i = 1, n do
  647.         j = random(i)
  648.         t[j],t[i] = t[i],t[j]
  649.     end
  650.     return t
  651. end
  652.  
  653. function table.length(T)
  654.   local count = 0
  655.   for _ in pairs(T) do count = count + 1 end
  656.   return count
  657. end
  658.  
  659.  
  660. function contains(t, val)
  661.    for i=1,#t do
  662.       if t[i] == val then
  663.          return true
  664.       end
  665.    end
  666.    return false
  667. end
  668.  
  669. function isMakeableFromLetters(letters, guess)
  670.     -- Convert to table
  671.     local tb = {}
  672.     for i = 1, #letters do
  673.         table.insert(tb, string.sub(letters,i,i))
  674.     end
  675.    
  676.     local gb = {}
  677.     for i = 1, #guess do
  678.         table.insert(gb, string.sub(guess,i,i))
  679.     end
  680.  
  681.     for i = 1, #guess do
  682.         if contains(tb, gb[i]) == false then
  683.             return false
  684.         end
  685.         -- else we remove from table to show its been used
  686.         for j = 1, #letters do
  687.             if tb[j] == gb[i] then
  688.                 table.remove(tb, j)
  689.                 break
  690.             end
  691.         end
  692.     end
  693.     return true
  694. end
  695.  
  696. function table.print(t)
  697.     local tx = ""
  698.     for k, v in pairs( t ) do
  699.         tx = tx .. v
  700.     end
  701.     print(tx)
  702. end
  703.  
  704.  
  705. function table.keys(t)
  706.     local t, r = t, {}
  707.     for k in pairs(t) do
  708.         table.insert(r, k)
  709.     end
  710.     return r
  711. end
  712.  
  713. function string.split(t, s)
  714.     local r = {}
  715.     for p in string.gmatch(t, "[^" .. (s or "%s") .. "]+") do
  716.         table.insert(r, p)
  717.     end
  718.     return r
  719. end
  720.  
  721. -- http://stackoverflow.com/questions/15706270/sort-a-table-in-lua
  722. function spairs(t, order)
  723.     -- collect the keys
  724.     local keys = {}
  725.     for k in pairs(t) do keys[#keys+1] = k end
  726.  
  727.     -- if order function given, sort by it by passing the table and keys a, b,
  728.     -- otherwise just sort the keys
  729.     if order then
  730.         table.sort(keys, function(a,b) return order(t, a, b) end)
  731.     else
  732.         table.sort(keys)
  733.     end
  734.  
  735.     -- return the iterator function
  736.     local i = 0
  737.     return function()
  738.         i = i + 1
  739.         if keys[i] then
  740.             return keys[i], t[keys[i]]
  741.         end
  742.     end
  743. end
  744.  
  745. function firstUpper(txt)
  746.     return txt:sub(1,1):upper() .. txt:sub(2):lower()
  747. end
  748.  
  749. local magicId = 554
  750.  
  751. -- Worst parser ever
  752. function eventTextAreaCallback(id,name,callback)
  753.     -- Admin Click to win UI
  754.     if string.split(callback, "=")[1] == "win" and contains(settings.admins, name) then
  755.         local targ = string.split(callback, "=")[2]
  756.         if status.started == false then
  757.             if status.roundCtr[1] == "L" then
  758.                status.playing[targ] = status.playing[targ] + string.len(status.claims[targ])
  759.                ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
  760.                    " score updated by " .. string.len(status.claims[targ]) .. "</b></p>", nil)
  761.             elseif status.roundCtr[1] == "N" then
  762.                if math.abs(status.targ - status.claims[targ]) <= 10 and isint(math.abs(status.targ - status.claims[targ])) then
  763.                    status.playing[targ] = status.playing[targ] + 10 - math.abs(status.targ - status.claims[targ])
  764.                    ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
  765.                    " score updated by " .. 10 - math.abs(status.targ - status.claims[targ]) .. "</b></p>", nil)
  766.                end
  767.             elseif status.roundCtr[1] == "C" then
  768.                 -- 10 Points given to conundrum in reality this could should never be called as its auto.
  769.                status.playing[targ] = status.playing[targ] + 10
  770.             end
  771.             renderPlayers()
  772.         end
  773.     end
  774.  
  775.     -- Numbers UI
  776.     if string.split(callback, "=")[1] == "clicked" then
  777.         if status.playerOperandOne[name] == nil then
  778.             ui.updateTextArea(id, "<p align='center'><br /><font size='30px' color='#ff0000'><b>" .. string.split(callback, "=")[2] .. "</b></p>", name)
  779.             status.playerOperandOne[name] = tonumber(string.split(callback, "=")[2])
  780.             status.claims[name] = tonumber(string.split(callback, "=")[2])
  781.             status.numberMarkableClaims[name] = nil
  782.             renderRecent(name, string.split(callback, "=")[2])
  783.             return
  784.         end
  785.     end
  786.    
  787.     if callback == "plus" and status.playerOperandOne[name] ~= nil then
  788.         status.playerOp[name] = "+"
  789.         renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
  790.         return
  791.     end
  792.    
  793.     if callback == "minus" and status.playerOperandOne[name] ~= nil then
  794.         status.playerOp[name] = "-"
  795.         renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
  796.         return
  797.     end
  798.    
  799.     if callback == "times" and status.playerOperandOne[name] ~= nil then
  800.         status.playerOp[name] = "*"
  801.         renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
  802.         return
  803.     end
  804.    
  805.     if callback == "div" and status.playerOperandOne[name] ~= nil then
  806.         status.playerOp[name] = "/"
  807.         renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
  808.         return
  809.     end
  810.    
  811.     if callback == "clear" then
  812.         reRenderNumbers(name)
  813.         return
  814.     end
  815.    
  816.    
  817.     if string.split(callback, "=")[1] == "clicked" then
  818.         if status.playerOperandTwo[name] == nil and status.playerOp[name] ~= nil then
  819.             ui.updateTextArea(id, "<p align='center'><br /><font size='30px' color='#ff0000'><b>" .. string.split(callback, "=")[2] .. "</b></p>", name)
  820.             status.playerOperandTwo[name] = tonumber(string.split(callback, "=")[2])
  821.             -- Let's parse this and add it as the first operation
  822.             local newNum
  823.             if status.playerOp[name] == "+" then
  824.                 newNum = status.playerOperandOne[name] + status.playerOperandTwo[name]
  825.             elseif status.playerOp[name] == "-" then
  826.                 newNum = status.playerOperandOne[name] - status.playerOperandTwo[name]
  827.             elseif status.playerOp[name] == "*" then
  828.                 newNum = status.playerOperandOne[name] * status.playerOperandTwo[name]
  829.             elseif status.playerOp[name] == "/" then
  830.                 newNum = status.playerOperandOne[name] / status.playerOperandTwo[name]
  831.             end
  832.             local tempId
  833.             -- Add Small UI, magic Ids 554->660 max
  834.             if status.playerNums[name] == nil or next(status.playerNums[name]) == nil then
  835.                 status.playerNums[name] = {magicId}
  836.                 tempId = magicId
  837.             else
  838.                 table.insert(status.playerNums[name], status.playerNums[name][table.length(status.playerNums[name])] + 1)  
  839.                 tempId = status.playerNums[name][table.length(status.playerNums[name])]
  840.             end
  841.             ui.addTextArea(tempId, "<p align='center'><a href='event:clicked=" .. newNum .. "'><br /><font size='15px' color='#ffffff'><b>" .. newNum .."</b></a></p>", name, 20 + (60 * (tempId - magicId)), 360, 50, 40, nil, nil, 1, true)
  842.             status.claims[name] = newNum
  843.             status.numberMarkableClaims[name] = nil
  844.  
  845.             renderRecent(name, newNum)
  846.             -- clear
  847.             status.playerOperandOne[name] = nil
  848.             status.playerOp[name] = nil
  849.             status.playerOperandTwo[name] = nil
  850.            
  851.             return
  852.         end
  853.     end
  854.    
  855.    
  856.    
  857. end
  858.  
  859. function isint(n)
  860.   return n==math.floor(n)
  861. end
  862.  
  863. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement