Dragon53535

Villager Internet(User)

Oct 3rd, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. local idMax = 20 --#Change this to the maximum ID number you're using.
  2. local idMin = 1 --#Change this to the minimum ID number you're using.
  3. local modemSide = "top" --#Change this if you change where the modem is.
  4. local myID = os.getComputerID()
  5. local modem = peripheral.wrap(modemSide)
  6. modem.open(myID)
  7. local function getID()
  8.   while true do
  9.     local idNum = math.random(idMin,idMax)
  10.     if idNum ~= myID then
  11.       return idNum
  12.     end
  13.   end
  14. end
  15. local function main()
  16.   while true do
  17.     local event = {os.pullEvent()}
  18.     if event[1] == "modem_message" then
  19.       print("\nVillager ".. event[4] .." sent you a message: "..event[5])
  20.     end
  21.   end
  22. end
  23. local function send()
  24.   local input = read()
  25.   modem.transmit(getID(),myID,input)
  26. end
  27. while true do
  28.   parallel.waitForAny(main,send)
  29. end
Advertisement
Add Comment
Please, Sign In to add comment