Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local allowed = {"Ares_Xiao_Hu", "Destiney"}
- if not fs.exists("conf") then
- shell.run("pastebin get 38M5cNbZ conf")
- term.clear()
- end
- -- Check if a player is whitelisted.
- local function isWhitelisted(playerName)
- for i = 1, #allowed do
- if playerName == allowed[i] then
- return true
- end
- end
- return false
- end
- -- Find the shield peripheral.
- local shield = peripheral.find("warpdriveForceFieldProjector")
- if not shield then
- error("Shield not found!")
- end
- -- Find and wrap all warpdrive cameras.
- local allPeripherals = peripheral.getNames()
- local cameras = {}
- for _, side in pairs(allPeripherals) do
- if peripheral.getType(side) == "warpdriveCamera" then
- print("Camera found on " .. side)
- table.insert(cameras, peripheral.wrap(side))
- end
- end
- print("Control System Online. Press C to Configure.")
- -- Determine shield range based on upgrades.
- local _, upgrades = shield.getUpgrades()
- local Size
- if upgrades:match("1/4 x Range") then
- Size = 16
- elseif upgrades:match("2/4 x Range") then
- Size = 32
- elseif upgrades:match("3/4 x Range") then
- Size = 48
- elseif upgrades:match("4/4 x Range") then
- Size = 64
- elseif upgrades:match("0/4 x Range") then
- Size = 0
- else
- Size = 32 -- default fallback
- end
- -- An offset value to adjust the target coordinates.
- local OffsetValue = -1
- -- Calculate the adjusted target coordinates.
- local function shieldOffset(lx, ly, lz, fx, fy, fz)
- local dx = lx - fx
- local dy = ly - fy
- local dz = lz - fz
- local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
- -- Normalize the vector.
- dx = dx / distance
- dy = dy / distance
- dz = dz / distance
- local t1x = lx + dx * OffsetValue
- local t1y = ly + dy * OffsetValue
- local t1z = lz + dz * OffsetValue
- return t1x, t1y, t1z, distance
- end
- -- Main shield translation loop.
- local function shieldLoop()
- while true do
- if not redstone.getInput("bottom") then
- print("Shield Disabled")
- shield.enable(false)
- else
- shield.enable(true)
- for _, camera in ipairs(cameras) do
- local count = camera.getResultsCount()
- if count and count > 0 then
- for i = 0, count - 1 do
- local success, entityType, playerName, x, y, z = camera.getResult(i)
- if success and entityType == "minecraft:player" and not isWhitelisted(playerName) then
- -- Round the coordinates.
- x = math.floor(x * 10) / 10
- y = math.floor((y * 10) / 10) - 1
- z = math.floor(z * 10) / 10
- print(playerName .. " detected at (" .. x .. ", " .. y .. ", " .. z .. ")")
- -- Get the shield's current local position.
- local fx, fy, fz = shield.getLocalPosition()
- -- Compute the adjusted target position.
- local t1x, t1y, t1z, distance = shieldOffset(x, y, z, fx, fy, fz)
- -- Scale the translation by the shield's Size.
- local tx = (t1x - fx) / Size
- local ty = (t1y - fy) / Size
- local tz = (t1z - fz) / Size
- shield.translation(tx, ty, tz)
- print("Shield translated to (" .. tx .. ", " .. ty .. ", " .. tz .. ")")
- end
- end
- end
- end
- end
- os.sleep(0.1)
- end
- end
- -- Key listener loop for configuration.
- local function keyListener()
- while true do
- local event, key = os.pullEvent("key")
- if key == 46 then -- Key code 46 corresponds to C.
- print("C key pressed, launching 'conf' script...")
- parallel.waitForAny(
- function() shell.run("conf") end,
- function() while true do os.sleep(0.1) end end
- )
- end
- end
- end
- -- Run both loops concurrently.
- parallel.waitForAny(shieldLoop, keyListener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement