Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tardis = peripheral.find("tardisinterface") or error("No tardis interface attached.", 0)
- box = peripheral.find("chatBox") or error("No chatBox attached.", 0)
- chatboxWhitelistUsername = settings.get("chatboxWhitelistUsername")
- whitelistedUsernameMissing = chatboxWhitelistUsername == nil
- if whitelistedUsernameMissing then
- print("No whitelisted username, anyone can control this Tardis")
- end
- function split(s, delimiter)
- result = {}
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match)
- end
- return result
- end
- function talkToMe(str, playerName)
- print(str)
- if (box == nil) then
- -- do nothing
- elseif type(str) ~= "string" then
- box.sendMessageToPlayer("NoStringError: talkToMe needs type string", playerName)
- else
- box.sendMessageToPlayer(str, playerName, "TARDIS")
- end
- end
- function handleMessage(message, username)
- split_string = split(message, " ")
- if split_string[1] == "Handles" or split_string[1] == "handles" or split_string[1] == "tardis" or split_string[1] == "TARDIS" or split_string[1] == "Tardis" then
- if split_string[2] == "go" then
- local x = tonumber(split_string[3])
- local y = tonumber(split_string[4])
- local z = tonumber(split_string[5])
- local d, dimName = tardis.getDestinationDimension()
- if split_string[6] ~= nil then
- local requestedDimension = split_string[6]
- -- Get list of dimensions
- local dimensionList = {tardis.getDimensions()}
- for key, value in ipairs(dimensionList) do
- local splitTheString = split(value, ' ')
- local id = splitTheString[1]
- local nameArray = split(splitTheString[3], ':')
- local name = nameArray[2]
- if string.find(name, requestedDimension) then
- d = (tonumber(key) - 1)
- print(key)
- end
- end
- end
- tardis.setDestinationAndDimension(x, y, z, d)
- sleep(1)
- talkToMe("You got it!", username)
- tardis.setDoors("CLOSED")
- sleep(1)
- tardis.setHandbrake(false)
- sleep(1)
- tardis.setFlight(1)
- talkToMe("Taking off!", username)
- sleep(3)
- tardis.setRefuel(true)
- local timeLeft = tardis.getTimeLeft()
- sleep(timeLeft)
- talkToMe("Landing now!", username)
- sleep(15)
- tardis.setHandbrake(true)
- talkToMe("I'm here!", username)
- end
- if split_string[2] == "hads" or split_string[2] == "HADS" then
- local curr_x, curr_y, curr_z = tardis.getLocation()
- -- Generate a random safe escape location (at least 2500 blocks away)
- local escape_x = curr_x + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1))
- local escape_y = curr_y -- Keep the Y level the same
- local escape_z = curr_z + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1))
- -- Notify the player and enable cloisters
- talkToMe("HADS activated! Escaping to a safe location.", username)
- tardis.setAlarm(true)
- -- Close doors and prepare for emergency jump
- tardis.setDoors("CLOSED")
- sleep(1)
- tardis.setHandbrake(false)
- sleep(1)
- -- Set the new escape destination
- tardis.setDestination(escape_x, escape_y, escape_z)
- tardis.setFlight(1)
- -- Wait for flight to complete
- sleep(3)
- local timeLeft = tardis.getTimeLeft()
- sleep(timeLeft)
- -- Landing process
- sleep(15)
- tardis.setHandbrake(true)
- tardis.setRefuel(true)
- tardis.setAlarm(false)
- local newLocationMessage = string.format("Phew, I got away! X: %d, Y: %d, Z: %d!", escape_x, escape_y, escape_z)
- talkToMe(newLocationMessage, username)
- end
- if split_string[2] == "cloisters" then
- if split_string[3] == "ring" then
- tardis.setAlarm(true)
- talkToMe("Cloister bells ringing!", username)
- elseif split_string[3] == "stop" then
- tardis.setAlarm(false)
- talkToMe("Cloister bells stopped!", username)
- end
- end
- if split_string[2] == "refuel" then
- tardis.setRefuel(true)
- talkToMe("Refueling!", username)
- end
- end -- Closing the main "Handles" command
- end -- Closing function handleMessage
- -- Main event loop
- while true do
- event, username, message = os.pullEvent("chat")
- -- Username check
- if whitelistedUsernameMissing or username == chatboxWhitelistUsername then
- print("User: ".. username .. " - Running: " .. message)
- handleMessage(message, username)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement