The Konami Code Detector
(well, it’s not just the Konami code, but)
I wanted to add an easter egg to my game, and I thought, “What could be better than the Konami Code?” But somehow, I couldn’t find a single open-sourced script for it in sight! That’s why I’d like to release this simple detector to you guys.
(the default keyboard binding has changed a little)
It supports Touch, Keyboard, and Gamepads! You can also mix and match the input types if you really wanted to. The combination you have to enter is fully customizable, too! You’re not just limited to the Konami code (although I’d recommend you stick to a sequence that’s the same size across all input types, lest you want to break the script)
Example Place and Code
Wanna try it out for yourself? In this example place, the cube will turn green when you enter it successfully.
konami v2.rbxl (22.7 KB)
Model:
Source
--[[
KonamiCode
Written by NobleReign
Date: 09/07/2020 12:16:47 PM Pacific Time
Description: Detects the Konami Code. Compatible with keyboard, touch, and gamepad.
]]
local uis = game:GetService("UserInputService")
local gui = game:GetService("GuiService")
local keyIndex = 1
local keys = {
[Enum.UserInputType.Keyboard] = {
Enum.KeyCode.Up,
Enum.KeyCode.Up,
Enum.KeyCode.Down,
Enum.KeyCode.Down,
Enum.KeyCode.Left,
Enum.KeyCode.Right,
Enum.KeyCode.Left,
Enum.KeyCode.Right,
Enum.KeyCode.B,
Enum.KeyCode.A,
Enum.KeyCode.Return,
},
[Enum.UserInputType.Gamepad1] = {
Enum.KeyCode.DPadUp,
Enum.KeyCode.DPadUp,
Enum.KeyCode.DPadDown,
Enum.KeyCode.DPadDown,
Enum.KeyCode.DPadLeft,
Enum.KeyCode.DPadRight,
Enum.KeyCode.DPadLeft,
Enum.KeyCode.DPadRight,
Enum.KeyCode.ButtonB,
Enum.KeyCode.ButtonA,
Enum.KeyCode.ButtonStart,
},
[Enum.UserInputType.Touch] = {
Enum.SwipeDirection.Up,
Enum.SwipeDirection.Up,
Enum.SwipeDirection.Down,
Enum.SwipeDirection.Down,
Enum.SwipeDirection.Left,
Enum.SwipeDirection.Right,
Enum.SwipeDirection.Left,
Enum.SwipeDirection.Right,
"Tap",
"Tap",
"LongTap"
}
}
local function detectKonami(input)
local keyPressed = input.KeyCode
if keys[input.UserInputType][keyIndex] == keyPressed then
keyIndex += 1
if not keys[input.UserInputType][keyIndex] then
--Konami win!
keyIndex = 1
script.Entered:Fire()
end
else
keyIndex = 1
--Konami fail.
end
end
gui.MenuOpened:Connect(function()
detectKonami({UserInputType = Enum.UserInputType.Gamepad1, KeyCode = Enum.KeyCode.ButtonStart})
end)
uis.TouchSwipe:Connect(function(swipeDirection, numberOfTouches, gameProcessedEvent)
detectKonami({UserInputType = Enum.UserInputType.Touch, KeyCode = swipeDirection})
end)
uis.TouchTap:Connect(function(touchPositions, gameProcessedEvent)
detectKonami({UserInputType = Enum.UserInputType.Touch, KeyCode = "Tap"})
end)
uis.TouchLongPress:Connect(function(touchPositions, state, gameProcessedEvent)
if state == Enum.UserInputState.Begin then
detectKonami({UserInputType = Enum.UserInputType.Touch, KeyCode = "LongTap"})
end
end)
uis.InputEnded:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
detectKonami(input)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
detectKonami({UserInputType = Enum.UserInputType.Keyboard, KeyCode = "LeftClick"})
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
detectKonami({UserInputType = Enum.UserInputType.Keyboard, KeyCode = "RightClick"})
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
detectKonami(input)
end
end)
Do I need to credit you?
It’d be appreciated, but I don’t really care that much. Go wild!
Bugs
I’m not sure if I’ll actively maintain this (I can barely even ‘maintain’ my own games as is), but if you find any, it wouldn’t hurt to let me know! (also if you used this in your game I would love to know that too)
Thanks for stopping by, and happy button pressing!