Advertisement
Mizeno

Tardis Handles CC:Tweaked

Mar 5th, 2025 (edited)
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. --This script relies on "Advanced Peripherals", in order to pull messages from the chat using the chatBox
  2. -- https://www.curseforge.com/minecraft/mc-mods/advanced-peripherals
  3. -- https://docs.srendi.de/1.16/peripherals/chat_box/
  4.  
  5. --remove legacy scripts
  6. if (fs.exists("messageHandler")) then
  7. print("Deleting messageHandler script, as it's now included in this script.")
  8. shell.run("delete", "messageHandler")
  9. end
  10.  
  11. tardis = peripheral.find("tardisinterface") or error("No tardis interface attached.", 0)
  12. box = peripheral.find("chatBox") or error("No chatBox attached.", 0)
  13.  
  14. chatboxWhitelistUsername = settings.get("chatboxWhitelistUsername")
  15. whitelistedUsernameMissing = chatboxWhitelistUsername == nil
  16.  
  17. if whitelistedUsernameMissing then
  18. print("No whitelisted username, anyone can control this Tardis")
  19. end
  20.  
  21.  
  22. function split(s, delimiter)
  23. result = {};
  24. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  25. table.insert(result, match);
  26. end
  27. return result;
  28. end
  29.  
  30. function talkToMe (str, playerName)
  31. print(str)
  32. if (box == nil) then
  33. -- do nothing
  34. elseif type(str) ~= "string" then
  35. box.sendMessageToPlayer("NoStringError: talkToMe needs type string", playerName)
  36. else
  37. box.sendMessageToPlayer(str, playerName, "TARDIS")
  38. end
  39. end
  40.  
  41. function handleMessage (message, username)
  42. split_string = split(message, " ")
  43.  
  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
  45. if split_string[2] == "go" then
  46. local x = tonumber(split_string[3])
  47. local y = tonumber(split_string[4])
  48. local z = tonumber(split_string[5])
  49. local d, dimName = tardis.getDestinationDimension()
  50.  
  51. if split_string[6] ~= nil then
  52. local requestedDimension = split_string[6]
  53. --get list of dimensions
  54. local dimensionList = {tardis.getDimensions()}
  55. --print(dimensionList)
  56.  
  57. for key,value in ipairs(dimensionList) do
  58. local splitTheString = split(value,' ')
  59. local id = splitTheString[1]
  60.  
  61. local nameArray = split(splitTheString[3],':')
  62. local name = nameArray[2]
  63.  
  64. if string.find(name, requestedDimension) then
  65. d = (tonumber(key) - 1) -- ??
  66. print(key)
  67. end
  68. end
  69. end
  70.  
  71. tardis.setDestinationAndDimension(x, y, z, d)
  72.  
  73. sleep(1)
  74. talkToMe("You got it!", username)
  75. tardis.setDoors("CLOSED")
  76. sleep(1)
  77. tardis.setHandbrake(false)
  78. sleep(1)
  79. tardis.setFlight(1)
  80. talkToMe("Taking off!", username)
  81. sleep(3)
  82. tardis.setRefuel(true)
  83. local timeLeft = tardis.getTimeLeft()
  84. sleep(timeLeft)
  85. talkToMe("Landing now!", username)
  86. sleep(15)
  87. tardis.setHandbrake(true)
  88. talkToMe("I'm here!", username)
  89. end
  90. end
  91. end
  92.  
  93. while true do
  94. event, username, message = os.pullEvent("chat")
  95.  
  96. --username specific. May switch to checking tardis's list of players.
  97. if whitelistedUsernameMissing or username == chatboxWhitelistUsername then
  98. print("User: ".. username .. " - Running: " .. message)
  99. handleMessage(message, username)
  100. end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement