Advertisement
Dogeking

wos alarm system

Jun 15th, 2020 (edited)
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.91 KB | None | 0 0
  1. local port = GetPort(1) --Put a screen here.
  2. local port2 = GetPort(2) --Put a life sensor here.
  3. local port4 = GetPort(4) --Put a microphone here.
  4. local port5 = GetPort(5) --Connect a polysilicon on mode 2 that is also attached to the microcontroller here.
  5. local port6 = GetPort(6) --Put a speaker here.
  6. local port7 = GetPort(7)
  7. local port8 = GetPort(8)
  8. local screen = GetPartFromPort(port, "Screen")
  9. local instrument = GetPartFromPort(port2, "LifeSensor")
  10. local mic = GetPartFromPort(port4, "Microphone")
  11. local speaker = GetPartFromPort(port6, "Speaker")
  12. local polys = GetPartFromPort(port7,"Polysilicon")
  13. local antenna = GetPartFromPort(port8, "Antenna")
  14. local enemy = false
  15. local alarm = false
  16. local suspicion = 0
  17. local valcheck = 0
  18. local say = ""
  19. local says = ""
  20. local alarmsystem = true
  21. local iscommander = true
  22. local powerproduction = false
  23. local steamproduction = false
  24. local reactors = false
  25. local mining = false
  26. local newtable = {}
  27. local order = 0
  28.  
  29. local assembleritems = {
  30.     general = {
  31.     wire = 701,
  32.     chute = 702,
  33.     pipe = 703,
  34.     rubber = 704,
  35.     cloth = 705,
  36.     gear = 706,
  37.     }, 
  38.     triggerwire = 707,
  39.     engine = 708,
  40.     motor = 709,
  41.     powercell = 710,
  42.     container = 711,
  43.     button = 712,
  44.     antenna = 713,
  45.     switch = 714,
  46.     cooler = 715,
  47.     heater = 716,
  48.     transporter = 717,
  49.     polysilicon = 718,
  50.     glass = 719
  51. }
  52.     local friendlypeople = { --Add your name here.
  53.         "altaltgoku0987654321",
  54.         "King_TIX1337",
  55.         "BTheFlyingXbox",
  56.         "Helvetica_Neue",
  57.         "Reptilos",
  58.     "HitScoredanceMan"
  59.     }
  60.     local admins = { --Add your name here too. Only admins can run commands.
  61.         "altaltgoku0987654321",
  62.         "Helvetica_Neue",
  63.         "Reptilos",
  64.         "BTheFlyingXbox",
  65.         "King_TIX1337",
  66.     "HitScoredanceMan"
  67.     }
  68.     local commands = { --These are the commands you can say into the microphone.
  69.     "addauth",
  70.     "removeauth",
  71.     "restart",
  72.     "help",
  73.     "check",
  74.     "print",
  75.     "toggle",
  76.     "assemble"
  77.     }
  78. function CPrint(text)
  79. screen:ClearElements()
  80. 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)})
  81. end
  82. function SPrint(text)
  83.     speaker:Chat(text)
  84. end
  85. function AntennaPoly(antid, polyid)
  86.     antenna:Configure({AntennaID = antid})
  87.     polys:Configure({PolysiliconMode = polyid})
  88.     TriggerPort(port7)
  89. end
  90. local Command = {}
  91. function Command.addauth(_, said)
  92.     local newperson = string.gsub(said,"addauth","")
  93.     if newperson ~= nil then
  94.         newperson = string.gsub(newperson," ","")
  95.         if newperson ~= nil then
  96.             table.insert(friendlypeople,newperson)
  97.             SPrint("Added '"..newperson.."' to the authorization table.")
  98.     else
  99.         SPrint("Command usage: State a username after the Command (add a space).")
  100.         end
  101.     end
  102. end
  103. function Command.removeauth(_, said)
  104.     local getout = string.gsub(said,"removeauth","")
  105.         if getout ~= nil then
  106.         getout = string.gsub(getout, " ","")
  107.         if getout ~= nil then
  108.             for i,v in ipairs(friendlypeople) do
  109.                 if v == getout then
  110.                     order = i
  111.                 end
  112.             end
  113.         end
  114.         else
  115.             SPrint("Command usage: State a valid authorized username after the Command. (add a space)")
  116.             end
  117.                 if friendlypeople[order] ~= nil then
  118.             table.remove(friendlypeople, order)
  119.                     SPrint("Removed '"..getout.."' from the authorization table.")
  120.     else
  121.         SPrint("Command usage: State a valid authorized username after the Command. (add a space)")
  122.     end
  123. end
  124. function Command.restart()
  125.      SPrint("Restarting.")
  126.      TriggerPort(port5)
  127. end
  128. function Command.help()
  129.     SPrint("Commands: add/remove auth (no space), restart, help, check, print, toggle, assemble")
  130. end
  131. function Command.check(_, said)
  132.     if string.match(said,"check values") ~= nil then
  133.         SPrint("Checking value match.")
  134.         CheckValues()
  135.      elseif string.match(said, "check enemies") ~= nil then
  136.         SPrint("Checking surroundings.")
  137.         alarmsystem = true
  138.         RunLoop()
  139.         else
  140.         SPrint("Command usage: values, enemies (add a space)")
  141.     end
  142. end
  143. function Command.print(_, said)
  144.     if string.match(said,"print alarms") ~= nil then
  145.         if alarmsystem == true then
  146.                     SPrint("Alarm system is set to true.")
  147.         else
  148.             SPrint("Alarm system is set to false.")
  149.         end
  150.     elseif string.match(said,"print auth") ~= nil then
  151.          for i,v in ipairs(friendlypeople) do
  152.        SPrint(v)
  153.     end
  154.     else
  155.         SPrint("Command usage: alarms, auth (add a space)")
  156.     end
  157. end
  158. function Command.toggle(_, said)
  159.     if string.match(said,"toggle alarms") then
  160.      if alarmsystem == true then
  161.         SPrint("Deactivating alarms.")
  162.         alarmsystem = false
  163.      else
  164.         SPrint("Activating alarms.")
  165.         alarmsystem = true
  166.         RunLoop()
  167.     end
  168.     elseif string.match(said,"toggle mining") then
  169.         if mining == true then
  170.             mining = false
  171.             SPrint("Deactivating mining.")
  172.             AntennaPoly(400, 1)
  173.         else
  174.             mining = true
  175.             SPrint("Activating mining.")
  176.             AntennaPoly(400, 0)        
  177.         end
  178.     elseif string.match(said,"toggle steamfeed") then
  179.         if powerproduction == false then
  180.             powerproduction = true
  181.             SPrint("Opening the steam turbine valve.")
  182.             AntennaPoly(600, 0)
  183.         else
  184.             powerproduction = false
  185.             SPrint("Closing the steam turbine valve.")
  186.             AntennaPoly(600, 1)
  187.         end
  188.     elseif string.match(said,"toggle waterfeed") then
  189.         if steamproduction == false then
  190.             steamproduction = true
  191.             SPrint("Opening the reactor water valve.")
  192.             AntennaPoly(601, 0)
  193.         else
  194.             steamproduction = false
  195.             SPrint("Closing the reactor water valve.")
  196.             AntennaPoly(601,1)
  197.         end
  198.     elseif string.match(said,"toggle reactors") then
  199.         if reactors == false then
  200.             reactors = true
  201.             SPrint("Starting reactors. Safeguards are in place.")
  202.             for _ = 1,10 do
  203.                 AntennaPoly(602,1)
  204.             end
  205.         else
  206.             reactors = false
  207.             SPrint("Stopping reactors.")
  208.             for _ = 1,12 do
  209.                 AntennaPoly(602,0)
  210.             end
  211.         end
  212.     else
  213.         SPrint("Command usage: Add a space after 'toggle,' then pick from the following: alarms, mining, steam feed (no space), water feed (no space), reactors")
  214.     end
  215.     end
  216. function Command.assemble(_, said)
  217.         local step1 = string.gsub(said,"assemble","")
  218.         local assembled = string.gsub(step1," ","")
  219.         local all = false
  220.         if assembled == "all" then all = true else all = false end
  221.         for k,v in pairs(assembleritems) do
  222.             if k == "general" then
  223.                 for k,v in pairs(assembleritems["general"]) do
  224.                     local assembling = tostring(k)
  225.             if assembled == assembling then
  226.                         AntennaPoly(v,2)
  227.                         SPrint("Toggled the assembly of "..assembled..".")
  228.                 end
  229.                 end
  230.         elseif assembled == nil or assembled == "" then
  231.             SPrint("Command usage: State a valid material on the assembly line to be assembled (add a space)")
  232.             break
  233.         end        
  234.             local assembling = tostring(k)
  235.             if assembled == assembling or all == true then
  236.                 if assembling == "general" then
  237.                     for _,v in pairs(assembleritems["general"]) do
  238.                         AntennaPoly(v,2)
  239.                         SPrint("Toggled the assembly of "..assembled..".")
  240.                     end
  241.                 end
  242.                 AntennaPoly(v,2)
  243.                 SPrint("Toggled the assembly of "..assembled.."(s).")
  244.         end
  245.     end
  246. end
  247. function CommandRun(plr, said)
  248.     for i,v in ipairs(commands) do
  249.         if string.match(string.lower(said),v) then
  250.                         if Command[v] then
  251.                 if iscommander == false then
  252.                     SPrint("You're not allowed to run commands, "..plr)
  253.                 else
  254.                 Command[v](plr, said)
  255.                             end
  256.             end
  257.         end
  258.     end
  259. end
  260. function AlarmLoop()
  261.     AntennaPoly(250,2)
  262.     while enemy == true do
  263.         TriggerPort(port8)
  264.         TriggerPort(port6)
  265.         wait(60)
  266.         TriggerPort(port8)
  267.         TriggerPort(port6)
  268.     end
  269. end
  270. function RunLoop()
  271. while alarmsystem == true do
  272.         local apple = instrument:GetReading()
  273.         newtable = {}
  274.     for k,v in pairs(apple) do
  275.         local ia = tostring(k)
  276.         table.insert(newtable, ia)
  277.     end
  278.         for _,v in ipairs(newtable) do
  279.             suspicion = 0
  280.             local suspect = v
  281.             --SPrint("Next suspect")
  282.             for _,v in ipairs(friendlypeople) do
  283.                 if suspect == "empty" then
  284.                     enemy = false
  285.                     suspicion = 0
  286.                     CheckValues()
  287.                     SPrint("Empty.")
  288.                     break
  289.                 end
  290.                 --SPrint("Comparing "..suspect.." and "..v.." with a suspicion level of '"..suspicion.."'")
  291.                 if v ~= suspect then
  292.                     suspicion = suspicion + 1
  293.                     if suspicion == #friendlypeople then
  294.                         enemy = true
  295.                         CheckValues()
  296.                         --SPrint("Add.")
  297.                         break
  298.                     end
  299.                 elseif v == suspect then
  300.                     enemy = false
  301.                     suspicion = 0
  302.                     CheckValues()
  303.                     --SPrint("Negate.")
  304.                     break
  305.                 end
  306.             end
  307.         end
  308.     end
  309. end
  310. function CheckValues()
  311. if enemy == true and alarm ~= true then
  312.     alarm = true
  313.             CPrint("Enemy detected.")
  314.         SPrint("Enemy detected.")
  315.             alarmsystem = false
  316.         AlarmLoop()
  317. elseif enemy == false and alarm ~= false then
  318.     alarm = false
  319.             CPrint("All clear.")
  320.         SPrint("Enemy left or all clear")
  321.     RunLoop()
  322.     end
  323. end
  324. SPrint("Waiting for a Command, type 'help' for commands.")
  325. CPrint("Waiting.")
  326. mic:ConnectToEvent("Chatted", function(plr,said)
  327.     valcheck = 0
  328.     for _,v in ipairs(admins) do
  329.             if plr ~= v then
  330.                     valcheck = valcheck + 1
  331.            
  332.         if valcheck == #admins then
  333.             return end
  334.             elseif plr == v then
  335.                 valcheck = 0
  336.                 CommandRun(plr, said)
  337.                 end
  338.             end
  339.         end)
  340. RunLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement