View difference between Paste ID: MVPGMpNC and Qa3W0dZ4
SHOW: | | - or go back to the newest paste.
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
 
12
function split(s, delimiter)
13
    result = {}
14
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
15
        table.insert(result, match)
16
    end
17
    return result
18
end
19
 
20
function talkToMe(str, playerName)
21
    print(str)
22
    if (box == nil) then
23
        -- do nothing
24
    elseif type(str) ~= "string" then
25
        box.sendMessageToPlayer("NoStringError: talkToMe needs type string", playerName)
26
    else
27
        box.sendMessageToPlayer(str, playerName, "TARDIS")
28
    end
29
end
30
 
31
function handleMessage(message, username)
32
    split_string = split(message, " ")
33
 
34
    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
35
        if split_string[2] == "go" then
36
            local x = tonumber(split_string[3])
37
            local y = tonumber(split_string[4])
38
            local z = tonumber(split_string[5])
39
            local d, dimName = tardis.getDestinationDimension()
40
 
41
            if split_string[6] ~= nil then
42
                local requestedDimension = split_string[6]
43
                -- Get list of dimensions
44
                local dimensionList = {tardis.getDimensions()}
45
 
46
                for key, value in ipairs(dimensionList) do
47
                    local splitTheString = split(value, ' ')
48
                    local id = splitTheString[1]
49
 
50
                    local nameArray = split(splitTheString[3], ':')
51
                    local name = nameArray[2]
52
 
53
                    if string.find(name, requestedDimension) then
54
                        d = (tonumber(key) - 1)
55
                        print(key)
56
                    end
57
                end
58
            end
59
 
60
            tardis.setDestinationAndDimension(x, y, z, d)
61
 
62
            sleep(1)
63
            talkToMe("You got it!", username)
64
            tardis.setDoors("CLOSED")
65
            sleep(1)
66
            tardis.setHandbrake(false)
67
            sleep(1)
68
            tardis.setFlight(1)
69
            talkToMe("Taking off!", username)
70
            sleep(3)
71
            tardis.setRefuel(true)
72
            local timeLeft = tardis.getTimeLeft()
73
            sleep(timeLeft)
74
            talkToMe("Landing now!", username)
75
            sleep(15)
76
            tardis.setHandbrake(true)
77
            talkToMe("I'm here!", username)
78
        end
79
 
80
        if split_string[2] == "hads" or split_string[2] == "HADS" then
81
    local curr_x, curr_y, curr_z = tardis.getLocation()
82
    
83
    -- Generate a random safe escape location (at least 2500 blocks away)
84
    local escape_x = curr_x + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1))
85
    local escape_y = curr_y  -- Keep the Y level the same
86
    local escape_z = curr_z + (math.random(2500, 5000) * (math.random(0,1) == 0 and -1 or 1))
87
    
88
    -- Notify the player and enable cloisters
89
    talkToMe("HADS activated! Escaping to a safe location.", username)
90
    tardis.setAlarm(true)
91
 
92
    -- Close doors and prepare for emergency jump
93
    tardis.setDoors("CLOSED")
94
    sleep(1)
95
    tardis.setHandbrake(false)
96
    sleep(1)
97
    
98
    -- Set the new escape destination
99
    tardis.setDestination(escape_x, escape_y, escape_z)
100
    tardis.setFlight(1)
101
    
102
    -- Wait for flight to complete
103
    sleep(3)
104
    local timeLeft = tardis.getTimeLeft()
105
    sleep(timeLeft)
106
    
107
    -- Landing process
108
    sleep(15)
109
    tardis.setHandbrake(true)
110
    tardis.setRefuel(true)
111
    tardis.setAlarm(false)
112
 
113
local newLocationMessage = string.format("Phew, I got away! X: %d, Y: %d, Z: %d!", escape_x, escape_y, escape_z)
114
    talkToMe(newLocationMessage, username)
115
end
116
117
 
118
        
119
        if split_string[2] == "cloisters" then
120
            if split_string[3] == "ring" then
121
                tardis.setAlarm(true)
122
                talkToMe("Cloister bells ringing!", username)
123
        elseif split_string[3] == "stop" then
124
            tardis.setAlarm(false)
125
            talkToMe("Cloister bells stopped!", username)
126
        end
127
end
128
 
129
        if split_string[2] == "refuel" then
130
            tardis.setRefuel(true)
131-
if os.pullEvent() == 'onLand' then
131+
			talkToMe("Refueling!", username)
132-
        sleep(15)
132+
133-
        tardis.setRefuel(true)
133+
134-
        tardis.setHandbrake(true)
134+
135
end  -- Closing function handleMessage
136
    
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