-- name: [EQUATION] Screen Locker -- description: Made by BlitherDev. Any second between 30-60 The screen lockes and an random equation will appear,To unlock the screen,somebody has to say the answer in chat to unlock it. It's that easy! This was inspired by a twitch streamer called "DougDoug" if _G.screen_lock then return end _G.screen_lock = true local MIN_SECONDS = 30 local MAX_SECONDS = 60 local FRAME_RATE = 60 local NUM_MIN = 1 local NUM_MAX = 20 local ticks_until_trigger = math.random(MIN_SECONDS, MAX_SECONDS) * FRAME_RATE local QUIZ_ACTIVE = false local current_answer = nil local current_equation = "" local announce_prefix = "[QUIZ] " local function randint(a,b) return math.random(a,b) end local function generate_equation() local a = randint(NUM_MIN, NUM_MAX) local b = randint(NUM_MIN, NUM_MAX) local ops = { "+", "-", "x" } local op = ops[randint(1,#ops)] local ans = 0 if op == "+" then ans = a + b elseif op == "-" then ans = a - b elseif op == "x" then ans = a * b end return tostring(a) .. " " .. op .. " " .. tostring(b), ans end local function announce_in_chat(msg) pcall(function() djui_chat_message_create(announce_prefix .. msg) end) end hook_event(HOOK_UPDATE, function() if QUIZ_ACTIVE then return end if ticks_until_trigger > 0 then ticks_until_trigger = ticks_until_trigger - 1 return end local eq, ans = generate_equation() current_equation = eq current_answer = ans QUIZ_ACTIVE = true announce_in_chat("Screen locked! Answer this equation to unlock the screen:") announce_in_chat(eq) end) hook_event(HOOK_ON_CHAT_MESSAGE, function(m, messageSent) if not QUIZ_ACTIVE then return true end if not messageSent then return true end local msg = messageSent:match("^%s*(.-)%s*$") local n = tonumber(msg) if n == nil then return true end if n == current_answer then local pname = "Player" pcall(function() if m and m.playerIndex and gNetworkPlayers and gNetworkPlayers[m.playerIndex] and gNetworkPlayers[m.playerIndex].name then pname = gNetworkPlayers[m.playerIndex].name elseif m and m.playerIndex then pname = "Player" .. tostring(m.playerIndex) end end) announce_in_chat(pname .. " Answered!") QUIZ_ACTIVE = false current_answer = nil current_equation = "" ticks_until_trigger = math.random(MIN_SECONDS, MAX_SECONDS) * FRAME_RATE return true end return true end) hook_event(HOOK_ON_HUD_RENDER, function() if not QUIZ_ACTIVE then return end pcall(function() djui_hud_set_resolution(RESOLUTION_DJUI) djui_hud_set_font(FONT_ALIASED) local w = djui_hud_get_screen_width() local h = djui_hud_get_screen_height() djui_hud_set_color(0, 0, 0, 255) djui_hud_render_rect(0, 0, w, h) local title = "Answer this equation to unlock the screen" local eq = current_equation or "" local titleW = djui_hud_measure_text(title) * 2.0 local eqW = djui_hud_measure_text(eq) * 2.0 local centerX = w * 0.5 local startY = h * 0.4 djui_hud_set_color(255, 255, 255, 255) djui_hud_print_text(title, centerX - (titleW * 0.5), startY, 2.0) djui_hud_set_color(255, 255, 160, 255) djui_hud_print_text(eq, centerX - (eqW * 0.5), startY + 64, 2.4) end) end)