Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- COUNTDOWN GAME - Made by Iceoccultism, yes the code isn't great, feel free to update it but don't remove accreditations.
- -- Credits to Makinit's CAH which I got some utility functions from and some boilerplate from.
- -- TODO
- -- Maybe show them all one by one.
- -- Parser in UI ... needs far more work, and some sort of backstack + back button. :/
- -- Guard join on UI clicks
- system.disableChatCommandDisplay("", true)
- -- Function needs to be preloaded
- function table.copy(t)
- local t, r = t, {}
- local n = #t
- for i = 1, n do
- r[i] = t[i]
- end
- return r
- end
- local settings = {
- maxplayers = 8,
- timerCounter = 35,
- timerCounterNum = 45,
- letters = 9,
- no = 6,
- -- Yes the frequency is somewhat proportionate to what you see on actual English
- 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"},
- 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"},
- 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},
- numbersBig = {100, 75, 25, 50},
- admins = {"Iceoccultism", "Luminousity", "Willowshine", "Sassybaskets"},
- keys = {"remindertoremovethis"},
- -- You can change this around, however, the C [Conundrum] must always be last for now.
- roundOrdering = {"N", "L", "L", "N", "L", "L", "N", "L", "L", "L", "L", "N", "C"},
- highlights = {"#F7CA18","#F89406","#26A65B", "#BB8EDE", "#4ECDC4","#011a40","#d6a273","#cccccc", "#f2d378", "#CF000F"},
- 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",
- "MISERABLE", "OCCULTISM", "NEPTUNIUM", "BLUNDERED", "SPAGHETTI", "ATTACKING", "MERIDIAN", "SPOKESMAN", "ARMENIANS", "GALAVANTS", "VALIDATES" }
- }
- local status = {
- playing = {},
- timer = settings.timerCounter,
- started = false,
- claims = {},
- numberMarkableClaims = {},
- round = 0,
- roundCtr = table.copy(settings.roundOrdering),
- letters = "",
- numbers = {},
- targ = 0,
- ingame = false,
- conundrum = "",
- conundrumGuesser = nil,
- playerOperandOne = {},
- playerOperandTwo = {},
- playerOp = {},
- playerNums = {}
- }
- local ids = {
- topLeft = 1444,
- topRight = 1445,
- topCenter = 9996,
- main = 1221,
- cardSummary = 8888,
- commands = 9999,
- helpn = 9990,
- helpl = 9991,
- helpc = 9992,
- timer = 6666,
- conundrum = 123,
- numbers = 7777,
- plus = 344,
- minus = 345,
- times = 346,
- div = 347,
- clear = 348
- }
- function eventLoop(t, r)
- if status.started == true then
- if(status.timer <= 0) then
- if #status.roundCtr == 1 then
- -- If no one guessed the conundrum
- endFullGame()
- return
- end
- endGame()
- return
- end
- status.timer = status.timer - 0.50
- renderTimer(status.timer)
- end
- table.print(status.roundCtr)
- end
- function endGame()
- status.started = false
- status.playerOperandOne = {}
- status.playerNums = {}
- status.playerOperandTwo = {}
- status.playerOp = {} settings.numbersBig = {100, 75, 25, 50}
- status.timer = settings.timerCounter
- ui.addTextArea(ids.topLeft, "ROUND ENDED ADMIN WILL ADJUDICATE POINTS ", nil, 20, 30, 300, 50, nil, nil, 1, true)
- -- Remove card UI and show guesses
- ui.removeTextArea(ids.main, nil)
- -- Magic numbers relate to fixed ids in card gen.
- for i=1, 10, 1 do
- ui.removeTextArea(i, nil)
- end
- -- Magic numbers relate to new numsids in card gen.
- for i=554, 560, 1 do
- ui.removeTextArea(i, nil)
- end
- -- Timer UI
- timerIn = nil
- ui.removeTextArea(ids.timer, nil)
- -- Numbers UI
- ui.removeTextArea(ids.numbers, nil)
- -- Numbers calc UI
- ui.removeTextArea(ids.plus, nil)
- ui.removeTextArea(ids.minus, nil)
- ui.removeTextArea(ids.times, nil)
- ui.removeTextArea(ids.div, nil)
- ui.removeTextArea(ids.clear, nil)
- -- Conundrum for testing
- ui.removeTextArea(ids.conundrum, nil)
- local frmt = "<br />"
- if next(status.claims) == nil then
- frmt = "<p align='center'><font size='20px' color='white'><b> No valid guesses... type !next for next round. </b></p>"
- end
- local hgh = 10
- -- Seperate for numbers / letters due to ordering
- if status.roundCtr[1] == "L" then
- -- hacky columns because html seems rejected?
- local col = 1
- for key,value in spairs(status.claims, function(t,a,b) return string.len(t[b]) < string.len(t[a]) end) do
- hgh = string.len(value)
- if hgh == nil then hgh = 10 end
- if col % 2 == 1 then
- frmt = frmt .. "<p align='left'><font size='20px' color='" .. settings.highlights[hgh] .. "'><b> <a href='event:win=" ..key .. "'>" .. key .. " <-> " .. value .. "</a></font></b>"
- else
- frmt = frmt .. " <font size='20px' color='" .. settings.highlights[hgh] .. "'><b><a href='event:win=" .. key .. "'>" .. key .. " <-> " .. value .. " </a></b></font></p>"
- end
- col = col + 1
- end
- elseif status.roundCtr[1] == "N" then
- -- hacky columns because html seems rejected?
- local col = 1
- 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
- local ul = ""
- table.print(status.numberMarkableClaims)
- if contains(table.keys(status.numberMarkableClaims), key) then ul = "<u>" end
- hgh = 9 - math.abs(status.targ - value)
- if hgh > 9 or hgh < 0 then hgh = 10 end
- if hgh == 0 then hgh = 1 end
- if col % 2 == 1 then
- frmt = frmt .. "<p align='left'><font size='20px' color='" .. settings.highlights[hgh] .. "'><b> <a href='event:win=" ..key .. "'>" .. ul .. key .. " <-> " .. value .. "</a></font></b></u>"
- else
- frmt = frmt .. " <font size='20px' color='" .. settings.highlights[hgh] .. "'><b><a href='event:win=" ..key .. "'>" .. ul .. key .. " <-> " .. value .. " </a></b></u></font></p>"
- end
- col = col + 1
- end
- end
- -- Now let's add in the other UI showing the guesses
- ui.addTextArea(ids.main, frmt, nil, 30, 100, 765, 250, nil, nil, 0.8, true)
- if status.roundCtr[1] == "L" then
- -- And a UI summarising the letters or numbers
- 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)
- elseif status.roundCtr[1] == "N" then
- local nos = ""
- for key,value in pairs(status.numbers) do
- nos = nos .. value .. ", "
- end
- -- And a UI summarising the numbers + target
- 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)
- end
- status.letters = ""
- status.numbers = {}
- end
- function endFullGame()
- status.started = false
- status.playerOperandOne = {}
- status.playerNums = {}
- status.playerOperandTwo = {}
- status.playerOp = {}
- 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)
- -- Remove card UI and show guesses
- ui.removeTextArea(ids.main, nil)
- -- Magic numbers relate to fixed ids in card gen.
- for i=1, 10, 1 do
- ui.removeTextArea(i, nil)
- end
- -- Magic numbers relate to new numsids in card gen.
- for i=554, 560, 1 do
- ui.removeTextArea(i, nil)
- end
- -- Timer UI
- timerIn = nil
- ui.removeTextArea(ids.timer, nil)
- -- Numbers calc UI
- ui.removeTextArea(ids.plus, nil)
- ui.removeTextArea(ids.minus, nil)
- ui.removeTextArea(ids.times, nil)
- ui.removeTextArea(ids.div, nil)
- ui.removeTextArea(ids.clear, nil)
- -- Conundrum UI
- ui.removeTextArea(ids.conundrum, nil)
- local frmt
- if status.conundrumGuesser == nil then
- frmt = "<p align='center'><font size='20px' color='white'><b>The conundrum answer was: " .. status.conundrum .. "</b></font></p><br />"
- else
- 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 />"
- end
- local col = 1
- for key,value in spairs(status.playing, function(t,a,b) return tonumber(t[b]) < tonumber(t[a]) end) do
- if col % 2 == 1 then
- frmt = frmt .. "<p align='left'><font size='20px' color='white'><b> #".. col .. ": " .. key .. " <-> " .. value
- else
- frmt = frmt .. " #".. col .. ": " .. key .. " <-> " .. value .. " </b></p>"
- end
- col = col + 1
- end
- -- Now let's add in the other UI showing the guesses
- ui.addTextArea(ids.main, frmt, nil, 30, 100, 765, 250, nil, nil, 0.8, true)
- status.timer = settings.timerCounter
- status.ingame = false
- status.conundrum = ""
- status.conundrumGuesser = nil
- status.playing = {}
- status.round = 0
- status.roundCtr = table.copy(settings.roundOrdering)
- end
- function renderPlayers()
- local v = "Playing: "
- for key,value in spairs(status.playing, function(t,a,b) return tonumber(t[b]) < tonumber(t[a]) end) do
- v = v .. key .. " : " .. value .. ", "
- end
- ui.addTextArea(ids.topRight, v, nil, 540, 30, 250, 50, nil, nil, 1, true)
- end
- function renderRecent(p, v)
- 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)
- end
- function main()
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoScore(true)
- tfm.exec.disableAutoTimeLeft(true)
- 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)
- end
- -- Available command
- function eventChatCommand(p, cmd)
- if contains(settings.admins, p) then
- if cmd == "start" and table.length(status.playing) > 1 and status.ingame == false then
- status.ingame = true
- 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)
- initLayout()
- renderCardsForNumbers()
- status.started = true
- status.round = status.round + 1
- return
- end
- if cmd == "next" and table.length(status.playing) > 1 and status.ingame == true then
- -- Lua caps to two operands???
- if status.started == false then
- table.remove(status.roundCtr, 1)
- -- Remove summary
- ui.removeTextArea(ids.cardSummary, nil)
- -- Add new round
- initLayout()
- if status.roundCtr[1] == "L" then
- 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)
- renderCardsForLetters()
- elseif status.roundCtr[1] == "N" then
- 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)
- renderCardsForNumbers()
- elseif status.roundCtr[1] == "C" then
- 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)
- renderCardsForConundrum()
- end
- status.started = true
- status.claims = {}
- status.round = status.round + 1
- return
- end
- end
- if cmd == "winall" then
- if status.started == false then
- if status.roundCtr[1] == "L" then
- for k,v in pairs(status.claims) do
- status.playing[k] = status.playing[k] + string.len(status.claims[k])
- end
- elseif status.roundCtr[1] == "N" then
- for k,v in pairs(status.claims) do
- if math.abs(status.targ - status.claims[k]) <= 10 and isint(math.abs(status.targ - status.claims[k])) then
- status.playing[k] = status.playing[k] + 10 - math.abs(status.targ - status.claims[k])
- end
- end
- elseif status.roundCtr[1] == "C" then
- for k,v in pairs(status.claims) do
- -- 10 Points given to conundrum
- status.playing[k] = status.playing[k] + 10
- end
- end
- ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>All valid scores updated. </b></p>", nil)
- renderPlayers()
- end
- end
- 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
- local targ = firstUpper(string.split(cmd, " ")[2])
- if contains(table.keys(status.claims), targ) == false then
- return
- end
- if status.started == false then
- if status.roundCtr[1] == "L" then
- status.playing[targ] = status.playing[targ] + string.len(status.claims[targ])
- ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
- " score updated by " .. string.len(status.claims[targ]) .. "</b></p>", nil)
- elseif status.roundCtr[1] == "N" then
- if math.abs(status.targ - status.claims[targ]) <= 10 and isint(math.abs(status.targ - status.claims[targ])) then
- status.playing[targ] = status.playing[targ] + 10 - math.abs(status.targ - status.claims[targ])
- ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
- " score updated by " .. 10 - math.abs(status.targ - status.claims[targ]) .. "</b></p>", nil)
- end
- elseif status.roundCtr[1] == "C" then
- -- 10 Points given to conundrum in reality this could should never be called as its auto.
- status.playing[targ] = status.playing[targ] + 10
- end
- renderPlayers()
- end
- end
- if table.length(string.split(cmd, " ")) == 3 and string.split(cmd, " ")[1] == "adjust" and contains(table.keys(status.playing), firstUpper(string.split(cmd, " ")[2]))
- and tonumber(string.split(cmd, " ")[3]) ~= nil then
- if status.started == false then
- 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)
- status.playing[firstUpper(string.split(cmd, " ")[2])] = string.split(cmd, " ")[3]
- renderPlayers()
- end
- end
- if table.length(string.split(cmd, " ")) == 3 and string.split(cmd, " ")[1] == "sub" and contains(table.keys(status.playing), firstUpper(string.split(cmd, " ")[2]))
- and tonumber(string.split(cmd, " ")[3]) ~= nil then
- if status.started == false then
- 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)
- status.playing[firstUpper(string.split(cmd, " ")[2])] = status.playing[firstUpper(string.split(cmd, " ")[2])] - string.split(cmd, " ")[3]
- renderPlayers()
- end
- end
- if table.length(string.split(cmd, " ")) == 3 and string.split(cmd, " ")[1] == "add" and contains(table.keys(status.playing), firstUpper(string.split(cmd, " ")[2]))
- and tonumber(string.split(cmd, " ")[3]) ~= nil then
- if status.started == false then
- 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)
- status.playing[firstUpper(string.split(cmd, " ")[2])] = status.playing[firstUpper(string.split(cmd, " ")[2])] + string.split(cmd, " ")[3]
- renderPlayers()
- end
- end
- end
- if cmd == "join" and contains(table.keys(status.playing), p) == false then
- 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)
- status.playing[p] = 0
- renderPlayers()
- end
- if cmd == "commands" then
- local popup = "<p align='center'><font size='30px' color='white'><b>Commands Menu - Read Carefully</b></font></p>" ..
- "<br /><p><font size='20px' color='white'><b>Admin Commands</b></font></p><br />" ..
- "<p><font size='12px' color='white'>!start - To start the game.</font></p>" ..
- "<p><font size='12px' color='white'>!next - To start the next round after points have been set.</font></p>" ..
- "<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>" ..
- "<p><font size='12px' color='white'>!winall - Everyone who guessed on that round is automatically given points.</font></p>" ..
- "<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>" ..
- "<p><font size='12px' color='white'>!sub Username pointstosubtract - Subtract points from the players score !sub Kenill 69.</font></p>" ..
- "<p><font size='12px' color='white'>!add Username actualpoints - Add points from the players score !add Iceoccultism 111.</font></p>" ..
- "<br /><p><font size='20px' color='white'><b>Everyone's Commands</b></font></p><br />" ..
- "<p><font size='12px' color='white'>!join - To join the game.</font></p>" ..
- "<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>" ..
- "<p><font size='12px' color='white'>!helpn !helpl !helpc - To view help on the numbers, letters and conundrum game respectively</font></p>"
- ui.addPopup(ids.commands, 0, popup , p, 70, 30, 600, true)
- end
- if cmd == "helpn" then
- local popup = "<p align='center'><font size='30px' color='white'><b>Help Menu - Read Carefully</b></font></p>" ..
- "<br /><p><font size='15px' color='white'><b>Number Game Rules</b></font></p><br />" ..
- "<p><font size='12px' color='#D24D57'>**WHEN MARKING THE NUMBERS GAMES, UNDERLINED ANSWERS NEED MANUAL VERIFICATION**</font></p>" ..
- "<p><font size='15px' color='white'>Using each number only once, and using only the operations +, -, *, /, attempt " ..
- "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" ..
- " interface clicking the numbers to arrive to your totals, on the bottom left in progress calculations are shown. Use those" ..
- " numbers within your calculation. Clear your method and start anew with 'C'. On the other manually submit the number you got " ..
- "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>" ..
- "<br /><p><font size='20px' color='white'><b>If you're noob and still confused /c Iceoccultism halp</b></font></p><br />"
- ui.addPopup(ids.helpn, 0, popup , p, 70, 30, 600, true)
- end
- if cmd == "helpl" then
- local popup = "<p align='center'><font size='30px' color='white'><b>Help Menu - Read Carefully</b></font></p>" ..
- "<br /><p><font size='20px' color='white'><b>Letters Game Rules</b></font></p><br />" ..
- "<p><font size='15px' color='white'>Using each letter only once, try to get the biggest valid English word from the letters available" ..
- " 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"
- .. " 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>" ..
- "<br /><p><font size='20px' color='white'><b>If you're noob and still confused /c Iceoccultism halp</b></font></p><br />"
- ui.addPopup(ids.helpl, 0, popup , p, 70, 30, 600, true)
- end
- if cmd == "helpc" then
- local popup = "<p align='center'><font size='30px' color='white'><b>Help Menu - Read Carefully</b></font></p>" ..
- "<br /><p><font size='20px' color='white'><b>Conundrum Rules</b></font></p><br />" ..
- "<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>" ..
- "<br /><p><font size='20px' color='white'><b>If you're noob and still confused /c Iceoccultism halp</b></font></p><br />"
- ui.addPopup(ids.helpc, 0, popup , p, 70, 30, 600, true)
- end
- if status.started == true and contains(settings.keys, cmd) == false then
- local sguess = string.gsub(cmd, "[^A-Za-z0-9]+", "")
- sguess = string.upper(sguess)
- -- Stops autopad cheating and guessings words not there
- if status.roundCtr[1] == "L" then
- if isMakeableFromLetters(status.letters, sguess) == true and contains(table.keys(status.playing), p) == true
- and string.len(sguess) <= 9 then
- renderRecent(p, sguess)
- status.claims[p] = sguess
- else
- renderRecent(p, "Invalid")
- end
- end
- print (string.len(sguess))
- print (status.roundCtr[1])
- print (tonumber(sguess))
- -- Correct format + Number round // MUST BE MARKED MANUALLY BY ADMIN BY VERIFYING METHOD
- if status.roundCtr[1] == "N" and tonumber(sguess) ~= nil and string.len(sguess) <= 4 then
- status.claims[p] = sguess
- renderRecent(p, sguess)
- status.numberMarkableClaims[p] = sguess
- elseif status.roundCtr[1] == "N" and tonumber(sguess) == nil then
- renderRecent(p, "Invalid")
- end
- -- Simply check if its the conundrum
- if status.roundCtr[1] == "C" and sguess == status.conundrum then
- -- Auto ends the game and gives points.
- status.playing[p] = status.playing[p] + 10
- ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. p .. "'s" ..
- " score updated by 10</b></p>", nil)
- status.conundrumGuesser = p
- renderRecent(p, sguess)
- endFullGame()
- elseif status.roundCtr[1] == "C" and sguess ~= status.conundrum then
- renderRecent(p, "Incorrect")
- end
- end
- end
- -- Where layout displayed
- function initLayout()
- ui.addTextArea(ids.main, "", nil, 30, 100, 765, 250, nil, nil, 0.8, true)
- end
- function renderModifiers()
- 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)
- 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)
- 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)
- 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)
- 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)
- end
- function reRenderNumbers(name)
- status.playerOperandOne[name] = nil
- status.playerOperandTwo[name] = nil
- status.playerOp[name] = nil
- status.playerNums[name] = nil
- for i = 1, table.length(status.numbers), 1 do
- 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)
- end
- -- Ew, magic numbers. :[
- for i = 554, 560, 1 do
- ui.removeTextArea(i, name)
- end
- end
- function renderCardsForNumbers()
- -- Increase the time.
- status.timer = settings.timerCounterNum
- renderModifiers()
- local big = math.random(1, 3)
- local off = 0
- local j = 1
- -- Pick big amount of big numbers
- for i=1, big, 1 do
- local bg = table.shuffle(settings.numbersBig)[1]
- table.insert(status.numbers, bg)
- -- Limited selection for big.
- table.remove(settings.numbersBig, 1)
- 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)
- off = 5 + i*110
- j = i
- end
- -- Pick Small Nos now.
- for i=1, settings.no - big, 1 do
- local sm = table.shuffle(settings.numbers)[1]
- table.insert(status.numbers, sm)
- 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)
- end
- local targ = math.random(101, 999)
- status.targ = targ
- 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)
- end
- function renderCardsForLetters()
- -- Countdown always nine letters, randomly generate between 2-5 vowels, rest consonants
- -- make 2 vowels really rare.
- local twoVowels = math.random(1, 8)
- local vowels
- if twoVowels == 7 then
- vowels = 2
- else
- vowels = math.random(3, 5)
- end
- local lt = {}
- -- Pick vowels amount of vowels
- for i=1, vowels, 1 do
- local vow = table.shuffle(settings.vowels)[1]
- table.insert(lt, vow)
- end
- for i=1, settings.letters - vowels, 1 do
- local cns = table.shuffle(settings.consonants)[1]
- table.insert(lt, cns)
- end
- table.shuffle(lt)
- for i=1, settings.letters, 1 do
- status.letters = status.letters .. lt[i]
- end
- -- Render randomly.
- for i=1, settings.letters, 1 do
- 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)
- end
- end
- function renderCardsForConundrum()
- -- Countdown always nine letters, from a set list.
- -- Pick random word
- local cndrm = table.shuffle(settings.conundrum)[1]
- local tb = {}
- status.conundrum = cndrm
- for i = 1, #cndrm do
- table.insert(tb, string.sub(cndrm,i,i))
- end
- local shuffledCndrm = table.shuffle(tb)
- 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)
- for i=1, string.len(cndrm), 1 do
- 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)
- end
- end
- timerIn = nil
- -- Updated by a timer periodically, this is the UI
- function renderTimer(rem)
- if timerIn == nil then
- 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)
- else
- ui.updateTextArea(ids.timer, "<p align='center'><br /><font size='50px' color='#ffffff'><b>Timer: " .. rem .. " </b></p>", nil)
- end
- end
- -- Utilities.
- function table.shuffle(t)
- local t = t
- local n = #t
- local j
- local random = math.random
- for i = 1, n do
- j = random(i)
- t[j],t[i] = t[i],t[j]
- end
- return t
- end
- function table.length(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function contains(t, val)
- for i=1,#t do
- if t[i] == val then
- return true
- end
- end
- return false
- end
- function isMakeableFromLetters(letters, guess)
- -- Convert to table
- local tb = {}
- for i = 1, #letters do
- table.insert(tb, string.sub(letters,i,i))
- end
- local gb = {}
- for i = 1, #guess do
- table.insert(gb, string.sub(guess,i,i))
- end
- for i = 1, #guess do
- if contains(tb, gb[i]) == false then
- return false
- end
- -- else we remove from table to show its been used
- for j = 1, #letters do
- if tb[j] == gb[i] then
- table.remove(tb, j)
- break
- end
- end
- end
- return true
- end
- function table.print(t)
- local tx = ""
- for k, v in pairs( t ) do
- tx = tx .. v
- end
- print(tx)
- end
- function table.keys(t)
- local t, r = t, {}
- for k in pairs(t) do
- table.insert(r, k)
- end
- return r
- end
- function string.split(t, s)
- local r = {}
- for p in string.gmatch(t, "[^" .. (s or "%s") .. "]+") do
- table.insert(r, p)
- end
- return r
- end
- -- http://stackoverflow.com/questions/15706270/sort-a-table-in-lua
- function spairs(t, order)
- -- collect the keys
- local keys = {}
- for k in pairs(t) do keys[#keys+1] = k end
- -- if order function given, sort by it by passing the table and keys a, b,
- -- otherwise just sort the keys
- if order then
- table.sort(keys, function(a,b) return order(t, a, b) end)
- else
- table.sort(keys)
- end
- -- return the iterator function
- local i = 0
- return function()
- i = i + 1
- if keys[i] then
- return keys[i], t[keys[i]]
- end
- end
- end
- function firstUpper(txt)
- return txt:sub(1,1):upper() .. txt:sub(2):lower()
- end
- local magicId = 554
- -- Worst parser ever
- function eventTextAreaCallback(id,name,callback)
- -- Admin Click to win UI
- if string.split(callback, "=")[1] == "win" and contains(settings.admins, name) then
- local targ = string.split(callback, "=")[2]
- if status.started == false then
- if status.roundCtr[1] == "L" then
- status.playing[targ] = status.playing[targ] + string.len(status.claims[targ])
- ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
- " score updated by " .. string.len(status.claims[targ]) .. "</b></p>", nil)
- elseif status.roundCtr[1] == "N" then
- if math.abs(status.targ - status.claims[targ]) <= 10 and isint(math.abs(status.targ - status.claims[targ])) then
- status.playing[targ] = status.playing[targ] + 10 - math.abs(status.targ - status.claims[targ])
- ui.updateTextArea(ids.topLeft, "<p align='center'><br /><font size='15px' color='#ffffff'><b>".. targ .. "'s" ..
- " score updated by " .. 10 - math.abs(status.targ - status.claims[targ]) .. "</b></p>", nil)
- end
- elseif status.roundCtr[1] == "C" then
- -- 10 Points given to conundrum in reality this could should never be called as its auto.
- status.playing[targ] = status.playing[targ] + 10
- end
- renderPlayers()
- end
- end
- -- Numbers UI
- if string.split(callback, "=")[1] == "clicked" then
- if status.playerOperandOne[name] == nil then
- ui.updateTextArea(id, "<p align='center'><br /><font size='30px' color='#ff0000'><b>" .. string.split(callback, "=")[2] .. "</b></p>", name)
- status.playerOperandOne[name] = tonumber(string.split(callback, "=")[2])
- status.claims[name] = tonumber(string.split(callback, "=")[2])
- status.numberMarkableClaims[name] = nil
- renderRecent(name, string.split(callback, "=")[2])
- return
- end
- end
- if callback == "plus" and status.playerOperandOne[name] ~= nil then
- status.playerOp[name] = "+"
- renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
- return
- end
- if callback == "minus" and status.playerOperandOne[name] ~= nil then
- status.playerOp[name] = "-"
- renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
- return
- end
- if callback == "times" and status.playerOperandOne[name] ~= nil then
- status.playerOp[name] = "*"
- renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
- return
- end
- if callback == "div" and status.playerOperandOne[name] ~= nil then
- status.playerOp[name] = "/"
- renderRecent(name, status.playerOperandOne[name] .. " " .. status.playerOp[name])
- return
- end
- if callback == "clear" then
- reRenderNumbers(name)
- return
- end
- if string.split(callback, "=")[1] == "clicked" then
- if status.playerOperandTwo[name] == nil and status.playerOp[name] ~= nil then
- ui.updateTextArea(id, "<p align='center'><br /><font size='30px' color='#ff0000'><b>" .. string.split(callback, "=")[2] .. "</b></p>", name)
- status.playerOperandTwo[name] = tonumber(string.split(callback, "=")[2])
- -- Let's parse this and add it as the first operation
- local newNum
- if status.playerOp[name] == "+" then
- newNum = status.playerOperandOne[name] + status.playerOperandTwo[name]
- elseif status.playerOp[name] == "-" then
- newNum = status.playerOperandOne[name] - status.playerOperandTwo[name]
- elseif status.playerOp[name] == "*" then
- newNum = status.playerOperandOne[name] * status.playerOperandTwo[name]
- elseif status.playerOp[name] == "/" then
- newNum = status.playerOperandOne[name] / status.playerOperandTwo[name]
- end
- local tempId
- -- Add Small UI, magic Ids 554->660 max
- if status.playerNums[name] == nil or next(status.playerNums[name]) == nil then
- status.playerNums[name] = {magicId}
- tempId = magicId
- else
- table.insert(status.playerNums[name], status.playerNums[name][table.length(status.playerNums[name])] + 1)
- tempId = status.playerNums[name][table.length(status.playerNums[name])]
- end
- 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)
- status.claims[name] = newNum
- status.numberMarkableClaims[name] = nil
- renderRecent(name, newNum)
- -- clear
- status.playerOperandOne[name] = nil
- status.playerOp[name] = nil
- status.playerOperandTwo[name] = nil
- return
- end
- end
- end
- function isint(n)
- return n==math.floor(n)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement