rules54

Mob Control

Jul 14th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. -- Determine variables, tables, etc.
  2. local modemSide = nil
  3. local sides = {"front", "back", "left", "right", "top", "bottom"}
  4. local default = 1
  5. local id = tonumber(os.getComputerID())
  6. local label = os.getComputerLabel()
  7. local channels = {}
  8. local function receive(timeout)
  9.   local e, s, sC, rC, m, sD = nil
  10.   local function rnEvent()
  11.     e, s, sC, rC, m, sD = os.pullEvent("modem_message")
  12.     if e ~= nil then returnValue = true end
  13.   end
  14.   parallel.waitForAny(function() sleep(timeout) end, rnEvent)
  15.   if returnValue then return e, s, sC, rC, m, sd end
  16. end
  17.  
  18. --Determine which side the modem is located
  19. for i=1, #sides do
  20.   if peripheral.getType(sides[i]) == "modem" then
  21.     modemSide = tostring(sides[i])
  22.   end
  23. end
  24. if modemSide == nil then print("Modem not found, please attach modem.") end
  25. modem = peripheral.wrap(modemSide)
  26. --Open a channelto receive messages
  27. modem.open(default) modem.transmit(default, default, "ping")
  28.  
  29. while true do
  30.  
  31.   --Wait for a message to come in on channel 1
  32.   local event, side, SenderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  33.  
  34.   --If the message begins with "Spawner" then add
  35.   --the sending computer plus the mob type to a list
  36.   if string.find(message, "Spawner") ~= nil then
  37.     local subtract = string.gsub(message, "Spawner ", '')
  38.     table.insert(channels, tonumber(replyChannel), subtract)
  39.     print("Added ".. subtract.. " to list.")
  40.   end
  41.  
  42.   --Send a message back to available computers
  43.   for k,v in pairs(channels) do
  44.     modem.transmit(tonumber(k), default, "loop")
  45.   end
  46.  
  47.   for k,v in pairs(channels) do
  48.     modem.transmit(k, default, "spawn")
  49.     print("On")
  50.   end
  51.   os.sleep(5)
  52.   for k,v in pairs(channels) do
  53.     modem.transmit(k, default, "not spawn")
  54.     print("Off")
  55.   end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment