Advertisement
posicat

/cattech/comms.lua

Oct 14th, 2024 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. --File: /cattech/comms.lua
  2.  
  3. function initializeRednetModem()
  4.     local sides = {"left", "right", "top", "bottom", "front", "back"}
  5.    
  6.     for _, side in ipairs(sides) do
  7.         if peripheral.isPresent(side) then
  8.             local peripheralType = peripheral.getType(side)
  9.             if peripheralType == "modem" or peripheralType == "ender_modem" then
  10.                 rednet.open(side)  -- Initialize rednet on the modem
  11.                 log("debug",peripheralType .. " available on " .. side .. ".  Rednet active.")
  12.                 return true
  13.             else
  14.                 log("debug","Peripheral found : " .. (peripheralType or "none"))
  15.             end
  16.         end
  17.     end
  18.  
  19.     log("error","No modem found on any side.")
  20.     return false
  21. end
  22.  
  23. function chunkload()
  24.     local turtleName = os.getComputerLabel()
  25.     local message = "err chunkload " .. (turtleName or "unnamed")
  26.  
  27.     local x, y, z = gps.locate(5) -- Attempt to locate with a timeout of 5 seconds
  28.     --if x then
  29.         local message = string.format("chunkLoad %d %d %d", x, y, z)
  30.     --end
  31.  
  32.     log("debug","Sending: " .. message)
  33.     rednet.broadcast(message,"worldServer")
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement