Advertisement
jaklsfjlsak

信号发射器 原型

Mar 22nd, 2025 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. -- Find the virtual assistant peripheral
  2. local chat = peripheral.find("warpdriveVirtualAssistant")
  3.  
  4. -- Define chat name
  5. chat.name("[name")
  6.  
  7. -- Open rednet on the modem's side (change "left" to your modem's side)
  8. rednet.open("top")
  9.  
  10. print("Waiting for chat command to broadcast coordinates...")
  11.  
  12. while true do
  13.     sleep(0.08)
  14.    
  15.     -- Pull the last command from the virtual assistant
  16.     local state, CMD = chat.pullLastCommand()
  17.     if state then
  18.         local cmdText = string.lower(CMD or "")
  19.        
  20.         -- Attempt to match and extract the coordinates
  21.         local x_value, y_value, z_value = cmdText:match(".*x:(%-?%d+),%s*y:(%-?%d+),%s*z:(%-?%d+)")
  22.         if x_value and y_value and z_value then
  23.             local x = tonumber(x_value)
  24.             local y = tonumber(y_value)
  25.             local z = tonumber(z_value)
  26.            
  27.             print("Broadcasting coordinates: x:" .. x .. ", y:" .. y .. ", z:" .. z)
  28.            
  29.             -- Package the coordinates into a table (you can also send a formatted string)
  30.             local data = { x = x, y = y, z = z }
  31.            
  32.             -- Broadcast the coordinates using a custom protocol ("coordBroadcast")
  33.             rednet.broadcast(data, "coordBroadcast")
  34.         else
  35.             -- Optionally, print a one-time error (or suppress further errors if needed)
  36.             print("No valid coordinates found in command: " .. cmdText)
  37.         end
  38.     end
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement