Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

remote

Xyzzy Mar 29th, 2015 (edited) 222 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. --MoarPeripherals/OCS Random control thingy by wok86
  2. --Uses the ChatBox from MoarPeripherals to get commands
  3. --Uses OCS for the player detection bit
  4.  
  5. local ID = "MB"                     --Identifier of the system. Change to whatever you want
  6. local playerName = "wok86"          --Username of the person the system will respond to
  7. local cbSide = "top"                --Side of the MP chatbox
  8. local sensorSide = "back"           --Side the OCS sensor is on
  9. local sleepTime = 0.5               --Time between cycles, used for lag reduction
  10. local tzone = "+11"                 --GMT timezone for ltime
  11. local rainPCID = 79                 --ID of the PC used for rain control
  12. local minePCID = 82                 --ID of the quarry control pc
  13. local sgPCID = 25
  14. local radius = 27                   --Range of the sensor to scan for players, spherical
  15. local mSide = "left"                --Side the Wireless Modem is on
  16. local hX = 895                      --X coordinate of the turtle "home" command
  17. local hY = 34                       --Y coordinate of the turtle "home" command
  18. local hZ = -1818                    --Z coordinate of the turtle "home" command
  19.  
  20. --Offset for the player scan area, from the sensor. Use relative values
  21. local offset = {
  22.   X = 0,
  23.   Y = 0,
  24.   Z = 0
  25. }
  26.  
  27.  
  28. --Don't edit past here
  29. local cb = peripheral.wrap(cbSide)
  30. local pcID = "[ID: "..ID.."]"
  31. os.loadAPI("ocs/apis/sensor")
  32.  
  33. function distance(pos)
  34.   local xd = pos.X - offset.X
  35.   local yd = pos.Y - offset.Y
  36.   local zd = pos.Z - offset.Z
  37.   return math.sqrt(xd*xd + yd*yd + zd*zd)
  38. end
  39.  
  40.  
  41. while true do
  42.   local command = {os.pullEvent("chatbox_command")}
  43.   local cArgs = {}
  44.   local ccommand = command[4]
  45.   local cindex = 1
  46.   for value in string.gmatch(ccommand, "%S+") do
  47.     cArgs[cindex] = value
  48.     cindex = cindex + 1
  49.   end
  50.   if command[3] == playerName then
  51.     print("Received command: "..command[4])
  52.     if cArgs[1] == ID.."-players" then
  53.       local pir = {}
  54.       local s = sensor.wrap(sensorSide)
  55.       local targets = s.getTargets()
  56.       for target in pairs(targets) do
  57.         local info = s.getTargetDetails(target)
  58.         if info.Name == "Player" then
  59.           if distance(info.Position) < radius then
  60.             table.insert(pir, info.Username)  
  61.           end
  62.         end
  63.       end
  64.       cb.tell(command[3], pcID.." Players in range are: "..table.concat(pir,", "))
  65.       print("Players in range are: "..table.concat(pir,", "))
  66.     elseif cArgs[1] == ID.."-gtime" then
  67.       local ostime = os.time()
  68.       local formattedTime = textutils.formatTime(ostime, false)
  69.       cb.tell(command[3], pcID.." Current game time is: "..formattedTime)
  70.       print("Current game time is: "..formattedTime)
  71.     elseif cArgs[1] == ID.."-ltime" then
  72.       if string.find(tzone, "+") then
  73.         sTime = "in"..tzone.."+hours"
  74.       elseif string.find(tzone, "-") then
  75.         sTimet = string.sub(tzone, 2)
  76.         sTime = sTimet.."+hours+ago"
  77.       end
  78.       local localTime = http.get("http://www.timeapi.org/utc/"..sTime.."?format=%25I:%25M%20%25p").readAll()
  79.       cb.tell(command[3], pcID.." Current local time (GMT "..tzone..") is: "..localTime)
  80.       print("Current local time (GMT "..tzone..") is: "..localTime)
  81.     elseif cArgs[1] == ID.."-turtle" then
  82.       if mSide ~= nil then
  83.         rednet.open(mSide)
  84.         local tArgs = {}
  85.         local tcommand = command[4]
  86.         local index = 1
  87.         for value in string.gmatch(tcommand, "%S+") do
  88.           tArgs[index] = value
  89.           index = index + 1
  90.         end
  91.         if tArgs[2] ~= nil then
  92.           if tArgs[3] == "goto" then
  93.             if tArgs[4] ~= nil then
  94.               if tArgs[5] ~= nil then
  95.                 if tArgs[6] ~= nil then
  96.                   local id = tonumber(tArgs[2])
  97.                   cb.tell(command[3], pcID.." Turtle ID "..tArgs[2].." instructed to go to: "..tArgs[4]..", "..tArgs[5]..", "..tArgs[6])
  98.                   print("Turtle ID "..tArgs[2].." instructed to go to: "..tArgs[4]..", "..tArgs[5]..", "..tArgs[6])
  99.                   rednet.send(id, "goto "..tArgs[4].." "..tArgs[5].." "..tArgs[6])
  100.                 else
  101.                   cb.tell(command[3], pcID.." No Z co-ordinate specified")
  102.                   print("No Z co-ordinate specified")
  103.                 end
  104.               else
  105.                 cb.tell(command[3], pcID.." No Y co-ordinate specified")
  106.                 print("No Y co-ordinate specified")
  107.               end
  108.             else
  109.               cb.tell(command[3], pcID.." No X co-ordinate specified")
  110.               print("No X co-ordinate specified")
  111.             end
  112.           elseif tArgs[3] == "dance" then
  113.             local id = tonumber(tArgs[2])
  114.             print("Turtle ID "..id.." has been instructed to DANCE!")
  115.             rednet.send(id, "dance")
  116.             cb.tell(command[3], pcID.." Turtle ID "..id.." is about to DANCE!")
  117.             rednet.close()
  118.           elseif tArgs[3] == "go" then
  119.             if tArgs[5] == nil then
  120.               local id = tonumber(tArgs[2])
  121.               cb.tell(command[3], pcID.." Turtle ID "..id.." sent command go "..tArgs[4])
  122.               print("Turtle ID "..id.." sent command go "..tArgs[4])
  123.               rednet.send(id, "go "..tArgs[4])
  124.               rednet.close()
  125.             else
  126.               local id = tonumber(tArgs[2])
  127.               cb.tell(command[3], pcID.." Turtle ID "..id.." sent command go "..tArgs[4].." "..tArgs[5])
  128.               print("Turtle ID "..id.." sent command go "..tArgs[4].." "..tArgs[5])
  129.               rednet.send(id, "go "..tArgs[4].." "..tArgs[5])
  130.               rednet.close()
  131.             end
  132.           elseif tArgs[3] == "turn" then
  133.             if tArgs[5] == nil then
  134.               local id = tonumber(tArgs[2])
  135.               cb.tell(command[3], pcID.." Turtle ID "..id.." sent command turn "..tArgs[4])
  136.               print("Turtle ID "..id.." sent command turn "..tArgs[4])
  137.               rednet.send(id, "turn "..tArgs[4])
  138.               rednet.close()
  139.             else
  140.               local id = tonumber(tArgs[2])
  141.               cb.tell(command[3], pcID.." Turtle ID "..id.." sent command turn "..tArgs[4].." "..tArgs[5])
  142.               print("Turtle ID "..id.." sent command turn "..tArgs[4].." "..tArgs[5])
  143.               rednet.send(id, "turn "..tArgs[4].." "..tArgs[5])
  144.               rednet.close()
  145.             end
  146.           elseif tArgs[3] == "home" then
  147.             local id = tonumber(tArgs[2])
  148.             print("Turtle ID "..id.." has been instructed to go home ("..hX..", "..hY..", "..hZ..")")
  149.             cb.tell(command[3], pcID.." Turtle ID "..id.." has been instructed to go home ("..hX..", "..hY..", "..hZ..")")
  150.             rednet.send(id, "goto "..hX.." "..hY.." "..hZ)
  151.             rednet.close()
  152.           end
  153.         end
  154.       else
  155.         cb.tell(command[3], pcID.." No modem side set.")
  156.         print("No modem side set")
  157.       end
  158.     elseif cArgs[1] == ID.."-rain" then
  159.       print("rain command")
  160.       if mSide ~= nil then
  161.         rednet.open(mSide)
  162.         if rainPCID ~= nil then
  163.           if cArgs[2] ~= nil then
  164.             if cArgs[2] == "off" then
  165.               cb.tell(command[3], pcID.." Sent command 'off' to RainPC")
  166.               print("Sent command 'off' to RainPC")
  167.               rednet.send(rainPCID, "rainoff")
  168.               local id,msg = rednet.receive()
  169.               if id == rainPCID then
  170.                 if msg == "done" then
  171.                   cb.tell(command[3], pcID.." Rain should now be stopping")
  172.                   print("rain stop confirmed")
  173.                 elseif msg == "norain" then
  174.                   cb.tell(command[3], pcID.." It is not currently raining - no action taken")
  175.                   print("norain confirmed")
  176.                 end
  177.               end
  178.             elseif cArgs[2] == "on" then
  179.               cb.tell(command[3], pcID.." NO POLLEN, SO NO RAIN 4 U")
  180.               print("received on cmd")
  181.             end
  182.           else
  183.             cb.tell(command[3], pcID.." Must specify ON or OFF")
  184.           end
  185.         else
  186.           cb.tell(command[3], pcID.." No rainPCID specified, so this function is disabled")
  187.         end
  188.         rednet.close()
  189.       else
  190.         cb.tell(command[3], pcID.." No modem side set.")
  191.         print("no modem side set")
  192.       end
  193.     elseif cArgs[1] == ID.."-quarry" then
  194.       if mSide ~= nil then
  195.         rednet.open(mSide)
  196.         print("quarry command")
  197.         if minePCID ~= nil then
  198.           if cArgs[2] ~= nil then
  199.             if cArgs[2] == "off" then
  200.               cb.tell(command[3], pcID.." Sent command 'off' to QuarryPC")
  201.               print("sent command 'off' to quarrypc")
  202.               rednet.send(minePCID, "stopmine")
  203.               local id,msg = rednet.receive()
  204.               if id == minePCID then
  205.                 if msg == "nowminestop" then
  206.                   cb.tell(command[3], pcID.." Quarry now stopped")
  207.                 elseif msg == "preminestop" then
  208.                   cb.tell(command[3], pcID.." Quarry already stopped")
  209.                 end
  210.               end
  211.             elseif cArgs[2] == "on" then
  212.               cb.tell(command[3], pcID.." Sent command 'on' to QuarryPC")
  213.               print("sent command 'on' to quarrypc")
  214.               rednet.send(minePCID, "startmine")
  215.               local id,msg = rednet.receive()
  216.               if id == minePCID then
  217.                 if msg == "nowmine" then
  218.                   cb.tell(command[3], pcID.." Quarry now running")
  219.                 elseif msg == "premine" then
  220.                   cb.tell(command[3], pcID.." Quarry already running")
  221.                 end
  222.               end
  223.             elseif cArgs[2] == "status" then
  224.               print("quarry status command")
  225.               rednet.send(minePCID, "statmine")
  226.               local id,msg = rednet.receive()
  227.               if id == minePCID then
  228.                 if msg == "statmineoff" then
  229.                   cb.tell(command[3], pcID.." Quarry not running")
  230.                 elseif msg == "statmineon" then
  231.                   cb.tell(command[3], pcID.. " Quarry currently running")
  232.                 end
  233.               end
  234.             end
  235.           else
  236.             cb.tell(command[3], pcID.." Must specifiy state or status")
  237.           end
  238.         else
  239.           cb.tell(command[3], pcID.." Must specify minePCID for this to work")
  240.         end
  241.       else
  242.         cb.tell(command[3], pcID.." No modem side set")
  243.         print("No modem side set")
  244.       end
  245.     elseif cArgs[1] == ID.."-iris" then
  246.       print("iris command")
  247.       if cArgs[2] ~= nil then
  248.         if cArgs[2] == "open" then
  249.           rednet.open(mSide)
  250.           rednet.send(sgPCID, "open")
  251.           local id,msg = rednet.receive()
  252.           if id == sgPCID then
  253.             cb.tell(command[3], pcID.." SG Iris "..msg)
  254.           end
  255.           print("iris open command")
  256.           rednet.close()
  257.         elseif cArgs[2] == "close" then
  258.           rednet.open(mSide)
  259.           rednet.send(sgPCID, "close")
  260.           local id,msg = rednet.receive()
  261.           if id == sgPCID then
  262.             cb.tell(command[3], pcID.." SG Iris "..msg)
  263.           end
  264.           print("iris close command")
  265.           rednet.close()
  266.         elseif cArgs[2] == "state" then
  267.           rednet.open(mSide)
  268.           rednet.send(sgPCID, "state")
  269.           local id,msg = rednet.receive()
  270.           if id == sgPCID then
  271.             cb.tell(command[3], pcID.." SG Iris "..msg)
  272.           end
  273.           print("iris state command")
  274.           rednet.close()
  275.         end
  276.       else
  277.         cb.tell(command[3], pcID.." Must specify option - open/close/state")
  278.       end
  279.     elseif cArgs[1] == ID.."-help" then
  280.       local tArgs = {}
  281.       local tcommand = command[4]
  282.       local index = 1
  283.       for value in string.gmatch(tcommand, "%S+") do
  284.         tArgs[index] = value
  285.         index = index + 1
  286.       end
  287.       print("command list, used ##"..ID.."-help")
  288.       if tArgs[2] ~= nil then
  289.         if tArgs[2] == "players" then
  290.           cb.tell(command[3], pcID.." ##"..ID.."-players - Gets a list of nearby players")
  291.         elseif tArgs[2] == "gtime" then
  292.           cb.tell(command[3], pcID.." ##"..ID.."-gtime - Gets the in-game time")
  293.         elseif tArgs[2] == "ltime" then
  294.           cb.tell(command[3], pcID.." ##"..ID.."-ltime - Gets the local time")
  295.         elseif tArgs[2] == "rain" then
  296.           cb.tell(command[3], pcID.." ##"..ID.."-rain <on/off> - Uses an iodine/dissipation charge on a rainmaker. Requires external setup and rainPCID to be set")
  297.         elseif tArgs[2] == "turtle" then
  298.           if tArgs[3] ~= nil then
  299.             if tArgs[3] == "home" then
  300.               cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> home - Sends the turtle to the home co-ordinates")
  301.             elseif tArgs[3] == "dance" then
  302.               cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> dance - Makes the turtle DANCE~!")
  303.             elseif tArgs[3] == "go" then
  304.               cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> go <direction> <<num>> - Makes the turtle move in specified direction, and how many times (optional)")
  305.             elseif tArgs[3] == "turn" then
  306.               cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> turn <direction> <<num>> - Makes the turtle turn in the specified direction, and how many times (optional)")
  307.             elseif tArgs[3] == "goto" then
  308.               cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> goto <x> <y> <z> - Sends the turtle to the specified co-ordinates")
  309.             end
  310.           elseif tArgs[2] == "quarry" then
  311.             if tArgs[3] ~= nil then
  312.               if tArgs[3] == "on" then
  313.                 cb.tell(command[3], pcID.." ##"..ID.."-quarry on - turns the frame quary on")
  314.               elseif tArgs[3] == "off" then
  315.                 cb.tell(command[3], pcID.." ##"..ID.."-quarry off - turns the frame quarry off")
  316.               elseif tArgs[3] == "status" then
  317.                 cb.tell(command[3], pcID.." ##"..ID.."-quarry status - returns the current status of the frame quarry")
  318.               end
  319.             else
  320.               cb.tell(command[3], pcID.." ##"..ID.."-quarry <off/on/status> - use ##"..ID.."-help quarry <option> for more details")
  321.             end
  322.           else
  323.             cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> <function> - Current functions are home,dance,go,turn,goto")
  324.           end
  325.         end
  326.       else
  327.         cb.tell(command[3], pcID.." The current usable commands are: ##"..ID.."-players, ##"..ID.."-gtime, ##"..ID.."-ltime, ##"..ID.."-turtle, ##"..ID.."-rain, ##"..ID.."-quarry. Use ##"..ID.."-help <command> for more info")
  328.       end
  329.     end
  330.   end
  331.   sleep(0.5)
  332. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top