legg0028

chat_end_portal

Jul 25th, 2021 (edited)
832
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local box = peripheral.find("chatBox") -- Finds a connected Chat Box
  2. local detector = peripheral.wrap("right") --Defines the Detector on the right
  3. if box == nil then error("Missing Chat Box") end
  4. if detector == nil then error("Missing Player Detector on right") end
  5.  
  6. function tablelength(T)
  7.   count = 0
  8.   for _ in pairs(T) do count = count + 1 end
  9.   return count
  10. end
  11.  
  12. function sayPlayers(range)
  13.   players = detector.getPlayersInRange(range)
  14.   nPlayers = tablelength(players)
  15.   for k,v in pairs(players) do
  16.     box.sendMessageToPlayer(v..", welcome to Campicus' End Portal, Mob spawner and Zoo!", v)
  17.   end
  18. end
  19.  
  20. while true do
  21.     sayPlayers(5)
  22.     for x = 1,120 do
  23.         sleep(1)
  24.         players = detector.getPlayersInRange(5)
  25.         if tablelength(players) > nPlayers then
  26.             sayPlayers(5)
  27.         end
  28.     end
  29. end
RAW Paste Data