Advertisement
Darking560

SecuritySensorClient

Aug 4th, 2015
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. --Zone editable du programme--
  2.  
  3. local channel1 = 200
  4. local channel2 = 201
  5.  
  6. --Ne pas toucher au programme apres cette ligne--
  7.  
  8.  
  9. local continuer = true
  10. local default = "Darking"
  11.  
  12. function myperipheral(name)
  13.     local function inlist(item,list)
  14.         for n,m in pairs(list)  do
  15.             if m == item then
  16.                 return true
  17.             end
  18.         end
  19.         return false
  20.     end
  21.    
  22.     local side
  23.     for k,v in pairs(peripheral.getNames()) do
  24.         if string.find(v,name) then
  25.             side = v
  26.         elseif inlist(v,rs.getSides()) then
  27.             if peripheral.getType(v) == name then
  28.                 side = v
  29.             end
  30.         end
  31.     end
  32.    
  33.     if side ~= nil then
  34.         print("Found "..name.." as "..side)
  35.         return side
  36.     else   
  37.         print("ERROR:"..name.." don't found")
  38.         return nil
  39.     end
  40. end
  41.  
  42. print("-------Check Peripheral-------")
  43. side = myperipheral("openperipheral_sensor")
  44. r = peripheral.wrap(myperipheral("modem"))
  45. print("-------End Check Peripheral-------")
  46.  
  47. if side ~= nil then
  48.     s = peripheral.wrap(side)
  49.     first = s.getPlayers()
  50.     default = first[1].name
  51. end
  52.    
  53. if os.getComputerLabel() == nil then
  54.     print("Error: No Computer's Label")
  55.     print("Pour Labeliser un computer la commande est :")
  56.     print("label set <nom>")
  57.     print("Par exemple \"label set "..default.."Base\"")
  58.     continuer = false
  59. end
  60.        
  61. while continuer do
  62.     list = s.getPlayers()
  63.     local l={}
  64.     for n,m in pairs(list) do
  65.         if m~=nil then
  66.             table.insert(l,m.name)
  67.         end
  68.     end
  69.     message = {name=os.getComputerLabel(),players=l}
  70.     r.transmit(channel2,channel1,textutils.serialize(message))
  71.     sleep(2)
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement