Dragon53535

Villager Internet(Villager)

Oct 3rd, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. local responseTable = {"Hello.","How are you?",
  2. "What is your name?","Do you want to hang out?","Yes.","No.",
  3. "Where do you live?", "In a house."} --[[#If you want more responses for
  4. the villagers to say then just add a comma , and put the text in quotes,
  5. then do so for each response]]--
  6. local lampTime = 5 --#Change for the time the lamp will stay on.
  7. local idMax = 20 --#Change this to the maximum ID number you're using.
  8. local idMin = 1 --#Change this to the minimum ID number you're using.
  9. local plate = "left" --#If you move the plate, change this to the side
  10. local lamp = "right" --#Same for the lamp.
  11. local modemSide = "top" --#Same for the modem
  12. local myID = os.getComputerID()
  13. local modem = peripheral.wrap(modemSide)
  14. modem.open(myID)
  15. local tID = os.startTimer(1)
  16. local function response()
  17.   return responseTable[math.random(1,#responseTable)]
  18. end
  19. local function getID()
  20.   while true do
  21.     local idNum = math.random(idMin,idMax)
  22.     if idNum ~= myID then
  23.       return idNum
  24.     end
  25.   end
  26. end
  27. while true do
  28.   local event = {os.pullEvent()}
  29.   if event[1] == "modem_message" then
  30.     print("Villager ".. event[4] .." sent you a message: "..event[5])
  31.     rs.setOutput(lamp,true)
  32.     tID = os.startTimer(lampTime)
  33.   elseif event[1] == "redstone" then
  34.     if rs.getInput(plate) then
  35.       modem.transmit(getID(),myID,response())
  36.     end
  37.   elseif event[1] == "timer" and event[2] == tID then
  38.     rs.setOutput(lamp,false)
  39.     sleep(0)
  40.   end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment