Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This script relies on "Advanced Peripherals", in order to pull messages from the chat using the chatBox
- -- https://www.curseforge.com/minecraft/mc-mods/advanced-peripherals
- -- https://docs.srendi.de/1.16/peripherals/chat_box/
- --remove legacy scripts
- if (fs.exists("messageHandler")) then
- print("Deleting messageHandler script, as it's now included in this script.")
- shell.run("delete", "messageHandler")
- end
- 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()}
- --print(dimensionList)
- 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
- end
- end
- while true do
- event, username, message = os.pullEvent("chat")
- --username specific. May switch to checking tardis's list of players.
- 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