Advertisement
jaklsfjlsak

护盾炮台v2 垃圾信息修复

Mar 31st, 2025 (edited)
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.13 KB | None | 0 0
  1. local allowed = {"Ares_Xiao_Hu", "Destiney"}
  2.  
  3. if not fs.exists("conf") then
  4.   shell.run("pastebin get 38M5cNbZ conf")
  5.   term.clear()
  6. end
  7.  
  8. -- Check if a player is whitelisted.
  9. local function isWhitelisted(playerName)
  10.   for i = 1, #allowed do
  11.     if playerName == allowed[i] then
  12.       return true
  13.     end
  14.   end
  15.   return false
  16. end
  17.  
  18. -- Find the shield peripheral.
  19. local shield = peripheral.find("warpdriveForceFieldProjector")
  20. if not shield then
  21.   error("Shield not found!")
  22. end
  23.  
  24. -- Find and wrap all warpdrive cameras.
  25. local allPeripherals = peripheral.getNames()
  26. local cameras = {}
  27. for _, side in pairs(allPeripherals) do
  28.   if peripheral.getType(side) == "warpdriveCamera" then
  29.     print("Camera found on " .. side)
  30.     table.insert(cameras, peripheral.wrap(side))
  31.   end
  32. end
  33.  
  34. print("Control System Online. Press C to Configure.")
  35.  
  36. -- Determine shield range based on upgrades.
  37. local _, upgrades = shield.getUpgrades()
  38. local Size
  39. if upgrades:match("1/4 x Range") then
  40.     Size = 16
  41. elseif upgrades:match("2/4 x Range") then
  42.     Size = 32
  43. elseif upgrades:match("3/4 x Range") then
  44.     Size = 48
  45. elseif upgrades:match("4/4 x Range") then
  46.     Size = 64
  47. elseif upgrades:match("0/4 x Range") then
  48.     Size = 0
  49. else
  50.     Size = 32  -- default fallback
  51. end
  52.  
  53. -- An offset value to adjust the target coordinates.
  54. local OffsetValue = -1
  55.  
  56. -- Calculate the adjusted target coordinates.
  57. local function shieldOffset(lx, ly, lz, fx, fy, fz)
  58.     local dx = lx - fx
  59.     local dy = ly - fy
  60.     local dz = lz - fz
  61.     local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
  62.     -- Normalize the vector.
  63.     dx = dx / distance
  64.     dy = dy / distance
  65.     dz = dz / distance
  66.     local t1x = lx + dx * OffsetValue
  67.     local t1y = ly + dy * OffsetValue
  68.     local t1z = lz + dz * OffsetValue
  69.     return t1x, t1y, t1z, distance
  70. end
  71.  
  72. -- Main shield translation loop.
  73. local function shieldLoop()
  74.   local lastShieldState = nil  -- nil, true (enabled) or false (disabled)
  75.   while true do
  76.     local rsInput = redstone.getInput("bottom")
  77.     if not rsInput then
  78.       if lastShieldState ~= false then
  79.         print("Shield Disabled")
  80.         shield.enable(false)
  81.         lastShieldState = false
  82.       end
  83.     else
  84.       if lastShieldState ~= true then
  85.         print("Shield Enabled")
  86.         shield.enable(true)
  87.         lastShieldState = true
  88.       end
  89.       for _, camera in ipairs(cameras) do
  90.         local count = camera.getResultsCount()
  91.         if count and count > 0 then
  92.           for i = 0, count - 1 do
  93.             local success, entityType, playerName, x, y, z = camera.getResult(i)
  94.             if success and entityType == "minecraft:player" and not isWhitelisted(playerName) then
  95.               -- Round the coordinates.
  96.               x = math.floor(x * 10) / 10
  97.               y = math.floor(y * 10) / 10 - 1
  98.               z = math.floor(z * 10) / 10
  99.               print(playerName .. " detected at (" .. x .. ", " .. y .. ", " .. z .. ")")
  100.              
  101.               -- Get the shield's current local position.
  102.               local fx, fy, fz = shield.getLocalPosition()
  103.               -- Compute the adjusted target position.
  104.               local t1x, t1y, t1z, distance = shieldOffset(x, y, z, fx, fy, fz)
  105.              
  106.               -- Scale the translation by the shield's Size.
  107.               local tx = (t1x - fx) / Size
  108.               local ty = (t1y - fy) / Size
  109.               local tz = (t1z - fz) / Size
  110.              
  111.               shield.translation(tx, ty, tz)
  112.               print("Shield translated to (" .. tx .. ", " .. ty .. ", " .. tz .. ")")
  113.             end
  114.           end
  115.         end
  116.       end
  117.     end
  118.     os.sleep(0.1)
  119.   end
  120. end
  121.  
  122. -- Key listener loop for configuration.
  123. local function keyListener()
  124.   while true do
  125.     local event, key = os.pullEvent("key")
  126.     if key == 46 then  -- Key code 46 corresponds to C.
  127.       print("C key pressed, launching 'conf' script...")
  128.       parallel.waitForAny(
  129.         function() shell.run("conf") end,
  130.         function() while true do os.sleep(0.1) end end
  131.       )
  132.     end
  133.   end
  134. end
  135.  
  136. -- Run both loops concurrently.
  137. parallel.waitForAny(shieldLoop, keyListener)
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement