OpenComputers · Addon guide · Intermediate
How to Build a Base Security System with OpenSecurity
This guide walks you through constructing an automated, multi-layered base security system using OpenComputers and the OpenSecurity addon. You will learn how to wire and program Keypads, Card Writers, Biometric Readers, Security Doors, and Energy Turrets to keep unauthorized players and hostile mobs out of your base.
What you need
- A working OpenComputers setup (Computer Case Tier 2 or 3, CPU, Memory, Graphics Card, Hard Disk Drive with OpenOS installed, Screen, and Keyboard)
- Power Converter and a reliable energy source (if power requirements are enabled in your modpack)
- OpenComputers Cables and an Analyzer
- OpenSecurity blocks: Keypad, Card Writer, Magstripe Reader, RFID Reader, Biometric Reader, Door Controller, Security Door (or Security Door Private), Entity Detector, and Energy Turret
- OpenSecurity items: Blank Magnetic Cards and RFID Cards
Step by step
1Assemble the Central Security Server
Place your Computer Case, Screen, and Keyboard in a secure inner room of your base where intruders cannot easily break them. Connect a Power Converter to your base's energy grid and attach it to the computer so the system never shuts down. Boot the computer and ensure OpenOS is installed on the Hard Disk Drive so you can write persistent Lua scripts.
Tip: Use a Server Rack in a chunk-loaded area if you plan to expand your security network across a massive base.
2Wire the Security Peripherals
Place your Security Door at the entrance and position a Door Controller directly adjacent to the bottom block of the door. Mount your chosen input devices—such as a Keypad, Magstripe Reader, or Biometric Reader—on the wall outside the entrance. Run OpenComputers Cables from your central Computer Case to the Door Controller and all input devices to link them onto the same component network.
Tip: OpenSecurity blocks have built-in component interfaces, so you can connect Cables directly to them without needing an Adapter block.
3Identify Component Addresses
Hold your OpenComputers Analyzer and sneak-right-click each security block to view its unique component address in the chat. Alternatively, run the 'components' command in the OpenOS shell to list every connected device by its name, such as 'os_keypad', 'os_doorcontroller', or 'os_biometric'. Write down the first three or four characters of each address so you can reference specific doors and readers in your Lua code.
Tip: In the game chat, you can usually click the address printed by the Analyzer to copy it directly to your clipboard.
4Encode Access Cards
Connect a Card Writer to your computer network and insert a blank Magnetic Card or RFID Card into its slot. Open the Lua interactive prompt by typing 'lua' in the terminal, and load the writer using 'writer = component.os_cardwriter'. Run 'writer.write("SecretPass123", "Base Access Card", true)' to burn your secret password onto the card, label it, and lock it against further tampering.
Tip: The third argument locks the card permanently, preventing unauthorized players from overwriting or duplicating the data if they steal it.
5Program the Door and Keypad Logic
Exit the Lua prompt and create a new script by typing 'edit security.lua'. Require the 'component' and 'event' libraries at the top of your file, and assign variables to your 'os_doorcontroller' and 'os_keypad' components. Write a 'while true do' loop that calls 'event.pull("keypad")', checks if the submitted PIN string matches your chosen passcode, and triggers the Door Controller to open for a few seconds before closing.
Tip: If your Door Controller requires a password (such as with a Security Door Private), configure it first and pass that password string into your open and close function calls.
6Add Biometric and Card Authentication
Expand your script by switching to a generic 'event.pull()' inside your main loop so it can listen for multiple security events simultaneously. Check if the first returned value is 'magData' (triggered when a player swipes a Magstripe Card) or 'biometric' (triggered when a player right-clicks a Biometric Reader). Compare the returned card data string against your secret password, or compare the returned player UUID against a whitelist table of trusted friends, then call the door toggle function if verified.
Tip: Unlike Magstripe Readers which wait for a player interaction event, RFID Readers must be actively polled in your code using their scan function to detect cards in nearby players' inventories.
7Deploy Automated Energy Turrets
Place an Energy Turret and an Entity Detector near your perimeter, connecting both to your computer's cable network and hooking the turret up to a heavy power supply. In your control script, call the Entity Detector's scan function to get a table of nearby entities and their relative X, Y, and Z coordinates. Calculate the horizontal yaw and vertical pitch angles using the 'math.atan2' function, feed those angles into the turret's 'moveTo' method, and execute the 'fire' command once the turret is aligned and ready.
Tip: Check JEI for available Turret Upgrades that can be installed inside the Energy Turret's GUI to boost its rotation speed, damage, or cooling rate.
How it works
OpenComputers relies on an event-driven architecture. Instead of wasting CPU cycles constantly checking if a button is pressed, blocks like the Keypad, Magstripe Reader, and Biometric Reader push a signal into the computer's event queue only when a player interacts with them. The 'event.pull()' function pauses your Lua script until one of these signals arrives, returning the event name, the specific component address that sent it, the player's name, and the payload (such as the typed PIN, card data string, or player UUID).
Active scanning blocks, such as the RFID Reader and Entity Detector, operate through polling rather than passive events. They do not emit signals on their own; instead, your Lua script must actively invoke their scan methods on a timer. Doing so draws a burst of energy from your power network and returns a Lua table containing all detected RFID payloads or entity coordinates within the block's radius.
Security Doors cannot be broken by normal survival tools or opened by standard redstone signals. They only change state when their adjacent Door Controller receives a valid API call over the OpenComputers cable network. Similarly, Energy Turrets act as dumb mechanical executors: they rely entirely on the central computer to perform trigonometric math using coordinates from an Entity Detector, translating relative X, Y, and Z offsets into rotation angles before firing.
Common mistakes
- Placing the Door Controller next to the top half of the Security Door instead of the bottom half, which prevents the controller from detecting and operating the door.
- Routing OpenComputers Cables along the outside wall of the base where intruders can easily break the blocks or attach their own computer to hijack your Door Controller.
- Using component.os_keypad directly when you have multiple keypads on the same network; always use component.proxy(address) with each block's unique address so you know which door to open.
- Writing an infinite 'while true do' loop for RFID or Entity Detector scanning without including an 'os.sleep()' or timeout delay, which will either drain your base's energy reserves instantly or cause the computer to crash with a 'too long without yielding' error.
FAQ
How do I stop my security script from terminating if the chunk unloads?
OpenComputers automatically persists the exact execution state of your computers across chunk unloads and server restarts, but you should also place a call to your script inside the '/home/.shrc' file so it boots automatically if the computer is ever manually restarted.
Why is my Energy Turret not rotating or firing even though the code runs without errors?
Ensure you have called the turret's power-on method in your script, verify that the turret has enough energy from an external power mod, and check that you have waited for the turret to finish aligning to its target angles before calling the fire method.
What is the difference between a Magstripe Card and an RFID Card?
A Magstripe Card requires the player to physically hold the card and right-click a Magstripe Reader to trigger an event, whereas an RFID Card can be read wirelessly through walls while sitting inside a player's inventory whenever the computer polls an RFID Reader.
How do I find the exact method names for a specific OpenSecurity block?
Connect the block to your computer, open the interactive Lua prompt by typing 'lua', and run 'for k,v in pairs(component.BLOCKNAME) do print(k,v) end' (replacing BLOCKNAME with the component type like os_turret or os_doorcontroller) to print all built-in functions and their documentation.
By combining OpenComputers' event-driven Lua scripting with OpenSecurity's tamper-proof doors, readers, and turrets, you can build an automated defense network tailored to your base.