SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --This script relies on "Advanced Peripherals", in order to pull messages from the chat using the chatBox |
| 1 | + | |
| 2 | - | -- https://www.curseforge.com/minecraft/mc-mods/advanced-peripherals |
| 2 | + | |
| 3 | - | -- https://docs.srendi.de/1.16/peripherals/chat_box/ |
| 3 | + | |
| 4 | chatboxWhitelistUsername = settings.get("chatboxWhitelistUsername")
| |
| 5 | - | --remove legacy scripts |
| 5 | + | |
| 6 | - | if (fs.exists("messageHandler")) then
|
| 6 | + | |
| 7 | - | print("Deleting messageHandler script, as it's now included in this script.")
|
| 7 | + | |
| 8 | - | shell.run("delete", "messageHandler")
|
| 8 | + | |
| 9 | end | |
| 10 | ||
| 11 | function split(s, delimiter) | |
| 12 | result = {}
| |
| 13 | for match in (s..delimiter):gmatch("(.-)"..delimiter) do
| |
| 14 | table.insert(result, match) | |
| 15 | end | |
| 16 | return result | |
| 17 | end | |
| 18 | ||
| 19 | function talkToMe(str, playerName) | |
| 20 | print(str) | |
| 21 | if (box == nil) then | |
| 22 | -- do nothing | |
| 23 | - | result = {};
|
| 23 | + | elseif type(str) ~= "string" then |
| 24 | box.sendMessageToPlayer("NoStringError: talkToMe needs type string", playerName)
| |
| 25 | - | table.insert(result, match); |
| 25 | + | else |
| 26 | box.sendMessageToPlayer(str, playerName, "TARDIS") | |
| 27 | - | return result; |
| 27 | + | |
| 28 | end | |
| 29 | ||
| 30 | - | function talkToMe (str, playerName) |
| 30 | + | function handleMessage(message, username) |
| 31 | - | print(str) |
| 31 | + | split_string = split(message, " ") |
| 32 | - | if (box == nil) then |
| 32 | + | |
| 33 | - | -- do nothing |
| 33 | + | 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 |
| 34 | - | elseif type(str) ~= "string" then |
| 34 | + | if split_string[2] == "go" then |
| 35 | - | box.sendMessageToPlayer("NoStringError: talkToMe needs type string", playerName)
|
| 35 | + | local x = tonumber(split_string[3]) |
| 36 | - | else |
| 36 | + | local y = tonumber(split_string[4]) |
| 37 | - | box.sendMessageToPlayer(str, playerName, "TARDIS") |
| 37 | + | local z = tonumber(split_string[5]) |
| 38 | - | end |
| 38 | + | local d, dimName = tardis.getDestinationDimension() |
| 39 | ||
| 40 | if split_string[6] ~= nil then | |
| 41 | - | function handleMessage (message, username) |
| 41 | + | local requestedDimension = split_string[6] |
| 42 | - | split_string = split(message, " ") |
| 42 | + | -- Get list of dimensions |
| 43 | local dimensionList = {tardis.getDimensions()}
| |
| 44 | - | 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 |
| 44 | + | |
| 45 | - | if split_string[2] == "go" then |
| 45 | + | for key, value in ipairs(dimensionList) do |
| 46 | - | local x = tonumber(split_string[3]) |
| 46 | + | local splitTheString = split(value, ' ') |
| 47 | - | local y = tonumber(split_string[4]) |
| 47 | + | local id = splitTheString[1] |
| 48 | - | local z = tonumber(split_string[5]) |
| 48 | + | |
| 49 | - | local d, dimName = tardis.getDestinationDimension() |
| 49 | + | local nameArray = split(splitTheString[3], ':') |
| 50 | local name = nameArray[2] | |
| 51 | - | if split_string[6] ~= nil then |
| 51 | + | |
| 52 | - | local requestedDimension = split_string[6] |
| 52 | + | if string.find(name, requestedDimension) then |
| 53 | - | --get list of dimensions |
| 53 | + | d = (tonumber(key) - 1) |
| 54 | - | local dimensionList = {tardis.getDimensions()}
|
| 54 | + | print(key) |
| 55 | - | --print(dimensionList) |
| 55 | + | end |
| 56 | end | |
| 57 | - | for key,value in ipairs(dimensionList) do |
| 57 | + | end |
| 58 | - | local splitTheString = split(value,' ') |
| 58 | + | |
| 59 | - | local id = splitTheString[1] |
| 59 | + | tardis.setDestinationAndDimension(x, y, z, d) |
| 60 | ||
| 61 | - | local nameArray = split(splitTheString[3],':') |
| 61 | + | sleep(1) |
| 62 | - | local name = nameArray[2] |
| 62 | + | talkToMe("You got it!", username)
|
| 63 | tardis.setDoors("CLOSED")
| |
| 64 | - | if string.find(name, requestedDimension) then |
| 64 | + | sleep(1) |
| 65 | - | d = (tonumber(key) - 1) -- ?? |
| 65 | + | tardis.setHandbrake(false) |
| 66 | - | print(key) |
| 66 | + | sleep(1) |
| 67 | - | end |
| 67 | + | tardis.setFlight(1) |
| 68 | - | end |
| 68 | + | talkToMe("Taking off!", username)
|
| 69 | - | end |
| 69 | + | sleep(3) |
| 70 | tardis.setRefuel(true) | |
| 71 | - | tardis.setDestinationAndDimension(x, y, z, d) |
| 71 | + | local timeLeft = tardis.getTimeLeft() |
| 72 | sleep(timeLeft) | |
| 73 | - | sleep(1) |
| 73 | + | talkToMe("Landing now!", username)
|
| 74 | - | talkToMe("You got it!", username)
|
| 74 | + | sleep(15) |
| 75 | - | tardis.setDoors("CLOSED")
|
| 75 | + | tardis.setHandbrake(true) |
| 76 | - | sleep(1) |
| 76 | + | talkToMe("I'm here!", username)
|
| 77 | - | tardis.setHandbrake(false) |
| 77 | + | end |
| 78 | - | sleep(1) |
| 78 | + | |
| 79 | - | tardis.setFlight(1) |
| 79 | + | if split_string[2] == "hads" or split_string[2] == "HADS" then |
| 80 | - | talkToMe("Taking off!", username)
|
| 80 | + | local curr_x, curr_y, curr_z = tardis.getLocation() |
| 81 | - | sleep(3) |
| 81 | + | |
| 82 | - | tardis.setRefuel(true) |
| 82 | + | -- Generate a random safe escape location (at least 2500 blocks away) |
| 83 | - | local timeLeft = tardis.getTimeLeft() |
| 83 | + | local escape_x = curr_x + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1)) |
| 84 | - | sleep(timeLeft) |
| 84 | + | local escape_y = curr_y -- Keep the Y level the same |
| 85 | - | talkToMe("Landing now!", username)
|
| 85 | + | local escape_z = curr_z + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1)) |
| 86 | - | sleep(15) |
| 86 | + | |
| 87 | - | tardis.setHandbrake(true) |
| 87 | + | -- Notify the player and enable cloisters |
| 88 | - | talkToMe("I'm here!", username)
|
| 88 | + | talkToMe("HADS activated! Escaping to a safe location.", username)
|
| 89 | - | end |
| 89 | + | tardis.setAlarm(true) |
| 90 | - | end |
| 90 | + | |
| 91 | -- Close doors and prepare for emergency jump | |
| 92 | tardis.setDoors("CLOSED")
| |
| 93 | sleep(1) | |
| 94 | - | event, username, message = os.pullEvent("chat")
|
| 94 | + | tardis.setHandbrake(false) |
| 95 | sleep(1) | |
| 96 | - | --username specific. May switch to checking tardis's list of players. |
| 96 | + | |
| 97 | - | if whitelistedUsernameMissing or username == chatboxWhitelistUsername then |
| 97 | + | -- Set the new escape destination |
| 98 | - | print("User: ".. username .. " - Running: " .. message)
|
| 98 | + | tardis.setDestination(escape_x, escape_y, escape_z) |
| 99 | - | handleMessage(message, username) |
| 99 | + | tardis.setFlight(1) |
| 100 | - | end |
| 100 | + | |
| 101 | -- Wait for flight to complete | |
| 102 | sleep(3) | |
| 103 | local timeLeft = tardis.getTimeLeft() | |
| 104 | sleep(timeLeft) | |
| 105 | ||
| 106 | -- Landing process | |
| 107 | sleep(15) | |
| 108 | tardis.setHandbrake(true) | |
| 109 | tardis.setRefuel(true) | |
| 110 | tardis.setAlarm(false) | |
| 111 | ||
| 112 | local newLocationMessage = string.format("Phew, I got away! X: %d, Y: %d, Z: %d!", escape_x, escape_y, escape_z)
| |
| 113 | talkToMe(newLocationMessage, username) | |
| 114 | end | |
| 115 | ||
| 116 | ||
| 117 | ||
| 118 | if split_string[2] == "cloisters" then | |
| 119 | if split_string[3] == "ring" then | |
| 120 | tardis.setAlarm(true) | |
| 121 | talkToMe("Cloister bells ringing!", username)
| |
| 122 | elseif split_string[3] == "stop" then | |
| 123 | tardis.setAlarm(false) | |
| 124 | talkToMe("Cloister bells stopped!", username)
| |
| 125 | end | |
| 126 | end | |
| 127 | ||
| 128 | end -- Closing the main "Handles" command | |
| 129 | end -- Closing function handleMessage | |
| 130 | ||
| 131 | if os.pullEvent() == 'onLand' then | |
| 132 | sleep(15) | |
| 133 | tardis.setRefuel(true) | |
| 134 | tardis.setHandbrake(true) | |
| 135 | ||
| 136 | end | |
| 137 | ||
| 138 | -- Main event loop | |
| 139 | while true do | |
| 140 | event, username, message = os.pullEvent("chat")
| |
| 141 | ||
| 142 | -- Username check | |
| 143 | if whitelistedUsernameMissing or username == chatboxWhitelistUsername then | |
| 144 | print("User: ".. username .. " - Running: " .. message)
| |
| 145 | handleMessage(message, username) | |
| 146 | end | |
| 147 | end |