Advertisement
Guest User

test

a guest
Aug 24th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. local t = peripheral.find("EntityDetector")
  2. local tPlayers = {}
  3. local tOldPlayers = {}
  4.  
  5. function getPlayers(range, x, y, z)
  6.   if not z then
  7.     return false
  8.   end
  9.  
  10.   local playerList = {}
  11.   local f = t.getEntityList(range, x, y, z)
  12.  
  13.   for k, v in pairs(f) do
  14.     if v.type == "EntityPlayerMP" then
  15.       table.insert(playerList, v.name)
  16.     end
  17.   end
  18.  
  19.   return playerList
  20. end
  21.  
  22. local function main()
  23.   while true do
  24.     tOldPlayers = tPlayers
  25.     tPlayers = getPlayers(20, 3244, 32, -260)
  26.    
  27.     if #tPlayers ~= #tOldPlayers then
  28.       print(#tPlayers.." players")
  29.       if #tPlayers > #tOldPlayers then
  30.         os.queueEvent("player_join", tPlayers, tOldPlayers)
  31.       elseif #tPlayers < #tOldPlayers then
  32.         os.queueEvent("player_left", tPlayers, tOldPlayers)
  33.       end
  34.     end
  35.    
  36.     sleep(1)
  37.   end
  38. end
  39.  
  40. local function playerHandler()
  41.   while true do
  42.     bState = false
  43.    
  44.     local event, tPlayers, tOldPlayers = os.pullEvent()
  45.    
  46.     if event == "player_join" then
  47.       for i = 1, #tPlayers do
  48.         sActualPlayer = tPlayers[i]
  49.        
  50.         if #tOldPlayers > 0 then
  51.           for i = 1, #tOldPlayers do
  52.             if tOldPlayers[i] == sActualPlayer then
  53.               bState = true
  54.             end
  55.          
  56.             if bState == false then
  57.               print(sActualPlayer.." join")
  58.             end
  59.           end
  60.         else
  61.           print(sActualPlayer.." join")
  62.         end
  63.       end
  64.     elseif event == "player_left" then
  65.       print("left")
  66.     end
  67.   end
  68. end
  69.  
  70. parallel.waitForAll(main, playerHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement