View difference between Paste ID: 4WmVQCrs and LmqFJ4Cm
SHOW: | | - or go back to the newest paste.
1-
local OffsetValue = 3
1+
local OffsetValue = 0
2
local shield = peripheral.find("warpdriveForceFieldProjector")
3
local lasers = peripheral.getNames()
4-
local speaker = peripheral.find("warpdriveSpeaker")
4+
5
local lastLx, lastLy, lastLz = 0, 0, 0
6-
local safedist = 15
6+
7
function shieldOffset(lx, ly, lz, fx, fy, fz)
8
    local dx = lx - fx
9
    local dy = ly - fy
10
    local dz = lz - fz
11
    local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
12
    dx = dx / distance
13
    dy = dy / distance
14
    dz = dz / distance
15
    local t1x = lx + dx * OffsetValue
16
    local t1y = ly + dy * OffsetValue
17
    local t1z = lz + dz * OffsetValue
18
    return t1x, t1y, t1z, distance
19
end
20
21
if fs.exists("conf") == false then
22
    shell.run("pastebin get 38M5cNbZ conf")
23
    term.clear()
24
end
25
26
for i = #lasers, 1, -1 do
27
    if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
28
        table.remove(lasers, i)
29
    else
30
        peripheral.wrap(lasers[i]).beamFrequency(1420)
31
    end
32
end
33
34
print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
35
36
local _, upgrades = shield.getUpgrades()
37
local Size
38
if upgrades:match("1/4 x Range") then
39
    Size = 16
40
elseif upgrades:match("2/4 x Range") then
41
    Size = 32
42
elseif upgrades:match("3/4 x Range") then
43
    Size = 48
44
elseif upgrades:match("4/4 x Range") then
45
    Size = 64
46
elseif upgrades:match("0/4 x Range") then
47
    Size = 0
48
end
49
50
while true do
51
    local event, laserName, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent()
52
53
    if event == "laserScanning" then
54
        lastLx, lastLy, lastLz = tonumber(lx), tonumber(ly), tonumber(lz)
55
        local fx, fy, fz = shield.getLocalPosition()
56
        local t1x, t1y, t1z, distance = shieldOffset(lastLx, lastLy, lastLz, fx, fy, fz)
57
58
        tx = (t1x - fx) / Size
59
        ty = (t1y - fy) / Size
60
        tz = (t1z - fz) / Size
61
62
        
63
            shield.translation(tx, ty, tz)
64-
        if distance < safedist then
64+
65-
            print("Target is too Close! Shield Disabled!")
65+
66
        local fx, fy, fz = shield.getLocalPosition()
67-
            speaker.speak("Target Dis: " .. tostring(distance))
67+
68-
            speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z))
68+
69-
            speaker.speak("Laser Coordinates: x=" .. tostring(lastLx) .. ", y=" .. tostring(lastLy) .. ", z=" .. tostring(lastLz))
69+
        if on > 6 then
70-
        elseif distance > safedist then
70+
71
        elseif on < 5 then
72-
            speaker.speak("Target Dis: " .. tostring(distance))
72+
73-
            speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z))
73+
74-
            speaker.speak("Laser Coordinates: x=" .. tostring(lastLx) .. ", y=" .. tostring(lastLy) .. ", z=" .. tostring(lastLz))
74+
75
        print("C key pressed, running 'conf' script...")
76
        shell.run("conf")
77
    end
78
end
79