-- 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 NUM_MIN = 1 local NUM_MAX = 20 local QUIZ_DURATION_SECONDS = 15 local trigger_seconds = math.random(MIN_SECONDS, MAX_SECONDS) local trigger_accum = 0 local QUIZ_ACTIVE = false local QUIZ_TIMER = 0 local quiz_accum = 0 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 local function reset_quiz() QUIZ_ACTIVE = false current_answer = nil current_equation = "" QUIZ_TIMER = 0 quiz_accum = 0 trigger_seconds = math.random(MIN_SECONDS, MAX_SECONDS) trigger_accum = 0 end hook_event(HOOK_UPDATE, function() if QUIZ_ACTIVE then quiz_accum = quiz_accum + 1 if quiz_accum >= 30 then quiz_accum = 0 QUIZ_TIMER = QUIZ_TIMER - 1 if QUIZ_TIMER > 0 then play_sound(SOUND_GENERAL2_SWITCH_TICK_FAST, gGlobalSoundSource) end if QUIZ_TIMER <= 0 then local m = gMarioStates[0] if m then m.health = 0xFF end reset_quiz() end end return end trigger_accum = trigger_accum + 1 if trigger_accum >= 30 then trigger_accum = 0 trigger_seconds = trigger_seconds - 1 end if trigger_seconds > 0 then return end local eq, ans = generate_equation() current_equation = eq current_answer = ans QUIZ_ACTIVE = true QUIZ_TIMER = QUIZ_DURATION_SECONDS quiz_accum = 0 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 = tostring(messageSent) msg = msg:match("^%s*(.-)%s*$") local n = tonumber(msg) if n == nil then return true end if n == current_answer then reset_quiz() 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 timer_text = "Time Left: " .. QUIZ_TIMER local timerW = djui_hud_measure_text(timer_text) * 2.0 djui_hud_set_color(255, 80, 80, 255) djui_hud_print_text(timer_text, w * 0.5 - (timerW * 0.5), 40, 2.0) 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)