Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Zone editable du programme--
- local channel1 = 200
- local channel2 = 201
- --Ne pas toucher au programme apres cette ligne--
- local continuer = true
- local prevList = {}
- local default = "Darking"
- function myperipheral(name)
- local function inlist(item,list)
- for n,m in pairs(list) do
- if m == item then
- return true
- end
- end
- return false
- end
- local side
- for k,v in pairs(peripheral.getNames()) do
- if string.find(v,name) then
- side = v
- elseif inlist(v,rs.getSides()) then
- if peripheral.getType(v) == name then
- side = v
- end
- end
- end
- if side ~= nil then
- print("Found "..name.." as "..side)
- return side
- else
- print("ERROR:"..name.." don't found")
- return nil
- end
- end
- function compare(list1,list2)
- for m,n in pairs(list1) do
- local ok = false
- for o,p in pairs(list2) do
- if n.name == p.name then
- ok = true
- end
- end
- if not ok then
- message = {name=os.getComputerLabel(),player=n.name,entrer=true}
- r.transmit(channel2,channel1,textutils.serialize(message))
- print(n.name.." transmit en enter")
- end
- end
- for m,n in pairs(list2) do
- local ok = false
- for o,p in pairs(list1) do
- if n.name == p.name then
- ok = true
- end
- end
- if not ok then
- sleep(0.5)
- message = {name=os.getComputerLabel(),player=n.name,entrer=false}
- r.transmit(channel2,channel1,textutils.serialize(message))
- print(n.name.." transmit en sortie")
- end
- end
- end
- print("-------Check Peripheral-------")
- side = myperipheral("openperipheral_sensor")
- r = peripheral.wrap(myperipheral("modem"))
- print("-------End Check Peripheral-------")
- if side ~= nil then
- s = peripheral.wrap(side)
- first = s.getPlayers()
- default = first[1].name
- end
- if os.getComputerLabel() == nil then
- print("Error: No Computer's Label")
- print("Pour Labeliser un computer la commande est :")
- print("label set <nom>")
- print("Par exemple \"label set "..default.."Base\"")
- continuer = false
- end
- --init
- local msg = ""
- while msg ~= "init" and continuer do
- r.open(channel1)
- e, side, sender, reply, msg = os.pullEvent()
- if msg == "init" and reply == channel2 then
- r.transmit(channel2,"init",os.getComputerLabel())
- r.close(channel1)
- end
- end
- print("Initialisation faite")
- sleep(5)
- while continuer do
- --print("scanning...")
- list = s.getPlayers()
- compare(list,prevList)
- prevList = list
- sleep(2)
- --read()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement