Advertisement
Mizeno

Tardis Handles CC:Tweaked 1.2.2

Mar 5th, 2025 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tardis = peripheral.find("tardisinterface") or error("No tardis interface attached.", 0)
  2. box = peripheral.find("chatBox") or error("No chatBox attached.", 0)
  3.  
  4. chatboxWhitelistUsername = settings.get("chatboxWhitelistUsername")
  5. whitelistedUsernameMissing = chatboxWhitelistUsername == nil
  6.  
  7. if whitelistedUsernameMissing then
  8.     print("No whitelisted username, anyone can control this Tardis")
  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.     elseif type(str) ~= "string" then
  24.         box.sendMessageToPlayer("NoStringError: talkToMe needs type string", playerName)
  25.     else
  26.         box.sendMessageToPlayer(str, playerName, "TARDIS")
  27.     end
  28. end
  29.  
  30. function handleMessage(message, username)
  31.     split_string = split(message, " ")
  32.  
  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.         if split_string[2] == "go" then
  35.             local x = tonumber(split_string[3])
  36.             local y = tonumber(split_string[4])
  37.             local z = tonumber(split_string[5])
  38.             local d, dimName = tardis.getDestinationDimension()
  39.  
  40.             if split_string[6] ~= nil then
  41.                 local requestedDimension = split_string[6]
  42.                 -- Get list of dimensions
  43.                 local dimensionList = {tardis.getDimensions()}
  44.  
  45.                 for key, value in ipairs(dimensionList) do
  46.                     local splitTheString = split(value, ' ')
  47.                     local id = splitTheString[1]
  48.  
  49.                     local nameArray = split(splitTheString[3], ':')
  50.                     local name = nameArray[2]
  51.  
  52.                     if string.find(name, requestedDimension) then
  53.                         d = (tonumber(key) - 1)
  54.                         print(key)
  55.                     end
  56.                 end
  57.             end
  58.  
  59.             tardis.setDestinationAndDimension(x, y, z, d)
  60.  
  61.             sleep(1)
  62.             talkToMe("You got it!", username)
  63.             tardis.setDoors("CLOSED")
  64.             sleep(1)
  65.             tardis.setHandbrake(false)
  66.             sleep(1)
  67.             tardis.setFlight(1)
  68.             talkToMe("Taking off!", username)
  69.             sleep(3)
  70.             tardis.setRefuel(true)
  71.             local timeLeft = tardis.getTimeLeft()
  72.             sleep(timeLeft)
  73.             talkToMe("Landing now!", username)
  74.             sleep(15)
  75.             tardis.setHandbrake(true)
  76.             talkToMe("I'm here!", username)
  77.         end
  78.  
  79.         if split_string[2] == "hads" or split_string[2] == "HADS" then
  80.     local curr_x, curr_y, curr_z = tardis.getLocation()
  81.    
  82.     -- Generate a random safe escape location (at least 2500 blocks away)
  83.     local escape_x = curr_x + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1))
  84.     local escape_y = curr_y  -- Keep the Y level the same
  85.     local escape_z = curr_z + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1))
  86.    
  87.     -- Notify the player and enable cloisters
  88.     talkToMe("HADS activated! Escaping to a safe location.", username)
  89.     tardis.setAlarm(true)
  90.  
  91.     -- Close doors and prepare for emergency jump
  92.     tardis.setDoors("CLOSED")
  93.     sleep(1)
  94.     tardis.setHandbrake(false)
  95.     sleep(1)
  96.    
  97.     -- Set the new escape destination
  98.     tardis.setDestination(escape_x, escape_y, escape_z)
  99.     tardis.setFlight(1)
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement