By Arongy
-You can set the WireType to 'redstone' or 'bundled'.
-Set wich color you want to activate.
-Choose to show or not the switch status. (Exemple: Is currently On)
-You can choose wich key need to be pressed.
-TerminalMode will change how the CTRL+T act. (Disable it, make it reboot or leave it default)
-You can change any text in the programs from the TEXT area.
-Set the title as you want or leave it empty to do not show the title.
-Debug Mode for wiring & color information.
-Clean script and good explanation.
Feel free to modify and/or distribute!
CODE:
Spoiler
The code to add to the computer folder in a file called startup:
--Custom Switch V3
--Coded by Arongy
--I made this script for those who want an easy way to make a Customized Switch.
--This will lock or not the computer to become a switch for light, door or anything you want to imagine.
--You can modify any part of the code as you need to.
--CONFIGS
local Title = "CustomSwitch v3" --Enter the title you want to show when the program start.
local Status = false --Set to 'true' if you want the redpower to be ON by default.
local Side = "back" --Set the side of the computer that will send power. [front-back-top-bottom-left-right]
local Key = " " --Enter the character Key to be pressed to switch ON/OFF. [leave to " " if you want spacebar]
local WireType = "bundled" --Set to 'redstone' or 'bundled' depending of what type of wiring your using.
local RedColor = "lime" --If using 'bundled' type, this will be the color to send the power.
local ShowStatus = true --Set to 'false' if you do not want to show the 'Text_Status' message.
local TerminalMode = 0 --Set to '0' for disabling CTRL+T, '1' for reboot on CTRL+T, '2' for Terminate normally.
local DebugMode = false --Set to true for activating the debug mode.
--TEXT
local Text_Status = "Light is currently %s" --Set your own Status message. Use '%s' to show the 'Text_On'/'Text_Off' word.
local Text_Toggle = "Press Spacebar to turn %s!" --Set your own Turn On message. Use '%s' to show the 'Text_On'/'Text_Off' word.
local Text_On = "On" --The word 'On' in your desired language.
local Text_Off = "Off" --The word 'Off' in your desired language.
--PROGRAM FUNCTIONS
--Function TerminalMode
function os.pullEvent()
local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
if event == "terminate" then
if TerminalMode == 1 then
os.reboot()
elseif TerminalMode == 2 then
error( "Terminated" )
end
end
return event, p1, p2, p3, p4, p5
end
--Function SwitchStatus
function SwitchStatus(s)
if s == true then
if WireType == "redstone" then
rs.setOutput(Side, true)
elseif WireType == "bundled" then
shell.run ("redset", Side, RedColor, "true")
end
Status = true
else
if WireType == "redstone" then
rs.setOutput(Side, false)
elseif WireType == "bundled" then
shell.run ("redset", Side, RedColor, "false")
end
Status = false
end
end
--Function Display
function Display()
if Title > "" then
print(Title)
end
if DebugMode == true then
print("===DEBUG===")
print("WireType: "..WireType)
if WireType == "bundled" then
print("RedColor: "..RedColor)
end
print("TerminalMode: "..TerminalMode)
print("===========")
end
local Text_State, Text_rState = Text_Off, Text_On
if Status == true then
Text_State = Text_On
Text_rState = Text_Off
end
if Status == true then
if ShowStatus == true then
print(string.format(Text_Status, Text_State))
end
print(string.format(Text_Toggle, Text_rState))
else
if ShowStatus == true then
print(string.format(Text_Status, Text_State))
end
print(string.format(Text_Toggle, Text_rState))
end
end
--MAIN PROGRAM
SwitchStatus(Status)--This will set the default switch status on program startup.
while true do
term.clear()--Clear the terminal.
term.setCursorPos(1,1)--Set cursor position.
Display()
event, param1, param2 = os.pullEvent()
if event == "char" and param1 == Key then
if Status == true then
SwitchStatus(false)
else
SwitchStatus(true)
end
end
end
PICTURES: