Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local port = GetPort(1) --Put a screen here.
- local port2 = GetPort(2) --Put a life sensor here.
- local port4 = GetPort(4) --Put a microphone here.
- local port5 = GetPort(5) --Connect a polysilicon on mode 2 that is also attached to the microcontroller here.
- local port6 = GetPort(6) --Put a speaker here.
- local port7 = GetPort(7)
- local port8 = GetPort(8)
- local screen = GetPartFromPort(port, "Screen")
- local instrument = GetPartFromPort(port2, "LifeSensor")
- local mic = GetPartFromPort(port4, "Microphone")
- local speaker = GetPartFromPort(port6, "Speaker")
- local polys = GetPartFromPort(port7,"Polysilicon")
- local antenna = GetPartFromPort(port8, "Antenna")
- local enemy = false
- local alarm = false
- local suspicion = 0
- local valcheck = 0
- local say = ""
- local says = ""
- local alarmsystem = true
- local iscommander = true
- local powerproduction = false
- local steamproduction = false
- local reactors = false
- local mining = false
- local newtable = {}
- local order = 0
- local assembleritems = {
- general = {
- wire = 701,
- chute = 702,
- pipe = 703,
- rubber = 704,
- cloth = 705,
- gear = 706,
- },
- triggerwire = 707,
- engine = 708,
- motor = 709,
- powercell = 710,
- container = 711,
- button = 712,
- antenna = 713,
- switch = 714,
- cooler = 715,
- heater = 716,
- transporter = 717,
- polysilicon = 718,
- glass = 719
- }
- local friendlypeople = { --Add your name here.
- "altaltgoku0987654321",
- "King_TIX1337",
- "BTheFlyingXbox",
- "Helvetica_Neue",
- "Reptilos",
- "HitScoredanceMan"
- }
- local admins = { --Add your name here too. Only admins can run commands.
- "altaltgoku0987654321",
- "Helvetica_Neue",
- "Reptilos",
- "BTheFlyingXbox",
- "King_TIX1337",
- "HitScoredanceMan"
- }
- local commands = { --These are the commands you can say into the microphone.
- "addauth",
- "removeauth",
- "restart",
- "help",
- "check",
- "print",
- "toggle",
- "assemble"
- }
- function CPrint(text)
- screen:ClearElements()
- screen:CreateElement("TextLabel", {Text = text, TextSize = 35, TextColor3 = Color3.new(51,51,51), BackgroundColor3 = Color3.new(255,255,255), Size = UDim2.new(0, 0, 0, 0), Position = UDim2.fromScale(0.5,0.5)})
- end
- function SPrint(text)
- speaker:Chat(text)
- end
- function AntennaPoly(antid, polyid)
- antenna:Configure({AntennaID = antid})
- polys:Configure({PolysiliconMode = polyid})
- TriggerPort(port7)
- end
- local Command = {}
- function Command.addauth(_, said)
- local newperson = string.gsub(said,"addauth","")
- if newperson ~= nil then
- newperson = string.gsub(newperson," ","")
- if newperson ~= nil then
- table.insert(friendlypeople,newperson)
- SPrint("Added '"..newperson.."' to the authorization table.")
- else
- SPrint("Command usage: State a username after the Command (add a space).")
- end
- end
- end
- function Command.removeauth(_, said)
- local getout = string.gsub(said,"removeauth","")
- if getout ~= nil then
- getout = string.gsub(getout, " ","")
- if getout ~= nil then
- for i,v in ipairs(friendlypeople) do
- if v == getout then
- order = i
- end
- end
- end
- else
- SPrint("Command usage: State a valid authorized username after the Command. (add a space)")
- end
- if friendlypeople[order] ~= nil then
- table.remove(friendlypeople, order)
- SPrint("Removed '"..getout.."' from the authorization table.")
- else
- SPrint("Command usage: State a valid authorized username after the Command. (add a space)")
- end
- end
- function Command.restart()
- SPrint("Restarting.")
- TriggerPort(port5)
- end
- function Command.help()
- SPrint("Commands: add/remove auth (no space), restart, help, check, print, toggle, assemble")
- end
- function Command.check(_, said)
- if string.match(said,"check values") ~= nil then
- SPrint("Checking value match.")
- CheckValues()
- elseif string.match(said, "check enemies") ~= nil then
- SPrint("Checking surroundings.")
- alarmsystem = true
- RunLoop()
- else
- SPrint("Command usage: values, enemies (add a space)")
- end
- end
- function Command.print(_, said)
- if string.match(said,"print alarms") ~= nil then
- if alarmsystem == true then
- SPrint("Alarm system is set to true.")
- else
- SPrint("Alarm system is set to false.")
- end
- elseif string.match(said,"print auth") ~= nil then
- for i,v in ipairs(friendlypeople) do
- SPrint(v)
- end
- else
- SPrint("Command usage: alarms, auth (add a space)")
- end
- end
- function Command.toggle(_, said)
- if string.match(said,"toggle alarms") then
- if alarmsystem == true then
- SPrint("Deactivating alarms.")
- alarmsystem = false
- else
- SPrint("Activating alarms.")
- alarmsystem = true
- RunLoop()
- end
- elseif string.match(said,"toggle mining") then
- if mining == true then
- mining = false
- SPrint("Deactivating mining.")
- AntennaPoly(400, 1)
- else
- mining = true
- SPrint("Activating mining.")
- AntennaPoly(400, 0)
- end
- elseif string.match(said,"toggle steamfeed") then
- if powerproduction == false then
- powerproduction = true
- SPrint("Opening the steam turbine valve.")
- AntennaPoly(600, 0)
- else
- powerproduction = false
- SPrint("Closing the steam turbine valve.")
- AntennaPoly(600, 1)
- end
- elseif string.match(said,"toggle waterfeed") then
- if steamproduction == false then
- steamproduction = true
- SPrint("Opening the reactor water valve.")
- AntennaPoly(601, 0)
- else
- steamproduction = false
- SPrint("Closing the reactor water valve.")
- AntennaPoly(601,1)
- end
- elseif string.match(said,"toggle reactors") then
- if reactors == false then
- reactors = true
- SPrint("Starting reactors. Safeguards are in place.")
- for _ = 1,10 do
- AntennaPoly(602,1)
- end
- else
- reactors = false
- SPrint("Stopping reactors.")
- for _ = 1,12 do
- AntennaPoly(602,0)
- end
- end
- else
- SPrint("Command usage: Add a space after 'toggle,' then pick from the following: alarms, mining, steam feed (no space), water feed (no space), reactors")
- end
- end
- function Command.assemble(_, said)
- local step1 = string.gsub(said,"assemble","")
- local assembled = string.gsub(step1," ","")
- local all = false
- if assembled == "all" then all = true else all = false end
- for k,v in pairs(assembleritems) do
- if k == "general" then
- for k,v in pairs(assembleritems["general"]) do
- local assembling = tostring(k)
- if assembled == assembling then
- AntennaPoly(v,2)
- SPrint("Toggled the assembly of "..assembled..".")
- end
- end
- elseif assembled == nil or assembled == "" then
- SPrint("Command usage: State a valid material on the assembly line to be assembled (add a space)")
- break
- end
- local assembling = tostring(k)
- if assembled == assembling or all == true then
- if assembling == "general" then
- for _,v in pairs(assembleritems["general"]) do
- AntennaPoly(v,2)
- SPrint("Toggled the assembly of "..assembled..".")
- end
- end
- AntennaPoly(v,2)
- SPrint("Toggled the assembly of "..assembled.."(s).")
- end
- end
- end
- function CommandRun(plr, said)
- for i,v in ipairs(commands) do
- if string.match(string.lower(said),v) then
- if Command[v] then
- if iscommander == false then
- SPrint("You're not allowed to run commands, "..plr)
- else
- Command[v](plr, said)
- end
- end
- end
- end
- end
- function AlarmLoop()
- AntennaPoly(250,2)
- while enemy == true do
- TriggerPort(port8)
- TriggerPort(port6)
- wait(60)
- TriggerPort(port8)
- TriggerPort(port6)
- end
- end
- function RunLoop()
- while alarmsystem == true do
- local apple = instrument:GetReading()
- newtable = {}
- for k,v in pairs(apple) do
- local ia = tostring(k)
- table.insert(newtable, ia)
- end
- for _,v in ipairs(newtable) do
- suspicion = 0
- local suspect = v
- --SPrint("Next suspect")
- for _,v in ipairs(friendlypeople) do
- if suspect == "empty" then
- enemy = false
- suspicion = 0
- CheckValues()
- SPrint("Empty.")
- break
- end
- --SPrint("Comparing "..suspect.." and "..v.." with a suspicion level of '"..suspicion.."'")
- if v ~= suspect then
- suspicion = suspicion + 1
- if suspicion == #friendlypeople then
- enemy = true
- CheckValues()
- --SPrint("Add.")
- break
- end
- elseif v == suspect then
- enemy = false
- suspicion = 0
- CheckValues()
- --SPrint("Negate.")
- break
- end
- end
- end
- end
- end
- function CheckValues()
- if enemy == true and alarm ~= true then
- alarm = true
- CPrint("Enemy detected.")
- SPrint("Enemy detected.")
- alarmsystem = false
- AlarmLoop()
- elseif enemy == false and alarm ~= false then
- alarm = false
- CPrint("All clear.")
- SPrint("Enemy left or all clear")
- RunLoop()
- end
- end
- SPrint("Waiting for a Command, type 'help' for commands.")
- CPrint("Waiting.")
- mic:ConnectToEvent("Chatted", function(plr,said)
- valcheck = 0
- for _,v in ipairs(admins) do
- if plr ~= v then
- valcheck = valcheck + 1
- if valcheck == #admins then
- return end
- elseif plr == v then
- valcheck = 0
- CommandRun(plr, said)
- end
- end
- end)
- RunLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement