Godleydemon

Guard

Jun 10th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. local turtleId
  2. local isWirelessTurtle
  3. local messageOutputFileName
  4.  
  5.  
  6.  
  7. isWirelessTurtle = peripheral.isPresent("right")
  8. if (isWirelessTurtle == true) then
  9.   turtleId = os.getComputerLabel()
  10.   rednet.open("right")
  11. end
  12.  
  13. function writeMessage(message)
  14.     print(message)
  15.  
  16.     -- If this turtle has a modem, then write the message to red net
  17.     if (isWirelessTurtle == true) then
  18.       if (turtleId == nil) then
  19.         rednet.broadcast(message)
  20.       else
  21.         -- Broadcast the message (prefixed with the turtle's id)
  22.         rednet.broadcast("[".. turtleId.."] "..message)
  23.       end
  24.     end
  25.  
  26.     if (messageOutputFileName ~= nil) then
  27.       -- Open file, write message and close file (flush doesn't seem to work!)
  28.       local outputFile = io.open(messageOutputFileName, "a")
  29.       outputFile:write(message)
  30.       outputFile:write("\n")
  31.       outputFile:close()
  32.     end
  33. end
  34.  
  35. while true do
  36.         if turtle.attack()
  37.             then writeMessage("Mob Detected and Dispatched")
  38.         end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment