Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --MoarPeripherals/OCS Random control thingy by wok86
- --Uses the ChatBox from MoarPeripherals to get commands
- --Uses OCS for the player detection bit
- local ID = "MB" --Identifier of the system. Change to whatever you want
- local playerName = "wok86" --Username of the person the system will respond to
- local cbSide = "top" --Side of the MP chatbox
- local sensorSide = "back" --Side the OCS sensor is on
- local sleepTime = 0.5 --Time between cycles, used for lag reduction
- local tzone = "+11" --GMT timezone for ltime
- local rainPCID = 79 --ID of the PC used for rain control
- local minePCID = 82 --ID of the quarry control pc
- local radius = 27 --Range of the sensor to scan for players, spherical
- local mSide = "left" --Side the Wireless Modem is on
- local hX = 895 --X coordinate of the turtle "home" command
- local hY = 34 --Y coordinate of the turtle "home" command
- local hZ = -1818 --Z coordinate of the turtle "home" command
- --Offset for the player scan area, from the sensor. Use relative values
- local offset = {
- X = 0,
- Y = 0,
- Z = 0
- }
- --Don't edit past here
- local cb = peripheral.wrap(cbSide)
- local pcID = "[ID: "..ID.."]"
- os.loadAPI("ocs/apis/sensor")
- function distance(pos)
- local xd = pos.X - offset.X
- local yd = pos.Y - offset.Y
- local zd = pos.Z - offset.Z
- return math.sqrt(xd*xd + yd*yd + zd*zd)
- end
- while true do
- local command = {os.pullEvent("chatbox_command")}
- local cArgs = {}
- local ccommand = command[4]
- local cindex = 1
- for value in string.gmatch(ccommand, "%S+") do
- cArgs[cindex] = value
- cindex = cindex + 1
- end
- if command[3] == playerName then
- print("Received command: "..command[4])
- if cArgs[1] == ID.."-players" then
- local pir = {}
- local s = sensor.wrap(sensorSide)
- local targets = s.getTargets()
- for target in pairs(targets) do
- local info = s.getTargetDetails(target)
- if info.Name == "Player" then
- if distance(info.Position) < radius then
- table.insert(pir, info.Username)
- end
- end
- end
- cb.tell(command[3], pcID.." Players in range are: "..table.concat(pir,", "))
- print("Players in range are: "..table.concat(pir,", "))
- elseif cArgs[1] == ID.."-gtime" then
- local ostime = os.time()
- local formattedTime = textutils.formatTime(ostime, false)
- cb.tell(command[3], pcID.." Current game time is: "..formattedTime)
- print("Current game time is: "..formattedTime)
- elseif cArgs[1] == ID.."-ltime" then
- if string.find(tzone, "+") then
- sTime = "in"..tzone.."+hours"
- elseif string.find(tzone, "-") then
- sTimet = string.sub(tzone, 2)
- sTime = sTimet.."+hours+ago"
- end
- local localTime = http.get("http://www.timeapi.org/utc/"..sTime.."?format=%25I:%25M%20%25p").readAll()
- cb.tell(command[3], pcID.." Current local time (GMT "..tzone..") is: "..localTime)
- print("Current local time (GMT "..tzone..") is: "..localTime)
- elseif cArgs[1] == ID.."-turtle" then
- if mSide ~= nil then
- rednet.open(mSide)
- local tArgs = {}
- local tcommand = command[4]
- local index = 1
- for value in string.gmatch(tcommand, "%S+") do
- tArgs[index] = value
- index = index + 1
- end
- if tArgs[2] ~= nil then
- if tArgs[3] == "goto" then
- if tArgs[4] ~= nil then
- if tArgs[5] ~= nil then
- if tArgs[6] ~= nil then
- local id = tonumber(tArgs[2])
- cb.tell(command[3], pcID.." Turtle ID "..tArgs[2].." instructed to go to: "..tArgs[4]..", "..tArgs[5]..", "..tArgs[6])
- print("Turtle ID "..tArgs[2].." instructed to go to: "..tArgs[4]..", "..tArgs[5]..", "..tArgs[6])
- rednet.send(id, "goto "..tArgs[4].." "..tArgs[5].." "..tArgs[6])
- else
- cb.tell(command[3], pcID.." No Z co-ordinate specified")
- print("No Z co-ordinate specified")
- end
- else
- cb.tell(command[3], pcID.." No Y co-ordinate specified")
- print("No Y co-ordinate specified")
- end
- else
- cb.tell(command[3], pcID.." No X co-ordinate specified")
- print("No X co-ordinate specified")
- end
- elseif tArgs[3] == "dance" then
- local id = tonumber(tArgs[2])
- print("Turtle ID "..id.." has been instructed to DANCE!")
- rednet.send(id, "dance")
- cb.tell(command[3], pcID.." Turtle ID "..id.." is about to DANCE!")
- rednet.close()
- elseif tArgs[3] == "go" then
- if tArgs[5] == nil then
- local id = tonumber(tArgs[2])
- cb.tell(command[3], pcID.." Turtle ID "..id.." sent command go "..tArgs[4])
- print("Turtle ID "..id.." sent command go "..tArgs[4])
- rednet.send(id, "go "..tArgs[4])
- rednet.close()
- else
- local id = tonumber(tArgs[2])
- cb.tell(command[3], pcID.." Turtle ID "..id.." sent command go "..tArgs[4].." "..tArgs[5])
- print("Turtle ID "..id.." sent command go "..tArgs[4].." "..tArgs[5])
- rednet.send(id, "go "..tArgs[4].." "..tArgs[5])
- rednet.close()
- end
- elseif tArgs[3] == "turn" then
- if tArgs[5] == nil then
- local id = tonumber(tArgs[2])
- cb.tell(command[3], pcID.." Turtle ID "..id.." sent command turn "..tArgs[4])
- print("Turtle ID "..id.." sent command turn "..tArgs[4])
- rednet.send(id, "turn "..tArgs[4])
- rednet.close()
- else
- local id = tonumber(tArgs[2])
- cb.tell(command[3], pcID.." Turtle ID "..id.." sent command turn "..tArgs[4].." "..tArgs[5])
- print("Turtle ID "..id.." sent command turn "..tArgs[4].." "..tArgs[5])
- rednet.send(id, "turn "..tArgs[4].." "..tArgs[5])
- rednet.close()
- end
- elseif tArgs[3] == "home" then
- local id = tonumber(tArgs[2])
- print("Turtle ID "..id.." has been instructed to go home ("..hX..", "..hY..", "..hZ..")")
- cb.tell(command[3], pcID.." Turtle ID "..id.." has been instructed to go home ("..hX..", "..hY..", "..hZ..")")
- rednet.send(id, "goto "..hX.." "..hY.." "..hZ)
- rednet.close()
- end
- end
- else
- cb.tell(command[3], pcID.." No modem side set.")
- print("No modem side set")
- end
- elseif cArgs[1] == ID.."-rain" then
- print("rain command")
- if mSide ~= nil then
- rednet.open(mSide)
- if rainPCID ~= nil then
- if cArgs[2] ~= nil then
- if cArgs[2] == "off" then
- cb.tell(command[3], pcID.." Sent command 'off' to RainPC")
- print("Sent command 'off' to RainPC")
- rednet.send(rainPCID, "rainoff")
- local id,msg = rednet.receive()
- if id == rainPCID then
- if msg == "done" then
- cb.tell(command[3], pcID.." Rain should now be stopping")
- print("rain stop confirmed")
- elseif msg == "norain" then
- cb.tell(command[3], pcID.." It is not currently raining - no action taken")
- print("norain confirmed")
- end
- end
- elseif cArgs[2] == "on" then
- cb.tell(command[3], pcID.." NO POLLEN, SO NO RAIN 4 U")
- print("received on cmd")
- end
- else
- cb.tell(command[3], pcID.." Must specify ON or OFF")
- end
- else
- cb.tell(command[3], pcID.." No rainPCID specified, so this function is disabled")
- end
- rednet.close()
- else
- cb.tell(command[3], pcID.." No modem side set.")
- print("no modem side set")
- end
- elseif cArgs[1] == ID.."-quarry" then
- if mSide ~= nil then
- rednet.open(mSide)
- print("quarry command")
- if minePCID ~= nil then
- if cArgs[2] ~= nil then
- if cArgs[2] == "off" then
- cb.tell(command[3], pcID.." Sent command 'off' to QuarryPC")
- print("sent command 'off' to quarrypc")
- rednet.send(minePCID, "stopmine")
- local id,msg = rednet.receive()
- if id == minePCID then
- if msg == "nowminestop" then
- cb.tell(command[3], pcID.." Quarry now stopped")
- elseif msg == "preminestop" then
- cb.tell(command[3], pcID.." Quarry already stopped")
- end
- end
- elseif cArgs[2] == "on" then
- cb.tell(command[3], pcID.." Sent command 'on' to QuarryPC")
- print("sent command 'on' to quarrypc")
- rednet.send(minePCID, "startmine")
- local id,msg = rednet.receive()
- if id == minePCID then
- if msg == "nowmine" then
- cb.tell(command[3], pcID.." Quarry now running")
- elseif msg == "premine" then
- cb.tell(command[3], pcID.." Quarry already running")
- end
- end
- elseif cArgs[2] == "status" then
- print("quarry status command")
- rednet.send(minePCID, "statmine")
- local id,msg = rednet.receive()
- if id == minePCID then
- if msg == "statmineoff" then
- cb.tell(command[3], pcID.." Quarry not running")
- elseif msg == "statmineon" then
- cb.tell(command[3], pcID.. " Quarry currently running")
- end
- end
- end
- else
- cb.tell(command[3], pcID.." Must specifiy state or status")
- end
- else
- cb.tell(command[3], pcID.." Must specify minePCID for this to work")
- end
- else
- cb.tell(command[3], pcID.." No modem side set")
- print("No modem side set")
- end
- elseif cArgs[1] == ID.."-help" then
- local tArgs = {}
- local tcommand = command[4]
- local index = 1
- for value in string.gmatch(tcommand, "%S+") do
- tArgs[index] = value
- index = index + 1
- end
- print("command list, used ##"..ID.."-help")
- if tArgs[2] ~= nil then
- if tArgs[2] == "players" then
- cb.tell(command[3], pcID.." ##"..ID.."-players - Gets a list of nearby players")
- elseif tArgs[2] == "gtime" then
- cb.tell(command[3], pcID.." ##"..ID.."-gtime - Gets the in-game time")
- elseif tArgs[2] == "ltime" then
- cb.tell(command[3], pcID.." ##"..ID.."-ltime - Gets the local time")
- elseif tArgs[2] == "rain" then
- 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")
- elseif tArgs[2] == "turtle" then
- if tArgs[3] ~= nil then
- if tArgs[3] == "home" then
- cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> home - Sends the turtle to the home co-ordinates")
- elseif tArgs[3] == "dance" then
- cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> dance - Makes the turtle DANCE~!")
- elseif tArgs[3] == "go" then
- cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> go <direction> <<num>> - Makes the turtle move in specified direction, and how many times (optional)")
- elseif tArgs[3] == "turn" then
- cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> turn <direction> <<num>> - Makes the turtle turn in the specified direction, and how many times (optional)")
- elseif tArgs[3] == "goto" then
- cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> goto <x> <y> <z> - Sends the turtle to the specified co-ordinates")
- end
- elseif tArgs[2] == "quarry" then
- if tArgs[3] ~= nil then
- if tArgs[3] == "on" then
- cb.tell(command[3], pcID.." ##"..ID.."-quarry on - turns the frame quary on")
- elseif tArgs[3] == "off" then
- cb.tell(command[3], pcID.." ##"..ID.."-quarry off - turns the frame quarry off")
- elseif tArgs[3] == "status" then
- cb.tell(command[3], pcID.." ##"..ID.."-quarry status - returns the current status of the frame quarry")
- end
- else
- cb.tell(command[3], pcID.." ##"..ID.."-quarry <off/on/status> - use ##"..ID.."-help quarry <option> for more details")
- end
- else
- cb.tell(command[3], pcID.." ##"..ID.."-turtle <id> <function> - Current functions are home,dance,go,turn,goto")
- end
- end
- else
- 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")
- end
- end
- end
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement